jscrambler
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -1,4 +0,1 @@ | ||
'use strict'; | ||
var JScramblerClient = require('./jscrambler-client'); | ||
var Q = require('q'); | ||
/** | ||
@@ -10,2 +7,10 @@ * A facade to access JScrambler API using JScramblerClient. | ||
*/ | ||
'use strict'; | ||
var fs = require('fs-extra'); | ||
var JScramblerClient = require('./jscrambler-client'); | ||
var JSZip = require('jszip'); | ||
var path = require('path'); | ||
var Q = require('q'); | ||
exports = module.exports = | ||
@@ -90,9 +95,56 @@ /** @lends jScramblerFacade */ | ||
var deferred = Q.defer(); | ||
this.zipProject(params.files); | ||
client.post('/code.json', params, function (err, res, body) { | ||
this.cleanZipProject(); | ||
if (err) deferred.reject(err); | ||
else if (res.statusCode >= 400) deferred.reject(res); | ||
else deferred.resolve(JSON.parse(body)); | ||
}.bind(this)); | ||
return deferred.promise; | ||
}, | ||
/** | ||
* Deletes code through the API. | ||
* @param {JScramblerClient} client | ||
* @param {String} projectId | ||
* @returns {Q.promise} | ||
*/ | ||
deleteCode: function (client, projectId) { | ||
var deferred = Q.defer(); | ||
client.delete('/code/' + projectId + '.zip', null, function (err, res, body) { | ||
if (err) deferred.reject(err); | ||
else if (res.statusCode >= 400) deferred.reject(res); | ||
else deferred.resolve(JSON.parse(body)); | ||
}); | ||
return deferred.promise; | ||
}, | ||
/** | ||
* It cleans the temporary zip project. | ||
*/ | ||
cleanZipProject: function () { | ||
fs.unlinkSync('.tmp.zip'); | ||
}, | ||
/** | ||
* It zips all files inside the passed parameter into a single zip file. | ||
*/ | ||
zipProject: function (files) { | ||
var zip = new JSZip(); | ||
for (var i = 0, l = files.length; i < l; ++i) { | ||
zip.file(files[i], fs.readFileSync(files[i])); | ||
} | ||
fs.outputFileSync('.tmp.zip', zip.generate(), {encoding: 'base64'}); | ||
files[0] = '.tmp.zip'; | ||
files.length = 1; | ||
}, | ||
/** | ||
* It unzips a zip file to the given destination. | ||
*/ | ||
unzipProject: function (zipFile, dest) { | ||
var zip = new JSZip(zipFile); | ||
for (var file in zip.files) { | ||
if (!zip.files[file].options.dir) { | ||
var buffer = zip.file(file).asNodeBuffer(); | ||
fs.outputFileSync(path.join(dest, file), buffer); | ||
} | ||
} | ||
} | ||
}; |
{ | ||
"name": "jscrambler", | ||
"description": "JScrambler API client.", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"homepage": "https://github.com/auditmark/node-jscrambler", | ||
@@ -31,3 +31,4 @@ "author": { | ||
"commander": "^2.1.0", | ||
"fs-extra": "^0.8.1" | ||
"fs-extra": "^0.8.1", | ||
"jszip": "^2.2.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "main": "jscrambler", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18977
9
327
6
2
+ Addedjszip@^2.2.0
+ Addedjszip@2.7.0(transitive)
+ Addedpako@1.0.11(transitive)