datagrok-tools 4.13.74 → 4.13.76
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/bin/commands/add.js +96 -106
- package/bin/commands/api.js +65 -107
- package/bin/commands/check.js +264 -396
- package/bin/commands/config.js +82 -158
- package/bin/commands/create.js +65 -80
- package/bin/commands/help.js +194 -12
- package/bin/commands/init.js +73 -95
- package/bin/commands/link.js +70 -176
- package/bin/commands/publish.js +283 -484
- package/bin/commands/test-all.js +77 -291
- package/bin/commands/test.js +169 -391
- package/bin/utils/color-utils.js +8 -11
- package/bin/utils/ent-helpers.js +52 -42
- package/bin/utils/func-generation.js +25 -57
- package/bin/utils/interfaces.js +5 -1
- package/bin/utils/order-functions.js +47 -118
- package/bin/utils/test-utils.js +322 -750
- package/bin/utils/utils.js +123 -235
- package/bin/validators/config-validator.js +12 -14
- package/package.json +13 -4
package/bin/commands/publish.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.processPackage = processPackage;
|
|
9
8
|
exports.publish = publish;
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
9
|
var _archiverPromise = _interopRequireDefault(require("archiver-promise"));
|
|
14
10
|
var _fs = _interopRequireDefault(require("fs"));
|
|
15
11
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
@@ -21,493 +17,296 @@ var _testUtils = require("../utils/test-utils");
|
|
|
21
17
|
var _check = require("./check");
|
|
22
18
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
23
19
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
24
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
25
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
26
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
27
|
-
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); }
|
|
28
|
-
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; } // @ts-ignore
|
|
20
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
29
22
|
// @ts-ignore
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
exec
|
|
28
|
+
} = require('child_process');
|
|
29
|
+
const grokDir = _path.default.join(_os.default.homedir(), '.grok');
|
|
30
|
+
const confPath = _path.default.join(grokDir, 'config.yaml');
|
|
31
|
+
const confTemplateDir = _path.default.join(_path.default.dirname(_path.default.dirname(__dirname)), 'config-template.yaml');
|
|
32
|
+
const confTemplate = _jsYaml.default.load(_fs.default.readFileSync(confTemplateDir, {
|
|
36
33
|
encoding: 'utf-8'
|
|
37
34
|
}));
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function processPackage(
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
timestamps = {};
|
|
53
|
-
url = "".concat(host, "/packages/dev/").concat(devKey, "/").concat(packageName);
|
|
54
|
-
if (!debug) {
|
|
55
|
-
_context2.next = 18;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
_context2.prev = 3;
|
|
59
|
-
_context2.next = 6;
|
|
60
|
-
return (0, _nodeFetch["default"])(url + '/timestamps');
|
|
61
|
-
case 6:
|
|
62
|
-
_context2.next = 8;
|
|
63
|
-
return _context2.sent.json();
|
|
64
|
-
case 8:
|
|
65
|
-
timestamps = _context2.sent;
|
|
66
|
-
if (!(timestamps['#type'] === 'ApiError')) {
|
|
67
|
-
_context2.next = 12;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
color.error(timestamps.message);
|
|
71
|
-
return _context2.abrupt("return", 1);
|
|
72
|
-
case 12:
|
|
73
|
-
_context2.next = 18;
|
|
74
|
-
break;
|
|
75
|
-
case 14:
|
|
76
|
-
_context2.prev = 14;
|
|
77
|
-
_context2.t0 = _context2["catch"](3);
|
|
78
|
-
console.error(_context2.t0);
|
|
79
|
-
return _context2.abrupt("return", 1);
|
|
80
|
-
case 18:
|
|
81
|
-
zip = (0, _archiverPromise["default"])('zip', {
|
|
82
|
-
store: false
|
|
83
|
-
}); // Gather the files
|
|
84
|
-
localTimestamps = {};
|
|
85
|
-
_context2.next = 22;
|
|
86
|
-
return (0, _ignoreWalk["default"])({
|
|
87
|
-
path: '.',
|
|
88
|
-
ignoreFiles: ['.npmignore', '.gitignore', '.grokignore'],
|
|
89
|
-
includeEmpty: false,
|
|
90
|
-
follow: true
|
|
91
|
-
});
|
|
92
|
-
case 22:
|
|
93
|
-
files = _context2.sent;
|
|
94
|
-
isWebpack = _fs["default"].existsSync('webpack.config.js');
|
|
95
|
-
if (!(!rebuild && isWebpack)) {
|
|
96
|
-
_context2.next = 34;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (!_fs["default"].existsSync('dist/package.js')) {
|
|
100
|
-
_context2.next = 32;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
_context2.next = 28;
|
|
104
|
-
return (0, _ignoreWalk["default"])({
|
|
105
|
-
path: './dist',
|
|
106
|
-
ignoreFiles: [],
|
|
107
|
-
includeEmpty: false,
|
|
108
|
-
follow: true
|
|
109
|
-
});
|
|
110
|
-
case 28:
|
|
111
|
-
distFiles = _context2.sent;
|
|
112
|
-
distFiles.forEach(function (df) {
|
|
113
|
-
files.push("dist/".concat(df));
|
|
114
|
-
});
|
|
115
|
-
_context2.next = 34;
|
|
116
|
-
break;
|
|
117
|
-
case 32:
|
|
118
|
-
color.warn('File `dist/package.js` not found. Building the package on the server side...\n' + 'Next time, please build your package locally with Webpack beforehand\n' + 'or run `grok publish` with the `--rebuild` option');
|
|
119
|
-
rebuild = true;
|
|
120
|
-
case 34:
|
|
121
|
-
contentValidationLog = '';
|
|
122
|
-
console.log('Starting package checks...');
|
|
123
|
-
checkStart = Date.now();
|
|
124
|
-
jsTsFiles = files.filter(function (f) {
|
|
125
|
-
return !f.startsWith('dist/') && (f.endsWith('.js') || f.endsWith('.ts'));
|
|
126
|
-
});
|
|
127
|
-
packageFilePath = _path["default"].join(curDir, 'package.json');
|
|
128
|
-
json = JSON.parse(_fs["default"].readFileSync(packageFilePath, {
|
|
129
|
-
encoding: 'utf-8'
|
|
130
|
-
}));
|
|
131
|
-
if (isWebpack) {
|
|
132
|
-
webpackConfigPath = _path["default"].join(curDir, 'webpack.config.js');
|
|
133
|
-
content = _fs["default"].readFileSync(webpackConfigPath, {
|
|
134
|
-
encoding: 'utf-8'
|
|
135
|
-
});
|
|
136
|
-
externals = (0, _check.extractExternals)(content);
|
|
137
|
-
if (externals) {
|
|
138
|
-
importWarnings = (0, _check.checkImportStatements)(curDir, jsTsFiles, externals);
|
|
139
|
-
contentValidationLog += importWarnings.join('\n') + (importWarnings.length ? '\n' : '');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
funcFiles = jsTsFiles.filter(function (f) {
|
|
143
|
-
return packageFiles.includes(f);
|
|
144
|
-
});
|
|
145
|
-
funcWarnings = (0, _check.checkFuncSignatures)(curDir, funcFiles);
|
|
146
|
-
contentValidationLog += funcWarnings.join('\n') + (funcWarnings.length ? '\n' : '');
|
|
147
|
-
packageWarnings = (0, _check.checkPackageFile)(curDir, json);
|
|
148
|
-
contentValidationLog += packageWarnings.join('\n') + (packageWarnings.length ? '\n' : '');
|
|
149
|
-
changelogWarnings = (0, _check.checkChangelog)(curDir, json);
|
|
150
|
-
contentValidationLog += changelogWarnings.join('\n') + (packageWarnings.length ? '\n' : '');
|
|
151
|
-
console.log("Checks finished in ".concat(Date.now() - checkStart, " ms"));
|
|
152
|
-
reg = new RegExp(/\${(\w*)}/g);
|
|
153
|
-
errs = [];
|
|
154
|
-
files.forEach(function (file) {
|
|
155
|
-
var fullPath = file;
|
|
156
|
-
var relativePath = _path["default"].relative(curDir, fullPath);
|
|
157
|
-
var canonicalRelativePath = relativePath.replace(/\\/g, '/');
|
|
158
|
-
if (canonicalRelativePath.includes('/.')) return;
|
|
159
|
-
if (canonicalRelativePath.startsWith('.')) return;
|
|
160
|
-
if (relativePath.startsWith('node_modules')) return;
|
|
161
|
-
if (relativePath.startsWith('dist') && rebuild) return;
|
|
162
|
-
if (relativePath.startsWith('src') && !rebuild && isWebpack) {
|
|
163
|
-
if (!relativePath.startsWith('src/package') && !relativePath.startsWith('src\\package')) return;
|
|
164
|
-
}
|
|
165
|
-
if (relativePath.startsWith('upload.keys.json')) return;
|
|
166
|
-
if (relativePath === 'zip') return;
|
|
167
|
-
if (!utils.checkScriptLocation(canonicalRelativePath)) {
|
|
168
|
-
contentValidationLog += "Warning: file `".concat(canonicalRelativePath, "`") + " should be in directory `".concat(_path["default"].basename(curDir), "/scripts/`\n");
|
|
169
|
-
}
|
|
170
|
-
var t = _fs["default"].statSync(fullPath).mtime.toUTCString();
|
|
171
|
-
localTimestamps[canonicalRelativePath] = t;
|
|
172
|
-
if (debug && timestamps[canonicalRelativePath] === t) {
|
|
173
|
-
console.log("Skipping ".concat(canonicalRelativePath));
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (canonicalRelativePath.startsWith('connections/')) {
|
|
177
|
-
var f = _fs["default"].readFileSync(fullPath, {
|
|
178
|
-
encoding: 'utf-8'
|
|
179
|
-
});
|
|
180
|
-
var matches = (0, _toConsumableArray2["default"])(f.matchAll(reg));
|
|
181
|
-
var _iterator = _createForOfIteratorHelper(matches),
|
|
182
|
-
_step;
|
|
183
|
-
try {
|
|
184
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
185
|
-
var m = _step.value;
|
|
186
|
-
var envVar = process.env[m[1]];
|
|
187
|
-
if (!envVar) {
|
|
188
|
-
errs.push("".concat(canonicalRelativePath, ": cannot find environment variable \"").concat(m[1], "\""));
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
f = f.replace(m[0], envVar);
|
|
192
|
-
}
|
|
193
|
-
} catch (err) {
|
|
194
|
-
_iterator.e(err);
|
|
195
|
-
} finally {
|
|
196
|
-
_iterator.f();
|
|
197
|
-
}
|
|
198
|
-
zip.append(f, {
|
|
199
|
-
name: relativePath
|
|
200
|
-
});
|
|
201
|
-
console.log("Adding ".concat(canonicalRelativePath, "..."));
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
zip.append(_fs["default"].createReadStream(fullPath), {
|
|
205
|
-
name: relativePath
|
|
206
|
-
});
|
|
207
|
-
console.log("Adding ".concat(canonicalRelativePath, "..."));
|
|
208
|
-
});
|
|
209
|
-
if (!errs.length) {
|
|
210
|
-
_context2.next = 55;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
errs.forEach(function (e) {
|
|
214
|
-
return color.error(e);
|
|
215
|
-
});
|
|
216
|
-
return _context2.abrupt("return", 1);
|
|
217
|
-
case 55:
|
|
218
|
-
zip.append(JSON.stringify(localTimestamps), {
|
|
219
|
-
name: 'timestamps.json'
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// Upload
|
|
223
|
-
url += "?debug=".concat(debug.toString(), "&rebuild=").concat(rebuild.toString());
|
|
224
|
-
if (suffix) url += "&suffix=".concat(suffix.toString());
|
|
225
|
-
uploadPromise = new Promise(function (resolve, reject) {
|
|
226
|
-
(0, _nodeFetch["default"])(url, {
|
|
227
|
-
method: 'POST',
|
|
228
|
-
body: zip
|
|
229
|
-
}).then( /*#__PURE__*/function () {
|
|
230
|
-
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(body) {
|
|
231
|
-
var response;
|
|
232
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
233
|
-
while (1) switch (_context.prev = _context.next) {
|
|
234
|
-
case 0:
|
|
235
|
-
_context.prev = 0;
|
|
236
|
-
_context.next = 3;
|
|
237
|
-
return body.text();
|
|
238
|
-
case 3:
|
|
239
|
-
response = _context.sent;
|
|
240
|
-
return _context.abrupt("return", JSON.parse(response));
|
|
241
|
-
case 7:
|
|
242
|
-
_context.prev = 7;
|
|
243
|
-
_context.t0 = _context["catch"](0);
|
|
244
|
-
console.error(response);
|
|
245
|
-
case 10:
|
|
246
|
-
case "end":
|
|
247
|
-
return _context.stop();
|
|
248
|
-
}
|
|
249
|
-
}, _callee, null, [[0, 7]]);
|
|
250
|
-
}));
|
|
251
|
-
return function (_x9) {
|
|
252
|
-
return _ref.apply(this, arguments);
|
|
253
|
-
};
|
|
254
|
-
}()).then(function (j) {
|
|
255
|
-
return resolve(j);
|
|
256
|
-
})["catch"](function (err) {
|
|
257
|
-
reject(err);
|
|
258
|
-
});
|
|
259
|
-
})["catch"](function (error) {
|
|
260
|
-
console.error(error);
|
|
261
|
-
});
|
|
262
|
-
_context2.next = 61;
|
|
263
|
-
return zip.finalize();
|
|
264
|
-
case 61:
|
|
265
|
-
_context2.prev = 61;
|
|
266
|
-
_context2.next = 64;
|
|
267
|
-
return uploadPromise;
|
|
268
|
-
case 64:
|
|
269
|
-
log = _context2.sent;
|
|
270
|
-
_fs["default"].unlinkSync('zip');
|
|
271
|
-
if (!(log['#type'] === 'ApiError')) {
|
|
272
|
-
_context2.next = 73;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
color.error(log['message']);
|
|
276
|
-
console.error(log['innerMessage']);
|
|
277
|
-
console.log(log);
|
|
278
|
-
return _context2.abrupt("return", 1);
|
|
279
|
-
case 73:
|
|
280
|
-
console.log(log);
|
|
281
|
-
color.warn(contentValidationLog);
|
|
282
|
-
case 75:
|
|
283
|
-
_context2.next = 81;
|
|
284
|
-
break;
|
|
285
|
-
case 77:
|
|
286
|
-
_context2.prev = 77;
|
|
287
|
-
_context2.t1 = _context2["catch"](61);
|
|
288
|
-
console.error(_context2.t1);
|
|
289
|
-
return _context2.abrupt("return", 1);
|
|
290
|
-
case 81:
|
|
291
|
-
return _context2.abrupt("return", 0);
|
|
292
|
-
case 82:
|
|
293
|
-
case "end":
|
|
294
|
-
return _context2.stop();
|
|
35
|
+
let curDir = process.cwd();
|
|
36
|
+
const packDir = _path.default.join(curDir, 'package.json');
|
|
37
|
+
const packageFiles = ['src/package.ts', 'src/detectors.ts', 'src/package.js', 'src/detectors.js', 'src/package-test.ts', 'src/package-test.js', 'package.js', 'detectors.js'];
|
|
38
|
+
let config;
|
|
39
|
+
async function processPackage(debug, rebuild, host, devKey, packageName, suffix) {
|
|
40
|
+
// Get the server timestamps
|
|
41
|
+
let timestamps = {};
|
|
42
|
+
let url = `${host}/packages/dev/${devKey}/${packageName}`;
|
|
43
|
+
if (debug) {
|
|
44
|
+
try {
|
|
45
|
+
timestamps = await (await (0, _nodeFetch.default)(url + '/timestamps')).json();
|
|
46
|
+
if (timestamps['#type'] === 'ApiError') {
|
|
47
|
+
color.error(timestamps.message);
|
|
48
|
+
return 1;
|
|
295
49
|
}
|
|
296
|
-
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(error);
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const zip = (0, _archiverPromise.default)('zip', {
|
|
56
|
+
store: false
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Gather the files
|
|
60
|
+
const localTimestamps = {};
|
|
61
|
+
const files = await (0, _ignoreWalk.default)({
|
|
62
|
+
path: '.',
|
|
63
|
+
ignoreFiles: ['.npmignore', '.gitignore', '.grokignore'],
|
|
64
|
+
includeEmpty: false,
|
|
65
|
+
follow: true
|
|
66
|
+
});
|
|
67
|
+
const isWebpack = _fs.default.existsSync('webpack.config.js');
|
|
68
|
+
if (!rebuild && isWebpack) {
|
|
69
|
+
if (_fs.default.existsSync('dist/package.js')) {
|
|
70
|
+
const distFiles = await (0, _ignoreWalk.default)({
|
|
71
|
+
path: './dist',
|
|
72
|
+
ignoreFiles: [],
|
|
73
|
+
includeEmpty: false,
|
|
74
|
+
follow: true
|
|
75
|
+
});
|
|
76
|
+
distFiles.forEach(df => {
|
|
77
|
+
files.push(`dist/${df}`);
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
color.warn('File `dist/package.js` not found. Building the package on the server side...\n' + 'Next time, please build your package locally with Webpack beforehand\n' + 'or run `grok publish` with the `--rebuild` option');
|
|
81
|
+
rebuild = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let contentValidationLog = '';
|
|
85
|
+
console.log('Starting package checks...');
|
|
86
|
+
const checkStart = Date.now();
|
|
87
|
+
const jsTsFiles = files.filter(f => !f.startsWith('dist/') && (f.endsWith('.js') || f.endsWith('.ts')));
|
|
88
|
+
const packageFilePath = _path.default.join(curDir, 'package.json');
|
|
89
|
+
const json = JSON.parse(_fs.default.readFileSync(packageFilePath, {
|
|
90
|
+
encoding: 'utf-8'
|
|
297
91
|
}));
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
case 25:
|
|
354
|
-
_context3.next = 36;
|
|
355
|
-
break;
|
|
356
|
-
case 27:
|
|
357
|
-
if (!args.link) {
|
|
358
|
-
_context3.next = 34;
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
_context3.next = 30;
|
|
362
|
-
return utils.runScript("npm install", curDir);
|
|
363
|
-
case 30:
|
|
364
|
-
_context3.next = 32;
|
|
365
|
-
return utils.runScript("grok link", curDir);
|
|
366
|
-
case 32:
|
|
367
|
-
_context3.next = 34;
|
|
368
|
-
return utils.runScript("npm run build", curDir);
|
|
369
|
-
case 34:
|
|
370
|
-
_context3.next = 36;
|
|
371
|
-
return publishPackage(args);
|
|
372
|
-
case 36:
|
|
373
|
-
case "end":
|
|
374
|
-
return _context3.stop();
|
|
92
|
+
if (isWebpack) {
|
|
93
|
+
const webpackConfigPath = _path.default.join(curDir, 'webpack.config.js');
|
|
94
|
+
const content = _fs.default.readFileSync(webpackConfigPath, {
|
|
95
|
+
encoding: 'utf-8'
|
|
96
|
+
});
|
|
97
|
+
const externals = (0, _check.extractExternals)(content);
|
|
98
|
+
if (externals) {
|
|
99
|
+
const importWarnings = (0, _check.checkImportStatements)(curDir, jsTsFiles, externals);
|
|
100
|
+
contentValidationLog += importWarnings.join('\n') + (importWarnings.length ? '\n' : '');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const funcFiles = jsTsFiles.filter(f => packageFiles.includes(f));
|
|
104
|
+
const funcWarnings = (0, _check.checkFuncSignatures)(curDir, funcFiles);
|
|
105
|
+
contentValidationLog += funcWarnings.join('\n') + (funcWarnings.length ? '\n' : '');
|
|
106
|
+
const packageWarnings = (0, _check.checkPackageFile)(curDir, json);
|
|
107
|
+
contentValidationLog += packageWarnings.join('\n') + (packageWarnings.length ? '\n' : '');
|
|
108
|
+
const changelogWarnings = (0, _check.checkChangelog)(curDir, json);
|
|
109
|
+
contentValidationLog += changelogWarnings.join('\n') + (packageWarnings.length ? '\n' : '');
|
|
110
|
+
console.log(`Checks finished in ${Date.now() - checkStart} ms`);
|
|
111
|
+
const reg = new RegExp(/\${(\w*)}/g);
|
|
112
|
+
const errs = [];
|
|
113
|
+
files.forEach(file => {
|
|
114
|
+
const fullPath = file;
|
|
115
|
+
const relativePath = _path.default.relative(curDir, fullPath);
|
|
116
|
+
const canonicalRelativePath = relativePath.replace(/\\/g, '/');
|
|
117
|
+
if (canonicalRelativePath.includes('/.')) return;
|
|
118
|
+
if (canonicalRelativePath.startsWith('.')) return;
|
|
119
|
+
if (relativePath.startsWith('node_modules')) return;
|
|
120
|
+
if (relativePath.startsWith('dist') && rebuild) return;
|
|
121
|
+
if (relativePath.startsWith('src') && !rebuild && isWebpack) {
|
|
122
|
+
if (!relativePath.startsWith('src/package') && !relativePath.startsWith('src\\package')) return;
|
|
123
|
+
}
|
|
124
|
+
if (relativePath.startsWith('upload.keys.json')) return;
|
|
125
|
+
if (relativePath === 'zip') return;
|
|
126
|
+
if (!utils.checkScriptLocation(canonicalRelativePath)) {
|
|
127
|
+
contentValidationLog += `Warning: file \`${canonicalRelativePath}\`` + ` should be in directory \`${_path.default.basename(curDir)}/scripts/\`\n`;
|
|
128
|
+
}
|
|
129
|
+
const t = _fs.default.statSync(fullPath).mtime.toUTCString();
|
|
130
|
+
localTimestamps[canonicalRelativePath] = t;
|
|
131
|
+
if (debug && timestamps[canonicalRelativePath] === t) {
|
|
132
|
+
console.log(`Skipping ${canonicalRelativePath}`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (canonicalRelativePath.startsWith('connections/')) {
|
|
136
|
+
let f = _fs.default.readFileSync(fullPath, {
|
|
137
|
+
encoding: 'utf-8'
|
|
138
|
+
});
|
|
139
|
+
const matches = [...f.matchAll(reg)];
|
|
140
|
+
for (const m of matches) {
|
|
141
|
+
const envVar = process.env[m[1]];
|
|
142
|
+
if (!envVar) {
|
|
143
|
+
errs.push(`${canonicalRelativePath}: cannot find environment variable "${m[1]}"`);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
f = f.replace(m[0], envVar);
|
|
375
147
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
148
|
+
zip.append(f, {
|
|
149
|
+
name: relativePath
|
|
150
|
+
});
|
|
151
|
+
console.log(`Adding ${canonicalRelativePath}...`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
zip.append(_fs.default.createReadStream(fullPath), {
|
|
155
|
+
name: relativePath
|
|
156
|
+
});
|
|
157
|
+
console.log(`Adding ${canonicalRelativePath}...`);
|
|
158
|
+
});
|
|
159
|
+
if (errs.length) {
|
|
160
|
+
errs.forEach(e => color.error(e));
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
163
|
+
zip.append(JSON.stringify(localTimestamps), {
|
|
164
|
+
name: 'timestamps.json'
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Upload
|
|
168
|
+
url += `?debug=${debug.toString()}&rebuild=${rebuild.toString()}`;
|
|
169
|
+
if (suffix) url += `&suffix=${suffix.toString()}`;
|
|
170
|
+
const uploadPromise = new Promise((resolve, reject) => {
|
|
171
|
+
(0, _nodeFetch.default)(url, {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
body: zip
|
|
174
|
+
}).then(async body => {
|
|
175
|
+
let response;
|
|
176
|
+
try {
|
|
177
|
+
response = await body.text();
|
|
178
|
+
return JSON.parse(response);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error(response);
|
|
181
|
+
}
|
|
182
|
+
}).then(j => resolve(j)).catch(err => {
|
|
183
|
+
reject(err);
|
|
184
|
+
});
|
|
185
|
+
}).catch(error => {
|
|
186
|
+
console.error(error);
|
|
187
|
+
});
|
|
188
|
+
await zip.finalize();
|
|
189
|
+
try {
|
|
190
|
+
const log = await uploadPromise;
|
|
191
|
+
_fs.default.unlinkSync('zip');
|
|
192
|
+
if (log['#type'] === 'ApiError') {
|
|
193
|
+
color.error(log['message']);
|
|
194
|
+
console.error(log['innerMessage']);
|
|
195
|
+
console.log(log);
|
|
196
|
+
return 1;
|
|
197
|
+
} else {
|
|
198
|
+
console.log(log);
|
|
199
|
+
color.warn(contentValidationLog);
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.error(error);
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
return 0;
|
|
382
206
|
}
|
|
383
|
-
function
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
case 6:
|
|
405
|
-
if (!(args.build && args.rebuild)) {
|
|
406
|
-
_context5.next = 9;
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
color.error('Incompatible options: --build and --rebuild');
|
|
410
|
-
return _context5.abrupt("return", false);
|
|
411
|
-
case 9:
|
|
412
|
-
if (!(args.debug && args.release)) {
|
|
413
|
-
_context5.next = 12;
|
|
414
|
-
break;
|
|
415
|
-
}
|
|
416
|
-
color.error('Incompatible options: --debug and --release');
|
|
417
|
-
return _context5.abrupt("return", false);
|
|
418
|
-
case 12:
|
|
419
|
-
// Create `config.yaml` if it doesn't exist yet
|
|
420
|
-
if (!_fs["default"].existsSync(grokDir)) _fs["default"].mkdirSync(grokDir);
|
|
421
|
-
if (!_fs["default"].existsSync(confPath)) _fs["default"].writeFileSync(confPath, _jsYaml["default"].dump(confTemplate));
|
|
422
|
-
host = config["default"];
|
|
423
|
-
urls = utils.mapURL(config);
|
|
424
|
-
if (nArgs === 2) host = args['_'][1];
|
|
425
|
-
key = '';
|
|
426
|
-
url = ''; // The host can be passed either as a URL or an alias
|
|
427
|
-
_context5.prev = 19;
|
|
428
|
-
url = new URL(host).href;
|
|
429
|
-
if (url.endsWith('/')) url = url.slice(0, -1);
|
|
430
|
-
if (url in urls) key = config['servers'][urls[url]]['key'];
|
|
431
|
-
_context5.next = 31;
|
|
432
|
-
break;
|
|
433
|
-
case 25:
|
|
434
|
-
_context5.prev = 25;
|
|
435
|
-
_context5.t0 = _context5["catch"](19);
|
|
436
|
-
if (host in config.servers) {
|
|
437
|
-
_context5.next = 29;
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
return _context5.abrupt("return", color.error("Unknown server alias. Please add it to ".concat(confPath)));
|
|
441
|
-
case 29:
|
|
442
|
-
url = config['servers'][host]['url'];
|
|
443
|
-
key = config['servers'][host]['key'];
|
|
444
|
-
case 31:
|
|
445
|
-
// Update the developer key
|
|
446
|
-
if (args.key) key = args.key;
|
|
447
|
-
if (!(key === '')) {
|
|
448
|
-
_context5.next = 34;
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
return _context5.abrupt("return", color.warn('Please provide the key with `--key` option or add it by running `grok config`'));
|
|
452
|
-
case 34:
|
|
453
|
-
if (_fs["default"].existsSync(packDir)) {
|
|
454
|
-
_context5.next = 36;
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
return _context5.abrupt("return", color.error('`package.json` doesn\'t exist'));
|
|
458
|
-
case 36:
|
|
459
|
-
_package = JSON.parse(_fs["default"].readFileSync(packDir, {
|
|
460
|
-
encoding: 'utf-8'
|
|
461
|
-
}));
|
|
462
|
-
packageName = _package.name; // Upload the package
|
|
463
|
-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
464
|
-
process.on('beforeExit', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
465
|
-
var code;
|
|
466
|
-
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
467
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
468
|
-
case 0:
|
|
469
|
-
code = 0;
|
|
470
|
-
_context4.prev = 1;
|
|
471
|
-
exec('git rev-parse HEAD', function (error, stdout, stderr) {
|
|
472
|
-
if (error) {
|
|
473
|
-
console.error("Error executing command: ".concat(error.message));
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (stderr) {
|
|
477
|
-
console.error("Standard Error: ".concat(stderr));
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
if (!args.suffix && stdout) args.suffix = stdout.toString().substring(0, 8);
|
|
481
|
-
});
|
|
482
|
-
_context4.next = 5;
|
|
483
|
-
return utils.delay(100);
|
|
484
|
-
case 5:
|
|
485
|
-
_context4.next = 7;
|
|
486
|
-
return processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
|
|
487
|
-
case 7:
|
|
488
|
-
code = _context4.sent;
|
|
489
|
-
_context4.next = 14;
|
|
490
|
-
break;
|
|
491
|
-
case 10:
|
|
492
|
-
_context4.prev = 10;
|
|
493
|
-
_context4.t0 = _context4["catch"](1);
|
|
494
|
-
console.error(_context4.t0);
|
|
495
|
-
code = 1;
|
|
496
|
-
case 14:
|
|
497
|
-
console.log("Exiting with code ".concat(code));
|
|
498
|
-
process.exit(code);
|
|
499
|
-
case 16:
|
|
500
|
-
case "end":
|
|
501
|
-
return _context4.stop();
|
|
502
|
-
}
|
|
503
|
-
}, _callee4, null, [[1, 10]]);
|
|
504
|
-
})));
|
|
505
|
-
return _context5.abrupt("return", true);
|
|
506
|
-
case 41:
|
|
507
|
-
case "end":
|
|
508
|
-
return _context5.stop();
|
|
207
|
+
async function publish(args) {
|
|
208
|
+
config = _jsYaml.default.load(_fs.default.readFileSync(confPath, {
|
|
209
|
+
encoding: 'utf-8'
|
|
210
|
+
}));
|
|
211
|
+
if (args.refresh || args.all) {
|
|
212
|
+
if (_path.default.basename(curDir) !== 'packages') curDir = _path.default.dirname(curDir);
|
|
213
|
+
let host = config.default;
|
|
214
|
+
if (args['_'].length === 2) host = args['_'][1];
|
|
215
|
+
utils.setHost(host, config);
|
|
216
|
+
let baseUrl = config['servers'][host]['url'];
|
|
217
|
+
let url = process.env.HOST ?? '';
|
|
218
|
+
const cfg = (0, _testUtils.getDevKey)(url);
|
|
219
|
+
url = cfg.url;
|
|
220
|
+
const key = cfg.key;
|
|
221
|
+
const token = await (0, _testUtils.getToken)(url, key);
|
|
222
|
+
url = `${baseUrl}/packages/published/current`;
|
|
223
|
+
let packagesToLoad = ['all'];
|
|
224
|
+
if (args.refresh) packagesToLoad = (await (await (0, _nodeFetch.default)(url, {
|
|
225
|
+
method: 'GET',
|
|
226
|
+
headers: {
|
|
227
|
+
'Authorization': token // Attach cookies here
|
|
509
228
|
}
|
|
510
|
-
}
|
|
229
|
+
})).json()).map(item => item.name);
|
|
230
|
+
console.log('Loading packages:');
|
|
231
|
+
await (0, _testUtils.loadPackages)(curDir, packagesToLoad.join(' '), host, false, false, args.link, args.release);
|
|
232
|
+
} else {
|
|
233
|
+
if (args.link) {
|
|
234
|
+
await utils.runScript(`npm install`, curDir);
|
|
235
|
+
await utils.runScript(`grok link`, curDir);
|
|
236
|
+
await utils.runScript(`npm run build`, curDir);
|
|
237
|
+
}
|
|
238
|
+
await publishPackage(args);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function publishPackage(args) {
|
|
242
|
+
const nOptions = Object.keys(args).length - 1;
|
|
243
|
+
const nArgs = args['_'].length;
|
|
244
|
+
if (nArgs > 2 || nOptions > 5) return false;
|
|
245
|
+
if (!Object.keys(args).slice(1).every(option => ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option))) return false;
|
|
246
|
+
if (args.build && args.rebuild) {
|
|
247
|
+
color.error('Incompatible options: --build and --rebuild');
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
if (args.debug && args.release) {
|
|
251
|
+
color.error('Incompatible options: --debug and --release');
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Create `config.yaml` if it doesn't exist yet
|
|
256
|
+
if (!_fs.default.existsSync(grokDir)) _fs.default.mkdirSync(grokDir);
|
|
257
|
+
if (!_fs.default.existsSync(confPath)) _fs.default.writeFileSync(confPath, _jsYaml.default.dump(confTemplate));
|
|
258
|
+
let host = config.default;
|
|
259
|
+
const urls = utils.mapURL(config);
|
|
260
|
+
if (nArgs === 2) host = args['_'][1];
|
|
261
|
+
let key = '';
|
|
262
|
+
let url = '';
|
|
263
|
+
|
|
264
|
+
// The host can be passed either as a URL or an alias
|
|
265
|
+
try {
|
|
266
|
+
url = new URL(host).href;
|
|
267
|
+
if (url.endsWith('/')) url = url.slice(0, -1);
|
|
268
|
+
if (url in urls) key = config['servers'][urls[url]]['key'];
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (!(host in config.servers)) return color.error(`Unknown server alias. Please add it to ${confPath}`);
|
|
271
|
+
url = config['servers'][host]['url'];
|
|
272
|
+
key = config['servers'][host]['key'];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Update the developer key
|
|
276
|
+
if (args.key) key = args.key;
|
|
277
|
+
if (key === '') return color.warn('Please provide the key with `--key` option or add it by running `grok config`');
|
|
278
|
+
|
|
279
|
+
// Get the package name
|
|
280
|
+
if (!_fs.default.existsSync(packDir)) return color.error('`package.json` doesn\'t exist');
|
|
281
|
+
const _package = JSON.parse(_fs.default.readFileSync(packDir, {
|
|
282
|
+
encoding: 'utf-8'
|
|
511
283
|
}));
|
|
512
|
-
|
|
284
|
+
const packageName = _package.name;
|
|
285
|
+
|
|
286
|
+
// Upload the package
|
|
287
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
288
|
+
process.on('beforeExit', async () => {
|
|
289
|
+
let code = 0;
|
|
290
|
+
try {
|
|
291
|
+
exec('git rev-parse HEAD', (error, stdout, stderr) => {
|
|
292
|
+
if (error) {
|
|
293
|
+
console.error(`Error executing command: ${error.message}`);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (stderr) {
|
|
297
|
+
console.error(`Standard Error: ${stderr}`);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!args.suffix && stdout) args.suffix = stdout.toString().substring(0, 8);
|
|
301
|
+
});
|
|
302
|
+
await utils.delay(100);
|
|
303
|
+
code = await processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
console.error(error);
|
|
306
|
+
code = 1;
|
|
307
|
+
}
|
|
308
|
+
console.log(`Exiting with code ${code}`);
|
|
309
|
+
process.exit(code);
|
|
310
|
+
});
|
|
311
|
+
return true;
|
|
513
312
|
}
|