jscrambler 6.0.4 → 6.1.2
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/LICENSE-MIT +1 -1
- package/README.md +1 -0
- package/dist/bin/jscrambler.js +108 -131
- package/dist/cleanup-input-fields.js +4 -7
- package/dist/cli.js +8 -13
- package/dist/client.js +106 -85
- package/dist/config.js +7 -8
- package/dist/constants.js +10 -8
- package/dist/generate-signed-params.js +21 -26
- package/dist/get-protection-default-fragments.js +52 -50
- package/dist/index.js +1094 -1058
- package/dist/introspection.js +66 -66
- package/dist/mutations.js +81 -72
- package/dist/queries.js +39 -32
- package/dist/utils.js +24 -11
- package/dist/zip.js +152 -124
- package/package.json +8 -10
package/dist/queries.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getApplication = getApplication;
|
|
7
|
-
exports.getApplicationSource = getApplicationSource;
|
|
8
7
|
exports.getApplicationProtections = getApplicationProtections;
|
|
9
8
|
exports.getApplicationProtectionsCount = getApplicationProtectionsCount;
|
|
10
|
-
exports.
|
|
9
|
+
exports.getApplicationSource = getApplicationSource;
|
|
11
10
|
exports.getApplications = getApplications;
|
|
12
11
|
exports.getProtection = getProtection;
|
|
13
|
-
|
|
12
|
+
exports.getTemplates = getTemplates;
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
var getApplicationDefaultFragments = "\n _id,\n name,\n createdAt,\n sources {\n _id,\n filename,\n extension\n }\n";
|
|
14
21
|
/**
|
|
15
22
|
* Return one application by id.
|
|
16
23
|
* The options params argument can be used to filter protections by version and limit the number of protections returned.
|
|
@@ -18,96 +25,96 @@ var getApplicationDefaultFragments = '\n _id,\n name,\n createdAt,\n sources
|
|
|
18
25
|
* @param {fragment} fragments GraphQL fragment
|
|
19
26
|
* @param {Array} params {{String}protectionsVersion, {Integer} protectionsNumber}
|
|
20
27
|
*/
|
|
28
|
+
|
|
21
29
|
function getApplication(applicationId) {
|
|
22
30
|
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationDefaultFragments;
|
|
23
|
-
var params = arguments[2];
|
|
24
|
-
|
|
31
|
+
var params = arguments.length > 2 ? arguments[2] : undefined;
|
|
25
32
|
return {
|
|
26
|
-
query:
|
|
27
|
-
params: JSON.stringify(
|
|
33
|
+
query: "\n query getApplication ($applicationId: String!, $protectionsVersion: String, $protectionsLimit: Int) {\n application(_id: $applicationId, protectionsVersion: $protectionsVersion, protectionsLimit: $protectionsLimit) {\n ".concat(fragments, "\n }\n }\n "),
|
|
34
|
+
params: JSON.stringify(_objectSpread({
|
|
28
35
|
applicationId: applicationId
|
|
29
36
|
}, params))
|
|
30
37
|
};
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
var getApplicationSourceDefaultFragments =
|
|
40
|
+
var getApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n";
|
|
34
41
|
|
|
35
42
|
function getApplicationSource(sourceId) {
|
|
36
43
|
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationSourceDefaultFragments;
|
|
37
|
-
var limits = arguments[2];
|
|
38
|
-
|
|
44
|
+
var limits = arguments.length > 2 ? arguments[2] : undefined;
|
|
39
45
|
return {
|
|
40
|
-
query:
|
|
41
|
-
params: JSON.stringify(
|
|
46
|
+
query: "\n query getApplicationSource ($sourceId: String!, $contentLimit: Int, $transformedLimit: Int) {\n applicationSource(_id: $sourceId, contentLimit: $contentLimit, transformedLimit: $transformedLimit) {\n ".concat(fragments, "\n }\n }\n "),
|
|
47
|
+
params: JSON.stringify(_objectSpread({
|
|
42
48
|
sourceId: sourceId
|
|
43
49
|
}, limits))
|
|
44
50
|
};
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
var getApplicationProtectionsDefaultFragments =
|
|
53
|
+
var getApplicationProtectionsDefaultFragments = "\n _id,\n sources,\n parameters,\n finishedAt,\n randomizationSeed\n";
|
|
48
54
|
|
|
49
55
|
function getApplicationProtections(applicationId, params) {
|
|
50
56
|
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getApplicationProtectionsDefaultFragments;
|
|
51
|
-
|
|
57
|
+
var queryArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
52
58
|
return {
|
|
53
|
-
query:
|
|
54
|
-
|
|
59
|
+
query: "\n query getApplicationProtections ($applicationId: String!, $sort: String, $order: String, $limit: Int, $page: Int".concat(queryArgs.map(function (v) {
|
|
60
|
+
return ",".concat(v);
|
|
61
|
+
}), ") {\n applicationProtections(_id: $applicationId, sort: $sort, order: $order, limit: $limit, page: $page").concat(queryArgs.map(function (v) {
|
|
62
|
+
return ", ".concat(v.split(':')[0].replace('$', ''), ": ").concat(v.split(':')[0]);
|
|
63
|
+
}), ") {\n ").concat(fragments, "\n }\n }\n "),
|
|
64
|
+
params: JSON.stringify(_objectSpread({
|
|
55
65
|
applicationId: applicationId
|
|
56
66
|
}, params))
|
|
57
67
|
};
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
var getApplicationProtectionsCountDefaultFragments =
|
|
70
|
+
var getApplicationProtectionsCountDefaultFragments = "\n count\n";
|
|
61
71
|
|
|
62
72
|
function getApplicationProtectionsCount(applicationId) {
|
|
63
73
|
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationProtectionsCountDefaultFragments;
|
|
64
|
-
|
|
65
74
|
return {
|
|
66
|
-
query:
|
|
75
|
+
query: "\n query getApplicationProtectionsCount ($applicationId: String!) {\n applicationProtectionsCount(_id: $applicationId) {\n ".concat(fragments, "\n }\n }\n "),
|
|
67
76
|
params: JSON.stringify({
|
|
68
77
|
applicationId: applicationId
|
|
69
78
|
})
|
|
70
79
|
};
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
var getTemplatesDefaultFragments =
|
|
82
|
+
var getTemplatesDefaultFragments = "\n _id,\n parameters\n";
|
|
74
83
|
|
|
75
84
|
function getTemplates() {
|
|
76
85
|
var fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getTemplatesDefaultFragments;
|
|
77
|
-
|
|
78
86
|
return {
|
|
79
|
-
query:
|
|
87
|
+
query: "\n query getTemplates {\n templates {\n ".concat(fragments, "\n }\n }\n "),
|
|
80
88
|
params: '{}'
|
|
81
89
|
};
|
|
82
90
|
}
|
|
83
91
|
|
|
84
|
-
var getApplicationsDefaultFragments =
|
|
92
|
+
var getApplicationsDefaultFragments = "\n _id,\n name,\n protections,\n parameters\n";
|
|
85
93
|
/**
|
|
86
94
|
* Return all applications.
|
|
87
95
|
* The options params argument can be used to filter protections by version and limit the number of protections returned.
|
|
88
96
|
* @param {fragment} fragments GraphQL fragment
|
|
89
97
|
* @param {Array} params {{String}protectionsVersion, {Integer} protectionsNumber}
|
|
90
98
|
*/
|
|
99
|
+
|
|
91
100
|
function getApplications() {
|
|
92
101
|
var fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getApplicationsDefaultFragments;
|
|
93
|
-
var params = arguments[1];
|
|
94
|
-
|
|
102
|
+
var params = arguments.length > 1 ? arguments[1] : undefined;
|
|
95
103
|
return {
|
|
96
|
-
query:
|
|
97
|
-
params: JSON.stringify(
|
|
104
|
+
query: "\n query getApplications($protectionsVersion:String, $protectionsLimit: Int) {\n applications(protectionsVersion: $protectionsVersion, protectionsLimit: $protectionsLimit) {\n ".concat(fragments, "\n }\n }\n "),
|
|
105
|
+
params: JSON.stringify(_objectSpread({}, params))
|
|
98
106
|
};
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
var getProtectionDefaultFragments = {
|
|
102
|
-
application:
|
|
103
|
-
applicationProtection:
|
|
110
|
+
application: "\n name\n ",
|
|
111
|
+
applicationProtection: "\n _id,\n state,\n bail,\n deprecations {\n type,\n entity\n },\n errorMessage,\n sources {\n filename,\n errorMessages {\n message,\n line,\n column,\n fatal\n }\n }\n "
|
|
104
112
|
};
|
|
105
113
|
|
|
106
114
|
function getProtection(applicationId, protectionId) {
|
|
107
115
|
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getProtectionDefaultFragments;
|
|
108
|
-
|
|
109
116
|
return {
|
|
110
|
-
query:
|
|
117
|
+
query: "\n query getProtection ($applicationId: String!, $protectionId: String!) {\n application (_id: $applicationId) {\n ".concat(fragments.application, "\n }\n applicationProtection (_id: $protectionId) {\n ").concat(fragments.applicationProtection, "\n }\n }\n "),
|
|
111
118
|
params: JSON.stringify({
|
|
112
119
|
applicationId: applicationId,
|
|
113
120
|
protectionId: protectionId
|
package/dist/utils.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getMatchedFiles = getMatchedFiles;
|
|
7
|
+
exports.validateNProtections = validateNProtections;
|
|
7
8
|
|
|
8
|
-
var _glob = require(
|
|
9
|
+
var _glob = _interopRequireDefault(require("glob"));
|
|
9
10
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _fs = require('fs');
|
|
13
|
-
|
|
14
|
-
var _fs2 = _interopRequireDefault(_fs);
|
|
11
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
15
12
|
|
|
16
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
14
|
|
|
@@ -21,13 +18,29 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
18
|
* @returns {string[]}
|
|
22
19
|
*/
|
|
23
20
|
function getMatchedFiles(pattern) {
|
|
24
|
-
var matchedFiles =
|
|
21
|
+
var matchedFiles = _glob.default.sync(pattern, {
|
|
25
22
|
dot: true
|
|
26
|
-
});
|
|
23
|
+
}); // special case when the real file name contains a minimatch expression (f.e [id]-1234.js)
|
|
24
|
+
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
if (matchedFiles.length === 0 && _fs2.default.existsSync(pattern)) {
|
|
26
|
+
if (matchedFiles.length === 0 && _fs.default.existsSync(pattern)) {
|
|
30
27
|
matchedFiles = [pattern];
|
|
31
28
|
}
|
|
29
|
+
|
|
32
30
|
return matchedFiles;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function validateNProtections(n) {
|
|
34
|
+
if (n === undefined) {
|
|
35
|
+
return n;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var nProtections = parseInt(n, 10);
|
|
39
|
+
|
|
40
|
+
if (Number.isNaN(nProtections) || nProtections.toString() !== n.toString() || nProtections < 1) {
|
|
41
|
+
console.error("*protections* requires an integer greater than 0.");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return nProtections;
|
|
33
46
|
}
|
package/dist/zip.js
CHANGED
|
@@ -1,31 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
6
|
+
Object.defineProperty(exports, "outputFileSync", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _fsExtra.outputFileSync;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.unzip = unzip;
|
|
13
|
+
exports.zip = zip;
|
|
14
|
+
exports.zipSources = zipSources;
|
|
15
|
+
|
|
16
|
+
var _lodash = _interopRequireDefault(require("lodash.size"));
|
|
17
|
+
|
|
18
|
+
var _temp = _interopRequireDefault(require("temp"));
|
|
19
|
+
|
|
20
|
+
var _jszip = _interopRequireDefault(require("jszip"));
|
|
21
|
+
|
|
22
|
+
var _fsExtra = require("fs-extra");
|
|
23
|
+
|
|
24
|
+
var _path2 = require("path");
|
|
25
|
+
|
|
26
|
+
var _q = require("q");
|
|
27
|
+
|
|
28
|
+
var _util = require("util");
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
|
|
32
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
33
|
+
|
|
34
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
35
|
+
|
|
36
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
|
+
|
|
38
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
7
39
|
|
|
8
|
-
var
|
|
40
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
9
41
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
42
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
43
|
+
|
|
44
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
45
|
+
|
|
46
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
47
|
+
|
|
48
|
+
var debug = !!process.env.DEBUG; // ./zip.js module is excluded from browser-like environments. We take advantage of that here.
|
|
49
|
+
|
|
50
|
+
function zip(_x, _x2) {
|
|
51
|
+
return _zip.apply(this, arguments);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _zip() {
|
|
55
|
+
_zip = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(files, cwd) {
|
|
56
|
+
var deferred, hasFiles, _zip2, zipFile, _zip3, i, l, buffer, name, sPath, tempFile;
|
|
13
57
|
|
|
14
58
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
59
|
while (1) {
|
|
16
60
|
switch (_context.prev = _context.next) {
|
|
17
61
|
case 0:
|
|
18
62
|
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
|
|
63
|
+
deferred = (0, _q.defer)(); // Flag to detect if any file was added to the zip archive
|
|
21
64
|
|
|
22
|
-
hasFiles = false;
|
|
23
|
-
// Sanitize `cwd`
|
|
65
|
+
hasFiles = false; // Sanitize `cwd`
|
|
24
66
|
|
|
25
67
|
if (cwd) {
|
|
26
68
|
cwd = (0, _path2.normalize)(cwd);
|
|
27
|
-
}
|
|
28
|
-
|
|
69
|
+
} // If it's already a zip file
|
|
70
|
+
|
|
29
71
|
|
|
30
72
|
if (!(files.length === 1 && /^.*\.zip$/.test(files[0]))) {
|
|
31
73
|
_context.next = 15;
|
|
@@ -33,23 +75,22 @@ var zip = exports.zip = function () {
|
|
|
33
75
|
}
|
|
34
76
|
|
|
35
77
|
hasFiles = true;
|
|
36
|
-
|
|
78
|
+
_zip2 = new _jszip.default();
|
|
37
79
|
zipFile = (0, _fsExtra.readFileSync)(files[0]);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
80
|
+
(0, _fsExtra.outputFileSync)(_temp.default.openSync({
|
|
81
|
+
suffix: '.zip'
|
|
82
|
+
}).path, zipFile);
|
|
41
83
|
_context.next = 11;
|
|
42
|
-
return
|
|
84
|
+
return _zip2.loadAsync(zipFile);
|
|
43
85
|
|
|
44
86
|
case 11:
|
|
45
87
|
zipFile = _context.sent;
|
|
46
|
-
|
|
47
88
|
deferred.resolve(zipFile);
|
|
48
89
|
_context.next = 43;
|
|
49
90
|
break;
|
|
50
91
|
|
|
51
92
|
case 15:
|
|
52
|
-
|
|
93
|
+
_zip3 = new _jszip.default();
|
|
53
94
|
i = 0, l = files.length;
|
|
54
95
|
|
|
55
96
|
case 17:
|
|
@@ -61,18 +102,19 @@ var zip = exports.zip = function () {
|
|
|
61
102
|
// Sanitise path
|
|
62
103
|
if (typeof files[i] === 'string') {
|
|
63
104
|
files[i] = (0, _path2.normalize)(files[i]);
|
|
105
|
+
|
|
64
106
|
if (files[i].indexOf('../') === 0) {
|
|
65
107
|
files[i] = (0, _path2.resolve)(files[i]);
|
|
66
108
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
109
|
+
} // Bypass unwanted patterns from `files`
|
|
110
|
+
|
|
69
111
|
|
|
70
112
|
if (!/.*\.(git|hg)(\/.*|$)/.test(files[i].path || files[i])) {
|
|
71
113
|
_context.next = 21;
|
|
72
114
|
break;
|
|
73
115
|
}
|
|
74
116
|
|
|
75
|
-
return _context.abrupt(
|
|
117
|
+
return _context.abrupt("continue", 26);
|
|
76
118
|
|
|
77
119
|
case 21:
|
|
78
120
|
buffer = void 0, name = void 0;
|
|
@@ -82,8 +124,9 @@ var zip = exports.zip = function () {
|
|
|
82
124
|
sPath = (0, _path2.join)(cwd, files[i]);
|
|
83
125
|
} else {
|
|
84
126
|
sPath = files[i];
|
|
85
|
-
}
|
|
86
|
-
|
|
127
|
+
} // If buffer
|
|
128
|
+
|
|
129
|
+
|
|
87
130
|
if (files[i].contents) {
|
|
88
131
|
name = (0, _path2.relative)(files[i].cwd, files[i].path);
|
|
89
132
|
buffer = files[i].contents;
|
|
@@ -94,14 +137,17 @@ var zip = exports.zip = function () {
|
|
|
94
137
|
} else {
|
|
95
138
|
name = files[i];
|
|
96
139
|
}
|
|
140
|
+
|
|
97
141
|
buffer = (0, _fsExtra.readFileSync)(sPath);
|
|
98
142
|
} else {
|
|
99
143
|
// Else if it's a directory path
|
|
100
|
-
|
|
144
|
+
_zip3.folder(sPath);
|
|
101
145
|
}
|
|
146
|
+
|
|
102
147
|
if (name) {
|
|
103
148
|
hasFiles = true;
|
|
104
|
-
|
|
149
|
+
|
|
150
|
+
_zip3.file(name, buffer);
|
|
105
151
|
}
|
|
106
152
|
|
|
107
153
|
case 26:
|
|
@@ -115,19 +161,22 @@ var zip = exports.zip = function () {
|
|
|
115
161
|
break;
|
|
116
162
|
}
|
|
117
163
|
|
|
118
|
-
tempFile =
|
|
164
|
+
tempFile = _temp.default.openSync({
|
|
165
|
+
suffix: '.zip'
|
|
166
|
+
});
|
|
119
167
|
_context.t0 = _fsExtra.outputFileSync;
|
|
120
168
|
_context.t1 = tempFile.path;
|
|
121
169
|
_context.next = 35;
|
|
122
|
-
return
|
|
170
|
+
return _zip3.generateAsync({
|
|
171
|
+
type: 'nodebuffer'
|
|
172
|
+
});
|
|
123
173
|
|
|
124
174
|
case 35:
|
|
125
175
|
_context.t2 = _context.sent;
|
|
126
176
|
(0, _context.t0)(_context.t1, _context.t2);
|
|
127
|
-
|
|
128
177
|
files[0] = tempFile.path;
|
|
129
178
|
files.length = 1;
|
|
130
|
-
deferred.resolve(
|
|
179
|
+
deferred.resolve(_zip3);
|
|
131
180
|
_context.next = 43;
|
|
132
181
|
break;
|
|
133
182
|
|
|
@@ -135,65 +184,107 @@ var zip = exports.zip = function () {
|
|
|
135
184
|
throw new Error('No source files found. If you intend to send a whole directory sufix your path with "**" (e.g. ./my-directory/**)');
|
|
136
185
|
|
|
137
186
|
case 43:
|
|
138
|
-
return _context.abrupt(
|
|
187
|
+
return _context.abrupt("return", deferred.promise);
|
|
139
188
|
|
|
140
189
|
case 44:
|
|
141
|
-
case
|
|
190
|
+
case "end":
|
|
142
191
|
return _context.stop();
|
|
143
192
|
}
|
|
144
193
|
}
|
|
145
|
-
}, _callee
|
|
194
|
+
}, _callee);
|
|
146
195
|
}));
|
|
196
|
+
return _zip.apply(this, arguments);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function zipSources(sources) {
|
|
200
|
+
var zipFile = new _jszip.default();
|
|
201
|
+
var fileNames = sources.map(function (source) {
|
|
202
|
+
zipFile.file(source.filename, source.content);
|
|
203
|
+
return source.filename;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (debug) {
|
|
207
|
+
console.log('Zipping files', (0, _util.inspect)(fileNames));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return Promise.resolve(zipFile);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function isWinAbsolutePath(path) {
|
|
214
|
+
return (0, _path2.isAbsolute)(path) && /^([a-z]:)(.*)/i.test(path);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function parseWinAbsolutePath(_path) {
|
|
218
|
+
var _path$match = _path.match(/^([a-z]:)(.*)/i),
|
|
219
|
+
_path$match2 = _slicedToArray(_path$match, 3),
|
|
220
|
+
full = _path$match2[0],
|
|
221
|
+
drv = _path$match2[1],
|
|
222
|
+
path = _path$match2[2];
|
|
147
223
|
|
|
148
|
-
return
|
|
149
|
-
|
|
224
|
+
return {
|
|
225
|
+
drv: drv,
|
|
226
|
+
path: path
|
|
150
227
|
};
|
|
151
|
-
}
|
|
228
|
+
}
|
|
152
229
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
230
|
+
function unzip(_x3, _x4) {
|
|
231
|
+
return _unzip.apply(this, arguments);
|
|
232
|
+
}
|
|
156
233
|
|
|
157
|
-
|
|
234
|
+
function _unzip() {
|
|
235
|
+
_unzip = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(zipFile, dest) {
|
|
236
|
+
var stream,
|
|
237
|
+
zip,
|
|
238
|
+
_size,
|
|
239
|
+
results,
|
|
240
|
+
file,
|
|
241
|
+
buffer,
|
|
242
|
+
destPath,
|
|
243
|
+
lastDestChar,
|
|
244
|
+
_file,
|
|
245
|
+
_args2 = arguments;
|
|
158
246
|
|
|
159
247
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
160
248
|
while (1) {
|
|
161
249
|
switch (_context2.prev = _context2.next) {
|
|
162
250
|
case 0:
|
|
163
|
-
|
|
164
|
-
|
|
251
|
+
stream = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : true;
|
|
252
|
+
zip = new _jszip.default();
|
|
253
|
+
_context2.next = 4;
|
|
165
254
|
return zip.loadAsync(zipFile);
|
|
166
255
|
|
|
167
|
-
case
|
|
168
|
-
_size = (0,
|
|
256
|
+
case 4:
|
|
257
|
+
_size = (0, _lodash.default)(zip.files);
|
|
169
258
|
results = [];
|
|
170
259
|
_context2.t0 = regeneratorRuntime.keys(zip.files);
|
|
171
260
|
|
|
172
|
-
case
|
|
261
|
+
case 7:
|
|
173
262
|
if ((_context2.t1 = _context2.t0()).done) {
|
|
174
|
-
_context2.next =
|
|
263
|
+
_context2.next = 16;
|
|
175
264
|
break;
|
|
176
265
|
}
|
|
177
266
|
|
|
178
267
|
file = _context2.t1.value;
|
|
179
268
|
|
|
180
269
|
if (zip.files[file].dir) {
|
|
181
|
-
_context2.next =
|
|
270
|
+
_context2.next = 14;
|
|
182
271
|
break;
|
|
183
272
|
}
|
|
184
273
|
|
|
185
|
-
_context2.next =
|
|
274
|
+
_context2.next = 12;
|
|
186
275
|
return zip.file(file).async('nodebuffer');
|
|
187
276
|
|
|
188
|
-
case
|
|
277
|
+
case 12:
|
|
189
278
|
buffer = _context2.sent;
|
|
190
279
|
|
|
191
|
-
|
|
192
280
|
if (typeof dest === 'function') {
|
|
193
281
|
if (stream) {
|
|
194
282
|
dest(buffer, file);
|
|
195
283
|
} else {
|
|
196
|
-
results.push({
|
|
284
|
+
results.push({
|
|
285
|
+
filename: file,
|
|
286
|
+
content: buffer.toString()
|
|
287
|
+
});
|
|
197
288
|
}
|
|
198
289
|
} else if (dest && typeof dest === 'string') {
|
|
199
290
|
lastDestChar = dest[dest.length - 1];
|
|
@@ -201,96 +292,33 @@ var unzip = exports.unzip = function () {
|
|
|
201
292
|
if (_size === 1 && lastDestChar !== '/' && lastDestChar !== '\\') {
|
|
202
293
|
destPath = dest;
|
|
203
294
|
} else {
|
|
204
|
-
_file = file;
|
|
205
|
-
// Deal with win path join c:\dest\:c\src
|
|
295
|
+
_file = file; // Deal with win path join c:\dest\:c\src
|
|
206
296
|
|
|
207
297
|
if (isWinAbsolutePath(_file)) {
|
|
208
298
|
_file = parseWinAbsolutePath(_file).path;
|
|
209
299
|
}
|
|
300
|
+
|
|
210
301
|
destPath = (0, _path2.join)(dest, _file);
|
|
211
302
|
}
|
|
303
|
+
|
|
212
304
|
(0, _fsExtra.outputFileSync)(destPath, buffer);
|
|
213
305
|
}
|
|
214
306
|
|
|
215
|
-
case
|
|
216
|
-
_context2.next =
|
|
307
|
+
case 14:
|
|
308
|
+
_context2.next = 7;
|
|
217
309
|
break;
|
|
218
310
|
|
|
219
|
-
case
|
|
220
|
-
|
|
311
|
+
case 16:
|
|
221
312
|
if (!stream) {
|
|
222
313
|
dest(results);
|
|
223
314
|
}
|
|
224
315
|
|
|
225
|
-
case
|
|
226
|
-
case
|
|
316
|
+
case 17:
|
|
317
|
+
case "end":
|
|
227
318
|
return _context2.stop();
|
|
228
319
|
}
|
|
229
320
|
}
|
|
230
|
-
}, _callee2
|
|
321
|
+
}, _callee2);
|
|
231
322
|
}));
|
|
232
|
-
|
|
233
|
-
return function unzip(_x4, _x5) {
|
|
234
|
-
return _ref2.apply(this, arguments);
|
|
235
|
-
};
|
|
236
|
-
}();
|
|
237
|
-
|
|
238
|
-
exports.zipSources = zipSources;
|
|
239
|
-
|
|
240
|
-
var _lodash = require('lodash.size');
|
|
241
|
-
|
|
242
|
-
var _lodash2 = _interopRequireDefault(_lodash);
|
|
243
|
-
|
|
244
|
-
var _temp = require('temp');
|
|
245
|
-
|
|
246
|
-
var _temp2 = _interopRequireDefault(_temp);
|
|
247
|
-
|
|
248
|
-
var _jszip = require('jszip');
|
|
249
|
-
|
|
250
|
-
var _jszip2 = _interopRequireDefault(_jszip);
|
|
251
|
-
|
|
252
|
-
var _fsExtra = require('fs-extra');
|
|
253
|
-
|
|
254
|
-
var _path2 = require('path');
|
|
255
|
-
|
|
256
|
-
var _q = require('q');
|
|
257
|
-
|
|
258
|
-
var _util = require('util');
|
|
259
|
-
|
|
260
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
-
|
|
264
|
-
var debug = !!process.env.DEBUG;
|
|
265
|
-
|
|
266
|
-
// ./zip.js module is excluded from browser-like environments. We take advantage of that here.
|
|
267
|
-
exports.outputFileSync = _fsExtra.outputFileSync;
|
|
268
|
-
function zipSources(sources) {
|
|
269
|
-
var zipFile = new _jszip2.default();
|
|
270
|
-
var fileNames = sources.map(function (source) {
|
|
271
|
-
zipFile.file(source.filename, source.content);
|
|
272
|
-
return source.filename;
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
if (debug) {
|
|
276
|
-
console.log('Zipping files', (0, _util.inspect)(fileNames));
|
|
277
|
-
}
|
|
278
|
-
return Promise.resolve(zipFile);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function isWinAbsolutePath(path) {
|
|
282
|
-
return (0, _path2.isAbsolute)(path) && /^([a-z]:)(.*)/i.test(path);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function parseWinAbsolutePath(_path) {
|
|
286
|
-
var _path$match = _path.match(/^([a-z]:)(.*)/i),
|
|
287
|
-
_path$match2 = _slicedToArray(_path$match, 3),
|
|
288
|
-
full = _path$match2[0],
|
|
289
|
-
drv = _path$match2[1],
|
|
290
|
-
path = _path$match2[2];
|
|
291
|
-
|
|
292
|
-
return {
|
|
293
|
-
drv: drv,
|
|
294
|
-
path: path
|
|
295
|
-
};
|
|
323
|
+
return _unzip.apply(this, arguments);
|
|
296
324
|
}
|