jscrambler 5.5.32 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/bin/jscrambler.js +8 -10
- package/dist/client.js +15 -1
- package/dist/config.js +3 -1
- package/dist/constants.js +24 -2
- package/dist/generate-signed-params.js +5 -1
- package/dist/index.js +30 -24
- package/dist/utils.js +33 -0
- package/dist/zip.js +232 -123
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Jscrambler Client for Browser and Node.js
|
|
3
3
|
|
|
4
4
|
- [Jscrambler](https://jscrambler.com/?utm_source=github.com&utm_medium=referral)
|
|
5
|
+
- [Version Compatibility](#version-compatibility)
|
|
5
6
|
- [Installation](#installation)
|
|
6
7
|
- [RC configuration](#rc-configuration)
|
|
7
8
|
- [CLI](#cli)
|
|
@@ -22,6 +23,16 @@ Jscrambler Client for Browser and Node.js
|
|
|
22
23
|
- [Quick example](#quick-example)
|
|
23
24
|
- [Jscrambler Parameters](#jscrambler-parameters)
|
|
24
25
|
|
|
26
|
+
## Version Compatibility
|
|
27
|
+
|
|
28
|
+
The version's compatibility table match your [Jscrambler Version](https://app.jscrambler.com/settings) with the Jscrambler Client.
|
|
29
|
+
Please make sure you install the right version, otherwise some functionalities might not work properly.
|
|
30
|
+
|
|
31
|
+
| _Jscrambler Version_ | _Client and Integrations_ |
|
|
32
|
+
|:----------:|:-------------:|
|
|
33
|
+
| _<= 7.1_ | _<= 5.x.x_ |
|
|
34
|
+
| _\>= 7.2_ | _\>= 6.0.0_ |
|
|
35
|
+
|
|
25
36
|
## Installation
|
|
26
37
|
|
|
27
38
|
On your project:
|
|
@@ -36,6 +47,12 @@ Or globally:
|
|
|
36
47
|
npm i -g jscrambler
|
|
37
48
|
```
|
|
38
49
|
|
|
50
|
+
Or a specific version:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
npm i jscrambler@5
|
|
54
|
+
```
|
|
55
|
+
|
|
39
56
|
## RC configuration
|
|
40
57
|
You may put your access and secret keys into a config file if found in [these directories](https://github.com/dominictarr/rc#standards). Besides simplifying the command entry, this has the added benefit of not logging your Jscrambler credentials.
|
|
41
58
|
|
package/dist/bin/jscrambler.js
CHANGED
|
@@ -9,10 +9,6 @@ var _lodash = require('lodash.defaults');
|
|
|
9
9
|
|
|
10
10
|
var _lodash2 = _interopRequireDefault(_lodash);
|
|
11
11
|
|
|
12
|
-
var _glob = require('glob');
|
|
13
|
-
|
|
14
|
-
var _glob2 = _interopRequireDefault(_glob);
|
|
15
|
-
|
|
16
12
|
var _path = require('path');
|
|
17
13
|
|
|
18
14
|
var _path2 = _interopRequireDefault(_path);
|
|
@@ -31,6 +27,8 @@ var _2 = _interopRequireDefault(_);
|
|
|
31
27
|
|
|
32
28
|
var _cli = require('../cli');
|
|
33
29
|
|
|
30
|
+
var _utils = require('../utils');
|
|
31
|
+
|
|
34
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
33
|
|
|
36
34
|
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
|
@@ -171,7 +169,9 @@ if (_commander2.default.args.length > 0) {
|
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
if (globSrc && globSrc.length) {
|
|
174
|
-
|
|
172
|
+
// this will be translated to real files in the updateApplicationSources method
|
|
173
|
+
filesSrc = globSrc;
|
|
174
|
+
var nSources = 0;
|
|
175
175
|
// Iterate `globSrc` to build a list of source files into `filesSrc`
|
|
176
176
|
for (var i = 0, l = globSrc.length; i < l; i += 1) {
|
|
177
177
|
// Calling sync `glob` because async is pointless for the CLI use case
|
|
@@ -183,9 +183,7 @@ if (globSrc && globSrc.length) {
|
|
|
183
183
|
process.exit(1);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
var tmpGlob =
|
|
187
|
-
dot: true
|
|
188
|
-
});
|
|
186
|
+
var tmpGlob = (0, _utils.getMatchedFiles)(globSrc[i]);
|
|
189
187
|
|
|
190
188
|
if (config.werror && tmpGlob.length === 0) {
|
|
191
189
|
console.error('Pattern "' + globSrc[i] + '" doesn\'t match any files.');
|
|
@@ -202,9 +200,9 @@ if (globSrc && globSrc.length) {
|
|
|
202
200
|
});
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
|
-
|
|
203
|
+
nSources += tmpGlob.length;
|
|
206
204
|
}
|
|
207
|
-
if (
|
|
205
|
+
if (nSources === 0) {
|
|
208
206
|
console.error('No files matched.');
|
|
209
207
|
process.exit(1);
|
|
210
208
|
}
|
package/dist/client.js
CHANGED
|
@@ -46,6 +46,10 @@ var _generateSignedParams = require('./generate-signed-params');
|
|
|
46
46
|
|
|
47
47
|
var _generateSignedParams2 = _interopRequireDefault(_generateSignedParams);
|
|
48
48
|
|
|
49
|
+
var _constants = require('./constants');
|
|
50
|
+
|
|
51
|
+
var _package = require('../package.json');
|
|
52
|
+
|
|
49
53
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
54
|
|
|
51
55
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -140,6 +144,8 @@ JScramblerClient.prototype.get = function (path, params) {
|
|
|
140
144
|
* @param {Callback} callback
|
|
141
145
|
*/
|
|
142
146
|
JScramblerClient.prototype.request = function (method, path) {
|
|
147
|
+
var _this2 = this;
|
|
148
|
+
|
|
143
149
|
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
144
150
|
var isJSON = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
145
151
|
|
|
@@ -284,8 +290,16 @@ JScramblerClient.prototype.request = function (method, path) {
|
|
|
284
290
|
errorMessage += err.response.status + ' ' + err.response.statusText;
|
|
285
291
|
statusCode = err.response.status;
|
|
286
292
|
|
|
293
|
+
var incompatibleApi = false;
|
|
294
|
+
if (statusCode === _constants.HTTP_STATUS_CODES.UNAUTHORIZED) {
|
|
295
|
+
incompatibleApi = err.response.data.errorCode !== _constants.JSCRAMBLER_ERROR_CODES.INVALID_SIGNATURE;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (incompatibleApi) {
|
|
299
|
+
errorMessage = 'Incompatible jscrambler CLI version (' + _package.version + '). Please downgrade to: \n\t$ npm install ' + _constants.CLIENT_PACKAGES[_this2.options.clientId] + '@5';
|
|
300
|
+
} else if (
|
|
287
301
|
// For when we have API error messages
|
|
288
|
-
|
|
302
|
+
err.response.data && err.response.data.error && err.response.data.message) {
|
|
289
303
|
errorMessage += ' - ' + err.response.data.message;
|
|
290
304
|
} else if (err.response.data && err.response.data.errors && err.response.data.errors.length > 0) {
|
|
291
305
|
errorMessage += ' - ' + err.response.data.errors;
|
package/dist/config.js
CHANGED
|
@@ -8,6 +8,8 @@ var _rc = require('rc');
|
|
|
8
8
|
|
|
9
9
|
var _rc2 = _interopRequireDefault(_rc);
|
|
10
10
|
|
|
11
|
+
var _constants = require('./constants');
|
|
12
|
+
|
|
11
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
14
|
|
|
13
15
|
// Load RC configuration if present. Pass `[]` as last argument to avoid
|
|
@@ -18,7 +20,7 @@ var config = (0, _rc2.default)('jscrambler', {
|
|
|
18
20
|
basePath: '',
|
|
19
21
|
jscramblerVersion: 'stable',
|
|
20
22
|
werror: true,
|
|
21
|
-
clientId:
|
|
23
|
+
clientId: _constants.CLIENT_IDS.CLI,
|
|
22
24
|
utc: true,
|
|
23
25
|
maxRetries: 5
|
|
24
26
|
}, []);
|
package/dist/constants.js
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
|
|
7
|
+
var _Object$freeze;
|
|
8
|
+
|
|
9
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
|
|
6
11
|
var HTTP_STATUS_CODES = exports.HTTP_STATUS_CODES = Object.freeze({
|
|
12
|
+
UNAUTHORIZED: 401,
|
|
7
13
|
FORBIDDEN: 403,
|
|
8
14
|
NOT_FOUND: 404,
|
|
9
15
|
SERVICE_UNAVAILABLE: 503,
|
|
10
16
|
GATEWAY_TIMEOUT: 504
|
|
11
|
-
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var JSCRAMBLER_ERROR_CODES = exports.JSCRAMBLER_ERROR_CODES = Object.freeze({
|
|
20
|
+
INVALID_SIGNATURE: '254'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var CLIENT_IDS = exports.CLIENT_IDS = Object.freeze({
|
|
24
|
+
CLI: 0,
|
|
25
|
+
APP: 1,
|
|
26
|
+
WEBPACK: 2,
|
|
27
|
+
GULP: 3,
|
|
28
|
+
GRUNT: 4,
|
|
29
|
+
EMBER: 5,
|
|
30
|
+
METRO: 6
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var CLIENT_PACKAGES = exports.CLIENT_PACKAGES = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, CLIENT_IDS.CLI, 'jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.APP, 'app'), _defineProperty(_Object$freeze, CLIENT_IDS.WEBPACK, 'jscrambler-webpack-plugin'), _defineProperty(_Object$freeze, CLIENT_IDS.GULP, 'gulp-jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.GRUNT, 'grunt-jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.EMBER, 'ember-cli-jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.METRO, 'jscrambler-metro-plugin'), _Object$freeze));
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
|
|
7
|
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
8
|
+
|
|
6
9
|
exports.default = signedParams;
|
|
7
10
|
|
|
8
11
|
var _lodash = require('lodash.clone');
|
|
@@ -51,7 +54,8 @@ function buildSortedQuery(params) {
|
|
|
51
54
|
var _keys = (0, _lodash6.default)(params).sort();
|
|
52
55
|
var query = '';
|
|
53
56
|
for (var i = 0, l = _keys.length; i < l; i++) {
|
|
54
|
-
|
|
57
|
+
var value = _typeof(params[_keys[i]]) === 'object' ? JSON.stringify(params[_keys[i]]) : params[_keys[i]];
|
|
58
|
+
query += encodeURIComponent(_keys[i]) + '=' + encodeURIComponent(value) + '&';
|
|
55
59
|
}
|
|
56
60
|
query = query.replace(/\*/g, '%2A').replace(/[!'()]/g, escape).replace(/%7E/g, '~').replace(/\+/g, '%20');
|
|
57
61
|
// Strip the last separator and return
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
|
|
7
7
|
require('babel-polyfill');
|
|
8
8
|
|
|
9
|
-
var _glob = require('glob');
|
|
10
|
-
|
|
11
|
-
var _glob2 = _interopRequireDefault(_glob);
|
|
12
|
-
|
|
13
9
|
var _path = require('path');
|
|
14
10
|
|
|
15
11
|
var _path2 = _interopRequireDefault(_path);
|
|
@@ -54,6 +50,8 @@ var _introspection = require('./introspection');
|
|
|
54
50
|
|
|
55
51
|
var introspection = _interopRequireWildcard(_introspection);
|
|
56
52
|
|
|
53
|
+
var _utils = require('./utils');
|
|
54
|
+
|
|
57
55
|
var _getProtectionDefaultFragments = require('./get-protection-default-fragments');
|
|
58
56
|
|
|
59
57
|
var _getProtectionDefaultFragments2 = _interopRequireDefault(_getProtectionDefaultFragments);
|
|
@@ -202,10 +200,7 @@ exports.default = {
|
|
|
202
200
|
|
|
203
201
|
for (i = 0, l = filesSrc.length; i < l; i += 1) {
|
|
204
202
|
if (typeof filesSrc[i] === 'string') {
|
|
205
|
-
|
|
206
|
-
_filesSrc = _filesSrc.concat(_glob2.default.sync(filesSrc[i], {
|
|
207
|
-
dot: true
|
|
208
|
-
}));
|
|
203
|
+
_filesSrc = _filesSrc.concat((0, _utils.getMatchedFiles)(filesSrc[i]));
|
|
209
204
|
} else {
|
|
210
205
|
_filesSrc.push(filesSrc[i]);
|
|
211
206
|
}
|
|
@@ -241,13 +236,17 @@ exports.default = {
|
|
|
241
236
|
|
|
242
237
|
case 23:
|
|
243
238
|
if (!zipped) {
|
|
244
|
-
_context.next =
|
|
239
|
+
_context.next = 34;
|
|
245
240
|
break;
|
|
246
241
|
}
|
|
247
242
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
243
|
+
_context.next = 26;
|
|
244
|
+
return zipped.generateAsync({
|
|
245
|
+
type: 'base64'
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
case 26:
|
|
249
|
+
content = _context.sent;
|
|
251
250
|
|
|
252
251
|
|
|
253
252
|
if (debug) {
|
|
@@ -261,17 +260,17 @@ exports.default = {
|
|
|
261
260
|
};
|
|
262
261
|
|
|
263
262
|
_context.t0 = errorHandler;
|
|
264
|
-
_context.next =
|
|
263
|
+
_context.next = 32;
|
|
265
264
|
return this.addApplicationSource(client, applicationId, source);
|
|
266
265
|
|
|
267
|
-
case
|
|
266
|
+
case 32:
|
|
268
267
|
_context.t1 = _context.sent;
|
|
269
268
|
(0, _context.t0)(_context.t1);
|
|
270
269
|
|
|
271
|
-
case
|
|
270
|
+
case 34:
|
|
272
271
|
return _context.abrupt('return', source);
|
|
273
272
|
|
|
274
|
-
case
|
|
273
|
+
case 35:
|
|
275
274
|
case 'end':
|
|
276
275
|
return _context.stop();
|
|
277
276
|
}
|
|
@@ -531,7 +530,7 @@ exports.default = {
|
|
|
531
530
|
}).catch(function () {
|
|
532
531
|
return debug && console.error(e);
|
|
533
532
|
}).finally(function () {
|
|
534
|
-
return process.exit(
|
|
533
|
+
return process.exit(1);
|
|
535
534
|
});
|
|
536
535
|
};
|
|
537
536
|
|
|
@@ -635,7 +634,10 @@ exports.default = {
|
|
|
635
634
|
console.log('Unzipping files');
|
|
636
635
|
}
|
|
637
636
|
|
|
638
|
-
|
|
637
|
+
_context2.next = 91;
|
|
638
|
+
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
639
|
+
|
|
640
|
+
case 91:
|
|
639
641
|
|
|
640
642
|
if (debug) {
|
|
641
643
|
console.log('Finished unzipping files');
|
|
@@ -645,7 +647,7 @@ exports.default = {
|
|
|
645
647
|
|
|
646
648
|
return _context2.abrupt('return', protectionId);
|
|
647
649
|
|
|
648
|
-
case
|
|
650
|
+
case 94:
|
|
649
651
|
case 'end':
|
|
650
652
|
return _context2.stop();
|
|
651
653
|
}
|
|
@@ -753,7 +755,7 @@ exports.default = {
|
|
|
753
755
|
}).catch(function () {
|
|
754
756
|
return debug && console.error(e);
|
|
755
757
|
}).finally(function () {
|
|
756
|
-
return process.exit(
|
|
758
|
+
return process.exit(1);
|
|
757
759
|
});
|
|
758
760
|
};
|
|
759
761
|
|
|
@@ -784,7 +786,10 @@ exports.default = {
|
|
|
784
786
|
console.log('Unzipping files');
|
|
785
787
|
}
|
|
786
788
|
|
|
787
|
-
|
|
789
|
+
_context3.next = 35;
|
|
790
|
+
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
791
|
+
|
|
792
|
+
case 35:
|
|
788
793
|
|
|
789
794
|
if (debug) {
|
|
790
795
|
console.log('Finished unzipping files');
|
|
@@ -796,7 +801,7 @@ exports.default = {
|
|
|
796
801
|
|
|
797
802
|
return _context3.abrupt('return', instrumentation.data.id);
|
|
798
803
|
|
|
799
|
-
case
|
|
804
|
+
case 39:
|
|
800
805
|
case 'end':
|
|
801
806
|
return _context3.stop();
|
|
802
807
|
}
|
|
@@ -953,9 +958,10 @@ exports.default = {
|
|
|
953
958
|
errorHandler(_context5.t0);
|
|
954
959
|
|
|
955
960
|
case 18:
|
|
956
|
-
|
|
961
|
+
_context5.next = 20;
|
|
962
|
+
return (0, _zip.unzip)(download, filesDest || destCallback, stream);
|
|
957
963
|
|
|
958
|
-
case
|
|
964
|
+
case 20:
|
|
959
965
|
case 'end':
|
|
960
966
|
return _context5.stop();
|
|
961
967
|
}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getMatchedFiles = getMatchedFiles;
|
|
7
|
+
|
|
8
|
+
var _glob = require('glob');
|
|
9
|
+
|
|
10
|
+
var _glob2 = _interopRequireDefault(_glob);
|
|
11
|
+
|
|
12
|
+
var _fs = require('fs');
|
|
13
|
+
|
|
14
|
+
var _fs2 = _interopRequireDefault(_fs);
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Return the list of matched files for minimatch patterns.
|
|
20
|
+
* @param {string} pattern
|
|
21
|
+
* @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
function getMatchedFiles(pattern) {
|
|
24
|
+
var matchedFiles = _glob2.default.sync(pattern, {
|
|
25
|
+
dot: true
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// special case when the real file name contains a minimatch expression (f.e [id]-1234.js)
|
|
29
|
+
if (matchedFiles.length === 0 && _fs2.default.existsSync(pattern)) {
|
|
30
|
+
matchedFiles = [pattern];
|
|
31
|
+
}
|
|
32
|
+
return matchedFiles;
|
|
33
|
+
}
|
package/dist/zip.js
CHANGED
|
@@ -3,13 +3,239 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.outputFileSync = undefined;
|
|
6
|
+
exports.unzip = exports.zip = exports.outputFileSync = undefined;
|
|
7
7
|
|
|
8
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
8
|
+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
9
|
+
|
|
10
|
+
var zip = exports.zip = function () {
|
|
11
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(files, cwd) {
|
|
12
|
+
var deferred, hasFiles, _zip, zipFile, _zip2, i, l, buffer, name, sPath, tempFile;
|
|
13
|
+
|
|
14
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) {
|
|
16
|
+
switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
debug && console.log('Zipping files', (0, _util.inspect)(files));
|
|
19
|
+
deferred = (0, _q.defer)();
|
|
20
|
+
// Flag to detect if any file was added to the zip archive
|
|
21
|
+
|
|
22
|
+
hasFiles = false;
|
|
23
|
+
// Sanitize `cwd`
|
|
24
|
+
|
|
25
|
+
if (cwd) {
|
|
26
|
+
cwd = (0, _path2.normalize)(cwd);
|
|
27
|
+
}
|
|
28
|
+
// If it's already a zip file
|
|
29
|
+
|
|
30
|
+
if (!(files.length === 1 && /^.*\.zip$/.test(files[0]))) {
|
|
31
|
+
_context.next = 15;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
hasFiles = true;
|
|
36
|
+
_zip = new _jszip2.default();
|
|
37
|
+
zipFile = (0, _fsExtra.readFileSync)(files[0]);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
(0, _fsExtra.outputFileSync)(_temp2.default.openSync({ suffix: '.zip' }).path, zipFile);
|
|
41
|
+
_context.next = 11;
|
|
42
|
+
return _zip.loadAsync(zipFile);
|
|
43
|
+
|
|
44
|
+
case 11:
|
|
45
|
+
zipFile = _context.sent;
|
|
46
|
+
|
|
47
|
+
deferred.resolve(zipFile);
|
|
48
|
+
_context.next = 43;
|
|
49
|
+
break;
|
|
50
|
+
|
|
51
|
+
case 15:
|
|
52
|
+
_zip2 = new _jszip2.default();
|
|
53
|
+
i = 0, l = files.length;
|
|
54
|
+
|
|
55
|
+
case 17:
|
|
56
|
+
if (!(i < l)) {
|
|
57
|
+
_context.next = 29;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Sanitise path
|
|
62
|
+
if (typeof files[i] === 'string') {
|
|
63
|
+
files[i] = (0, _path2.normalize)(files[i]);
|
|
64
|
+
if (files[i].indexOf('../') === 0) {
|
|
65
|
+
files[i] = (0, _path2.resolve)(files[i]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Bypass unwanted patterns from `files`
|
|
69
|
+
|
|
70
|
+
if (!/.*\.(git|hg)(\/.*|$)/.test(files[i].path || files[i])) {
|
|
71
|
+
_context.next = 21;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return _context.abrupt('continue', 26);
|
|
76
|
+
|
|
77
|
+
case 21:
|
|
78
|
+
buffer = void 0, name = void 0;
|
|
79
|
+
sPath = void 0;
|
|
80
|
+
|
|
81
|
+
if (cwd && files[i].indexOf && files[i].indexOf(cwd) !== 0) {
|
|
82
|
+
sPath = (0, _path2.join)(cwd, files[i]);
|
|
83
|
+
} else {
|
|
84
|
+
sPath = files[i];
|
|
85
|
+
}
|
|
86
|
+
// If buffer
|
|
87
|
+
if (files[i].contents) {
|
|
88
|
+
name = (0, _path2.relative)(files[i].cwd, files[i].path);
|
|
89
|
+
buffer = files[i].contents;
|
|
90
|
+
} else if (!(0, _fsExtra.statSync)(sPath).isDirectory()) {
|
|
91
|
+
// Else if it's a path and not a directory
|
|
92
|
+
if (cwd && files[i].indexOf && files[i].indexOf(cwd) === 0) {
|
|
93
|
+
name = files[i].substring(cwd.length);
|
|
94
|
+
} else {
|
|
95
|
+
name = files[i];
|
|
96
|
+
}
|
|
97
|
+
buffer = (0, _fsExtra.readFileSync)(sPath);
|
|
98
|
+
} else {
|
|
99
|
+
// Else if it's a directory path
|
|
100
|
+
_zip2.folder(sPath);
|
|
101
|
+
}
|
|
102
|
+
if (name) {
|
|
103
|
+
hasFiles = true;
|
|
104
|
+
_zip2.file(name, buffer);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
case 26:
|
|
108
|
+
++i;
|
|
109
|
+
_context.next = 17;
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
case 29:
|
|
113
|
+
if (!hasFiles) {
|
|
114
|
+
_context.next = 42;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
tempFile = _temp2.default.openSync({ suffix: '.zip' });
|
|
119
|
+
_context.t0 = _fsExtra.outputFileSync;
|
|
120
|
+
_context.t1 = tempFile.path;
|
|
121
|
+
_context.next = 35;
|
|
122
|
+
return _zip2.generateAsync({ type: 'nodebuffer' });
|
|
123
|
+
|
|
124
|
+
case 35:
|
|
125
|
+
_context.t2 = _context.sent;
|
|
126
|
+
(0, _context.t0)(_context.t1, _context.t2);
|
|
127
|
+
|
|
128
|
+
files[0] = tempFile.path;
|
|
129
|
+
files.length = 1;
|
|
130
|
+
deferred.resolve(_zip2);
|
|
131
|
+
_context.next = 43;
|
|
132
|
+
break;
|
|
133
|
+
|
|
134
|
+
case 42:
|
|
135
|
+
throw new Error('No source files found. If you intend to send a whole directory sufix your path with "**" (e.g. ./my-directory/**)');
|
|
136
|
+
|
|
137
|
+
case 43:
|
|
138
|
+
return _context.abrupt('return', deferred.promise);
|
|
139
|
+
|
|
140
|
+
case 44:
|
|
141
|
+
case 'end':
|
|
142
|
+
return _context.stop();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, _callee, this);
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
return function zip(_x, _x2) {
|
|
149
|
+
return _ref.apply(this, arguments);
|
|
150
|
+
};
|
|
151
|
+
}();
|
|
152
|
+
|
|
153
|
+
var unzip = exports.unzip = function () {
|
|
154
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(zipFile, dest) {
|
|
155
|
+
var stream = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
156
|
+
|
|
157
|
+
var zip, _size, results, file, buffer, destPath, lastDestChar, _file;
|
|
158
|
+
|
|
159
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
160
|
+
while (1) {
|
|
161
|
+
switch (_context2.prev = _context2.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
zip = new _jszip2.default();
|
|
164
|
+
_context2.next = 3;
|
|
165
|
+
return zip.loadAsync(zipFile);
|
|
166
|
+
|
|
167
|
+
case 3:
|
|
168
|
+
_size = (0, _lodash2.default)(zip.files);
|
|
169
|
+
results = [];
|
|
170
|
+
_context2.t0 = regeneratorRuntime.keys(zip.files);
|
|
171
|
+
|
|
172
|
+
case 6:
|
|
173
|
+
if ((_context2.t1 = _context2.t0()).done) {
|
|
174
|
+
_context2.next = 15;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
file = _context2.t1.value;
|
|
179
|
+
|
|
180
|
+
if (zip.files[file].dir) {
|
|
181
|
+
_context2.next = 13;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
_context2.next = 11;
|
|
186
|
+
return zip.file(file).async('nodebuffer');
|
|
187
|
+
|
|
188
|
+
case 11:
|
|
189
|
+
buffer = _context2.sent;
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if (typeof dest === 'function') {
|
|
193
|
+
if (stream) {
|
|
194
|
+
dest(buffer, file);
|
|
195
|
+
} else {
|
|
196
|
+
results.push({ filename: file, content: buffer.toString() });
|
|
197
|
+
}
|
|
198
|
+
} else if (dest && typeof dest === 'string') {
|
|
199
|
+
lastDestChar = dest[dest.length - 1];
|
|
200
|
+
|
|
201
|
+
if (_size === 1 && lastDestChar !== '/' && lastDestChar !== '\\') {
|
|
202
|
+
destPath = dest;
|
|
203
|
+
} else {
|
|
204
|
+
_file = file;
|
|
205
|
+
// Deal with win path join c:\dest\:c\src
|
|
206
|
+
|
|
207
|
+
if (isWinAbsolutePath(_file)) {
|
|
208
|
+
_file = parseWinAbsolutePath(_file).path;
|
|
209
|
+
}
|
|
210
|
+
destPath = (0, _path2.join)(dest, _file);
|
|
211
|
+
}
|
|
212
|
+
(0, _fsExtra.outputFileSync)(destPath, buffer);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
case 13:
|
|
216
|
+
_context2.next = 6;
|
|
217
|
+
break;
|
|
218
|
+
|
|
219
|
+
case 15:
|
|
220
|
+
|
|
221
|
+
if (!stream) {
|
|
222
|
+
dest(results);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
case 16:
|
|
226
|
+
case 'end':
|
|
227
|
+
return _context2.stop();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}, _callee2, this);
|
|
231
|
+
}));
|
|
232
|
+
|
|
233
|
+
return function unzip(_x4, _x5) {
|
|
234
|
+
return _ref2.apply(this, arguments);
|
|
235
|
+
};
|
|
236
|
+
}();
|
|
9
237
|
|
|
10
|
-
exports.zip = zip;
|
|
11
238
|
exports.zipSources = zipSources;
|
|
12
|
-
exports.unzip = unzip;
|
|
13
239
|
|
|
14
240
|
var _lodash = require('lodash.size');
|
|
15
241
|
|
|
@@ -33,87 +259,12 @@ var _util = require('util');
|
|
|
33
259
|
|
|
34
260
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
261
|
|
|
262
|
+
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } // TODO Replace `sync` functions with async versions
|
|
263
|
+
|
|
36
264
|
var debug = !!process.env.DEBUG;
|
|
37
265
|
|
|
38
266
|
// ./zip.js module is excluded from browser-like environments. We take advantage of that here.
|
|
39
267
|
exports.outputFileSync = _fsExtra.outputFileSync;
|
|
40
|
-
function zip(files, cwd) {
|
|
41
|
-
debug && console.log('Zipping files', (0, _util.inspect)(files));
|
|
42
|
-
var deferred = (0, _q.defer)();
|
|
43
|
-
// Flag to detect if any file was added to the zip archive
|
|
44
|
-
var hasFiles = false;
|
|
45
|
-
// Sanitize `cwd`
|
|
46
|
-
if (cwd) {
|
|
47
|
-
cwd = (0, _path2.normalize)(cwd);
|
|
48
|
-
}
|
|
49
|
-
// If it's already a zip file
|
|
50
|
-
if (files.length === 1 && /^.*\.zip$/.test(files[0])) {
|
|
51
|
-
hasFiles = true;
|
|
52
|
-
var _zip = new _jszip2.default();
|
|
53
|
-
var zipFile = (0, _fsExtra.readFileSync)(files[0]);
|
|
54
|
-
|
|
55
|
-
(0, _fsExtra.outputFileSync)(_temp2.default.openSync({ suffix: '.zip' }).path, zipFile);
|
|
56
|
-
zipFile = _zip.load(zipFile);
|
|
57
|
-
deferred.resolve(zipFile);
|
|
58
|
-
} else {
|
|
59
|
-
var _zip2 = new _jszip2.default();
|
|
60
|
-
for (var i = 0, l = files.length; i < l; ++i) {
|
|
61
|
-
// Sanitise path
|
|
62
|
-
if (typeof files[i] === 'string') {
|
|
63
|
-
files[i] = (0, _path2.normalize)(files[i]);
|
|
64
|
-
if (files[i].indexOf('../') === 0) {
|
|
65
|
-
files[i] = (0, _path2.resolve)(files[i]);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Bypass unwanted patterns from `files`
|
|
69
|
-
if (/.*\.(git|hg)(\/.*|$)/.test(files[i].path || files[i])) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
var buffer = void 0,
|
|
73
|
-
name = void 0;
|
|
74
|
-
var sPath = void 0;
|
|
75
|
-
if (cwd && files[i].indexOf && files[i].indexOf(cwd) !== 0) {
|
|
76
|
-
sPath = (0, _path2.join)(cwd, files[i]);
|
|
77
|
-
} else {
|
|
78
|
-
sPath = files[i];
|
|
79
|
-
}
|
|
80
|
-
// If buffer
|
|
81
|
-
if (files[i].contents) {
|
|
82
|
-
name = (0, _path2.relative)(files[i].cwd, files[i].path);
|
|
83
|
-
buffer = files[i].contents;
|
|
84
|
-
} else if (!(0, _fsExtra.statSync)(sPath).isDirectory()) {
|
|
85
|
-
// Else if it's a path and not a directory
|
|
86
|
-
if (cwd && files[i].indexOf && files[i].indexOf(cwd) === 0) {
|
|
87
|
-
name = files[i].substring(cwd.length);
|
|
88
|
-
} else {
|
|
89
|
-
name = files[i];
|
|
90
|
-
}
|
|
91
|
-
buffer = (0, _fsExtra.readFileSync)(sPath);
|
|
92
|
-
} else {
|
|
93
|
-
// Else if it's a directory path
|
|
94
|
-
_zip2.folder(sPath);
|
|
95
|
-
}
|
|
96
|
-
if (name) {
|
|
97
|
-
hasFiles = true;
|
|
98
|
-
_zip2.file(name, buffer);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (hasFiles) {
|
|
102
|
-
var tempFile = _temp2.default.openSync({ suffix: '.zip' });
|
|
103
|
-
(0, _fsExtra.outputFileSync)(tempFile.path, _zip2.generate({ type: 'nodebuffer' }), {
|
|
104
|
-
encoding: 'base64'
|
|
105
|
-
});
|
|
106
|
-
files[0] = tempFile.path;
|
|
107
|
-
files.length = 1;
|
|
108
|
-
deferred.resolve(_zip2);
|
|
109
|
-
} else {
|
|
110
|
-
throw new Error('No source files found. If you intend to send a whole directory sufix your path with "**" (e.g. ./my-directory/**)');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return deferred.promise;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
268
|
function zipSources(sources) {
|
|
118
269
|
var zipFile = new _jszip2.default();
|
|
119
270
|
var fileNames = sources.map(function (source) {
|
|
@@ -142,46 +293,4 @@ function parseWinAbsolutePath(_path) {
|
|
|
142
293
|
drv: drv,
|
|
143
294
|
path: path
|
|
144
295
|
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function unzip(zipFile, dest) {
|
|
148
|
-
var stream = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
149
|
-
|
|
150
|
-
var zip = new _jszip2.default(zipFile);
|
|
151
|
-
var _size = (0, _lodash2.default)(zip.files);
|
|
152
|
-
|
|
153
|
-
var results = [];
|
|
154
|
-
|
|
155
|
-
for (var file in zip.files) {
|
|
156
|
-
if (!zip.files[file].options.dir) {
|
|
157
|
-
var buffer = zip.file(file).asNodeBuffer();
|
|
158
|
-
|
|
159
|
-
if (typeof dest === 'function') {
|
|
160
|
-
if (stream) {
|
|
161
|
-
dest(buffer, file);
|
|
162
|
-
} else {
|
|
163
|
-
results.push({ filename: file, content: buffer.toString() });
|
|
164
|
-
}
|
|
165
|
-
} else if (dest && typeof dest === 'string') {
|
|
166
|
-
var destPath;
|
|
167
|
-
|
|
168
|
-
var lastDestChar = dest[dest.length - 1];
|
|
169
|
-
if (_size === 1 && lastDestChar !== '/' && lastDestChar !== '\\') {
|
|
170
|
-
destPath = dest;
|
|
171
|
-
} else {
|
|
172
|
-
var _file = file;
|
|
173
|
-
// Deal with win path join c:\dest\:c\src
|
|
174
|
-
if (isWinAbsolutePath(_file)) {
|
|
175
|
-
_file = parseWinAbsolutePath(_file).path;
|
|
176
|
-
}
|
|
177
|
-
destPath = (0, _path2.join)(dest, _file);
|
|
178
|
-
}
|
|
179
|
-
(0, _fsExtra.outputFileSync)(destPath, buffer);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (!stream) {
|
|
185
|
-
dest(results);
|
|
186
|
-
}
|
|
187
296
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jscrambler",
|
|
3
3
|
"description": "Jscrambler API client.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.1",
|
|
5
5
|
"homepage": "https://github.com/jscrambler/jscrambler",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "magalhas",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"fs-extra": "^0.30.0",
|
|
39
39
|
"glob": "^7.0.3",
|
|
40
40
|
"http-proxy-agent": "^4.0.1",
|
|
41
|
-
"jszip": "^
|
|
41
|
+
"jszip": "^3.7.1",
|
|
42
42
|
"lodash.clone": "^4.0.3",
|
|
43
43
|
"lodash.clonedeep": "^4.5.0",
|
|
44
44
|
"lodash.defaults": "^4.0.1",
|