datagrok-tools 4.13.31 → 4.13.34

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/CHANGELOG.md CHANGED
@@ -1,6 +1,26 @@
1
1
  # Datagrok-tools changelog
2
2
 
3
3
 
4
+ ## 4.13.34 (2024-11-1)
5
+
6
+ ### Features
7
+
8
+ * Config bug fixes
9
+
10
+ ## 4.13.33 (2024-10-31)
11
+
12
+ ### Features
13
+
14
+ * Added Changelog to package template
15
+ * Added ability to reload page on Execution Timeout
16
+
17
+ ## 4.13.32 (2024-10-16)
18
+
19
+ ### Features
20
+
21
+ * Replaced publishAll by publuish variables
22
+ * Added global.d.ts file
23
+
4
24
  ## 4.13.31 (2024-10-15)
5
25
 
6
26
  ### Features
@@ -49,6 +49,7 @@ function createDirectoryContents(name, config, templateDir, packageDir) {
49
49
  contents = contents.replace(/#{PACKAGE_DETECTORS_NAME}/g, utils.kebabToCamelCase(name));
50
50
  contents = contents.replace(/#{PACKAGE_NAME_LOWERCASE}/g, name.toLowerCase());
51
51
  contents = contents.replace(/#{PACKAGE_NAME_LOWERCASE_WORD}/g, name.replace(/-/g, '').toLowerCase());
52
+ contents = contents.replace(/#{CURRENT_DATE}/g, new Date().toISOString().slice(0, 10));
52
53
  // eslint-disable-next-line new-cap
53
54
  contents = utils.replacers['PACKAGE_NAMESPACE'](contents, name);
54
55
  contents = contents.replace(/#{GROK_HOST_ALIAS}/g, config["default"]);
@@ -11,10 +11,9 @@ var HELP_API = "\nUsage: grok api\n\nCreate wrapper functions for package script
11
11
  var HELP_CONFIG = "\nUsage: grok config\n\nCreate or update a configuration file\n\nOptions:\n[--reset] [--server] [--alias] [-k | --key]\n\n--reset Restore the default config file template\n--server Use to add a server to the config (`grok config add --alias alias --server url --key key`)\n--alias Use in conjunction with the `server` option to set the server name\n--key Use in conjunction with the `server` option to set the developer key\n--default Use in conjunction with the `server` option to set the added server as default\n";
12
12
  var HELP_CREATE = "\nUsage: grok create [name]\n\nCreate a package:\n\ngrok create Create a package in the current working directory\ngrok create <name> Create a package in a folder with the specified name\n\nPlease note that the package name may only include letters, numbers, underscores, or hyphens\n\nOptions:\n[--eslint] [--ide] [--js | --ts] [--test]\n\n--eslint Add a configuration for eslint\n--ide Add an IDE-specific configuration for debugging (vscode)\n--js Create a JavaScript package\n--ts Create a TypeScript package (default)\n--test Add tests support (TypeScript packages only)\n";
13
13
  var HELP_PUBLISH = "\nUsage: grok publish [host]\n\nUpload a package\n\nOptions:\n[--build|--rebuild] [--debug|--release] [-k | --key] [--suffix]\n\nRunning `grok publish` is the same as running `grok publish defaultHost --build --debug`\n";
14
- var HELP_PUBLISHALL = "\nUsage: grok publishAll \n\nUpload all packages\n\nOptions:\n [--host] [--release] [--link-package] [--skip-build]\n\n --host Host alias as in the config file\n --release Publish cureent version as release version\n --skip-build Skip the package build step\n --link-package Link local packages\n";
15
- var HELP_CHECK = "\nUsage: grok check\n\nOptions:\n[-r | --recursive]\n\n--recursive Check all packages in the current directory\n\nCheck package content (function signatures, import statements of external modules, etc.)\n";
14
+ var HELP_CHECK = "\nUsage: grok check\n\nOptions:\n[-r | --recursive]\n\n--recursive Check all packages in the current directory\n--all Publish all available packages \n--refresh Publish all available already loaded packages \n\nCheck package content (function signatures, import statements of external modules, etc.)\n";
16
15
  var HELP_TEST = "\nUsage: grok test\n\nOptions:\n[--package] [--category] [--test] [--host] [--csv] [--gui] [--skip-build] [--skip-publish] [--link] [--catchUnhandled] [--report] [--record] [--verbose] [--platform] [--benchmark] [--stress-test]\n\n--package Specify a package name to run tests for\n--category Specify a category name to run tests for\n--test Specify a test name to run \n--host Host alias as in the config file\n--csv Save the test report in a CSV file\n--gui Launch graphical interface (non-headless mode)\n--catchUnhandled Catch unhandled exceptions during test execution (default=true)\n--report Report failed tests to audit, notifies package author (default=false)\n--skip-build Skip the package build step\n--skip-publish Skip the package publication step\n--link \t Link the package to local utils\n--record Records the test execution process in mp4 format\n--verbose Prints detailed information about passed and skipped tests in the console\n--platform Runs only platform tests (applicable for ApiTests package only)\n--core Runs package & core tests (applicable for DevTools package only)\n--benchmark \t Runs tests in benchmark mode\n--stress-test Runs shuffled stress-test only\n \nRun package tests\n\nSee instructions:\nhttps://datagrok.ai/help/develop/how-to/test-packages#local-testing\n";
17
- var HELP_TESTALL = "\nUsage: grok testAll\n\nOptions:\n[--packages] [--host] [--csv] [--gui] [--skip-build] [--skip-publish] [--link-package] [--catchUnhandled] [--report] [--record] [--verbose] [--benchmark] [--stress-test] [--order] [--tags] [--testRepeat] [--workersCount]\n\n--packages Specify a packages names to run tests for\n--host Host alias as in the config file\n--csv Save the test report in a CSV file\n--gui Launch graphical interface (non-headless mode)\n--catchUnhandled Catch unhandled exceptions during test execution (default=true)\n--report Report failed tests to audit, notifies packages author (default=false)\n--skip-build Skip the packages build step\n--skip-publish Skip the packages publication step\n--link-package \t Link the packages to local utils\n--record Records the test execution process in mp4 format\n--verbose Prints detailed information about passed and skipped tests in the console\n--core Runs packages & core tests (applicable for DevTools packages only)\n--benchmark \t Runs tests in benchmark mode\n--stress-test Runs shuffled stress-test only\n--order Specify order for tests invocation\n--tags Filter tests by tag name for run\n--testRepeat Set amount of tests repeats\n--workersCount Set amount of workers for tests run\n\nRun tests of all or specified packages \n\nSee instructions:\nhttps://datagrok.ai/help/develop/how-to/test-packages#local-testing\n";
16
+ var HELP_TESTALL = "\nUsage: grok testall\n\nOptions:\n[--packages] [--host] [--csv] [--gui] [--skip-build] [--skip-publish] [--link-package] [--catchUnhandled] [--report] [--record] [--verbose] [--benchmark] [--stress-test] [--order] [--tags] [--testRepeat] [--workersCount]\n\n--packages Specify a packages names to run tests for\n--host Host alias as in the config file\n--csv Save the test report in a CSV file\n--gui Launch graphical interface (non-headless mode)\n--catchUnhandled Catch unhandled exceptions during test execution (default=true)\n--report Report failed tests to audit, notifies packages author (default=false)\n--skip-build Skip the packages build step\n--skip-publish Skip the packages publication step\n--link-package \t Link the packages to local utils\n--record Records the test execution process in mp4 format\n--verbose Prints detailed information about passed and skipped tests in the console\n--core Runs packages & core tests (applicable for DevTools packages only)\n--benchmark \t Runs tests in benchmark mode\n--stress-test Runs shuffled stress-test only\n--order Specify order for tests invocation\n--tags Filter tests by tag name for run\n--testRepeat Set amount of tests repeats\n--workersCount Set amount of workers for tests run\n\nRun tests of all or specified packages \n\nSee instructions:\nhttps://datagrok.ai/help/develop/how-to/test-packages#local-testing\n";
18
17
  var HELP_LINK = "\nUsage: grok link\n\nLink `datagrok-api` and libraries for local development\n";
19
18
 
20
19
  // const HELP_MIGRATE = `
@@ -33,8 +32,7 @@ var help = exports.help = {
33
32
  init: HELP_INIT,
34
33
  link: HELP_LINK,
35
34
  publish: HELP_PUBLISH,
36
- publishAll: HELP_PUBLISHALL,
37
35
  test: HELP_TEST,
38
- testAll: HELP_TESTALL,
36
+ testall: HELP_TESTALL,
39
37
  help: HELP
40
38
  };
@@ -19,6 +19,7 @@ var _ignoreWalk = _interopRequireDefault(require("ignore-walk"));
19
19
  var _jsYaml = _interopRequireDefault(require("js-yaml"));
20
20
  var _check = require("./check");
21
21
  var utils = _interopRequireWildcard(require("../utils/utils"));
22
+ var _testUtils = require("../utils/test-utils");
22
23
  var color = _interopRequireWildcard(require("../utils/color-utils"));
23
24
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
25
  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; }
@@ -37,85 +38,87 @@ var confTemplate = _jsYaml["default"].load(_fs["default"].readFileSync(confTempl
37
38
  var curDir = process.cwd();
38
39
  var packDir = _path["default"].join(curDir, 'package.json');
39
40
  var 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'];
41
+ var config;
40
42
  function processPackage(_x, _x2, _x3, _x4, _x5, _x6) {
41
43
  return _processPackage.apply(this, arguments);
42
44
  }
43
45
  function _processPackage() {
44
- _processPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(debug, rebuild, host, devKey, packageName, suffix) {
46
+ _processPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(debug, rebuild, host, devKey, packageName, suffix) {
45
47
  var timestamps, url, zip, localTimestamps, files, isWebpack, distFiles, contentValidationLog, checkStart, jsTsFiles, packageFilePath, json, webpackConfigPath, content, externals, importWarnings, funcFiles, funcWarnings, packageWarnings, changelogWarnings, reg, errs, uploadPromise, log;
46
- return _regenerator["default"].wrap(function _callee3$(_context3) {
47
- while (1) switch (_context3.prev = _context3.next) {
48
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
49
+ while (1) switch (_context2.prev = _context2.next) {
48
50
  case 0:
49
51
  // Get the server timestamps
50
52
  timestamps = {};
51
53
  url = "".concat(host, "/packages/dev/").concat(devKey, "/").concat(packageName);
52
54
  if (!debug) {
53
- _context3.next = 18;
55
+ _context2.next = 19;
54
56
  break;
55
57
  }
56
- _context3.prev = 3;
57
- _context3.next = 6;
58
+ _context2.prev = 3;
59
+ console.log(url);
60
+ _context2.next = 7;
58
61
  return (0, _nodeFetch["default"])(url + '/timestamps');
59
- case 6:
60
- _context3.next = 8;
61
- return _context3.sent.json();
62
- case 8:
63
- timestamps = _context3.sent;
62
+ case 7:
63
+ _context2.next = 9;
64
+ return _context2.sent.json();
65
+ case 9:
66
+ timestamps = _context2.sent;
64
67
  if (!(timestamps['#type'] === 'ApiError')) {
65
- _context3.next = 12;
68
+ _context2.next = 13;
66
69
  break;
67
70
  }
68
71
  color.error(timestamps.message);
69
- return _context3.abrupt("return", 1);
70
- case 12:
71
- _context3.next = 18;
72
+ return _context2.abrupt("return", 1);
73
+ case 13:
74
+ _context2.next = 19;
72
75
  break;
73
- case 14:
74
- _context3.prev = 14;
75
- _context3.t0 = _context3["catch"](3);
76
- console.error(_context3.t0);
77
- return _context3.abrupt("return", 1);
78
- case 18:
76
+ case 15:
77
+ _context2.prev = 15;
78
+ _context2.t0 = _context2["catch"](3);
79
+ console.error(_context2.t0);
80
+ return _context2.abrupt("return", 1);
81
+ case 19:
79
82
  zip = (0, _archiverPromise["default"])('zip', {
80
83
  store: false
81
84
  }); // Gather the files
82
85
  localTimestamps = {};
83
- _context3.next = 22;
86
+ _context2.next = 23;
84
87
  return (0, _ignoreWalk["default"])({
85
88
  path: '.',
86
89
  ignoreFiles: ['.npmignore', '.gitignore', '.grokignore'],
87
90
  includeEmpty: false,
88
91
  follow: true
89
92
  });
90
- case 22:
91
- files = _context3.sent;
93
+ case 23:
94
+ files = _context2.sent;
92
95
  isWebpack = _fs["default"].existsSync('webpack.config.js');
93
96
  if (!(!rebuild && isWebpack)) {
94
- _context3.next = 34;
97
+ _context2.next = 35;
95
98
  break;
96
99
  }
97
100
  if (!_fs["default"].existsSync('dist/package.js')) {
98
- _context3.next = 32;
101
+ _context2.next = 33;
99
102
  break;
100
103
  }
101
- _context3.next = 28;
104
+ _context2.next = 29;
102
105
  return (0, _ignoreWalk["default"])({
103
106
  path: './dist',
104
107
  ignoreFiles: [],
105
108
  includeEmpty: false,
106
109
  follow: true
107
110
  });
108
- case 28:
109
- distFiles = _context3.sent;
111
+ case 29:
112
+ distFiles = _context2.sent;
110
113
  distFiles.forEach(function (df) {
111
114
  files.push("dist/".concat(df));
112
115
  });
113
- _context3.next = 34;
116
+ _context2.next = 35;
114
117
  break;
115
- case 32:
118
+ case 33:
116
119
  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');
117
120
  rebuild = true;
118
- case 34:
121
+ case 35:
119
122
  contentValidationLog = '';
120
123
  console.log('Starting package checks...');
121
124
  checkStart = Date.now();
@@ -205,14 +208,14 @@ function _processPackage() {
205
208
  console.log("Adding ".concat(canonicalRelativePath, "..."));
206
209
  });
207
210
  if (!errs.length) {
208
- _context3.next = 55;
211
+ _context2.next = 56;
209
212
  break;
210
213
  }
211
214
  errs.forEach(function (e) {
212
215
  return color.error(e);
213
216
  });
214
- return _context3.abrupt("return", 1);
215
- case 55:
217
+ return _context2.abrupt("return", 1);
218
+ case 56:
216
219
  zip.append(JSON.stringify(localTimestamps), {
217
220
  name: 'timestamps.json'
218
221
  });
@@ -225,29 +228,29 @@ function _processPackage() {
225
228
  method: 'POST',
226
229
  body: zip
227
230
  }).then( /*#__PURE__*/function () {
228
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(body) {
231
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(body) {
229
232
  var response;
230
- return _regenerator["default"].wrap(function _callee2$(_context2) {
231
- while (1) switch (_context2.prev = _context2.next) {
233
+ return _regenerator["default"].wrap(function _callee$(_context) {
234
+ while (1) switch (_context.prev = _context.next) {
232
235
  case 0:
233
- _context2.prev = 0;
234
- _context2.next = 3;
236
+ _context.prev = 0;
237
+ _context.next = 3;
235
238
  return body.text();
236
239
  case 3:
237
- response = _context2.sent;
238
- return _context2.abrupt("return", JSON.parse(response));
240
+ response = _context.sent;
241
+ return _context.abrupt("return", JSON.parse(response));
239
242
  case 7:
240
- _context2.prev = 7;
241
- _context2.t0 = _context2["catch"](0);
243
+ _context.prev = 7;
244
+ _context.t0 = _context["catch"](0);
242
245
  console.error(response);
243
246
  case 10:
244
247
  case "end":
245
- return _context2.stop();
248
+ return _context.stop();
246
249
  }
247
- }, _callee2, null, [[0, 7]]);
250
+ }, _callee, null, [[0, 7]]);
248
251
  }));
249
- return function (_x7) {
250
- return _ref2.apply(this, arguments);
252
+ return function (_x9) {
253
+ return _ref.apply(this, arguments);
251
254
  };
252
255
  }()).then(function (j) {
253
256
  return resolve(j);
@@ -257,136 +260,230 @@ function _processPackage() {
257
260
  })["catch"](function (error) {
258
261
  console.error(error);
259
262
  });
260
- _context3.next = 61;
263
+ _context2.next = 62;
261
264
  return zip.finalize();
262
- case 61:
263
- _context3.prev = 61;
264
- _context3.next = 64;
265
+ case 62:
266
+ _context2.prev = 62;
267
+ _context2.next = 65;
265
268
  return uploadPromise;
266
- case 64:
267
- log = _context3.sent;
269
+ case 65:
270
+ log = _context2.sent;
268
271
  _fs["default"].unlinkSync('zip');
269
272
  if (!(log['#type'] === 'ApiError')) {
270
- _context3.next = 73;
273
+ _context2.next = 74;
271
274
  break;
272
275
  }
273
276
  color.error(log['message']);
274
277
  console.error(log['innerMessage']);
275
278
  console.log(log);
276
- return _context3.abrupt("return", 1);
277
- case 73:
279
+ return _context2.abrupt("return", 1);
280
+ case 74:
278
281
  console.log(log);
279
282
  color.warn(contentValidationLog);
280
- case 75:
281
- _context3.next = 81;
283
+ case 76:
284
+ _context2.next = 82;
282
285
  break;
283
- case 77:
284
- _context3.prev = 77;
285
- _context3.t1 = _context3["catch"](61);
286
- console.error(_context3.t1);
287
- return _context3.abrupt("return", 1);
288
- case 81:
289
- return _context3.abrupt("return", 0);
286
+ case 78:
287
+ _context2.prev = 78;
288
+ _context2.t1 = _context2["catch"](62);
289
+ console.error(_context2.t1);
290
+ return _context2.abrupt("return", 1);
290
291
  case 82:
292
+ return _context2.abrupt("return", 0);
293
+ case 83:
291
294
  case "end":
292
- return _context3.stop();
295
+ return _context2.stop();
293
296
  }
294
- }, _callee3, null, [[3, 14], [61, 77]]);
297
+ }, _callee2, null, [[3, 15], [62, 78]]);
295
298
  }));
296
299
  return _processPackage.apply(this, arguments);
297
300
  }
298
- function publish(args) {
299
- var nOptions = Object.keys(args).length - 1;
300
- var nArgs = args['_'].length;
301
- if (nArgs > 2 || nOptions > 5) return false;
302
- if (!Object.keys(args).slice(1).every(function (option) {
303
- return ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option);
304
- })) return false;
305
- if (args.build && args.rebuild) {
306
- color.error('Incompatible options: --build and --rebuild');
307
- return false;
308
- }
309
- if (args.debug && args.release) {
310
- color.error('Incompatible options: --debug and --release');
311
- return false;
312
- }
313
-
314
- // Create `config.yaml` if it doesn't exist yet
315
- if (!_fs["default"].existsSync(grokDir)) _fs["default"].mkdirSync(grokDir);
316
- if (!_fs["default"].existsSync(confPath)) _fs["default"].writeFileSync(confPath, _jsYaml["default"].dump(confTemplate));
317
- var config = _jsYaml["default"].load(_fs["default"].readFileSync(confPath, {
318
- encoding: 'utf-8'
319
- }));
320
- var host = config["default"];
321
- var urls = utils.mapURL(config);
322
- if (nArgs === 2) host = args['_'][1];
323
- var key = '';
324
- var url = '';
325
-
326
- // The host can be passed either as a URL or an alias
327
- try {
328
- url = new URL(host).href;
329
- if (url.endsWith('/')) url = url.slice(0, -1);
330
- if (url in urls) key = config['servers'][urls[url]]['key'];
331
- } catch (error) {
332
- if (!(host in config.servers)) return color.error("Unknown server alias. Please add it to ".concat(confPath));
333
- url = config['servers'][host]['url'];
334
- key = config['servers'][host]['key'];
335
- }
336
-
337
- // Update the developer key
338
- if (args.key) key = args.key;
339
- if (key === '') return color.warn('Please provide the key with `--key` option or add it by running `grok config`');
340
-
341
- // Get the package name
342
- if (!_fs["default"].existsSync(packDir)) return color.error('`package.json` doesn\'t exist');
343
- var _package = JSON.parse(_fs["default"].readFileSync(packDir, {
344
- encoding: 'utf-8'
345
- }));
346
- var packageName = _package.name;
347
-
348
- // Upload the package
349
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
350
- process.on('beforeExit', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
351
- var code;
352
- return _regenerator["default"].wrap(function _callee$(_context) {
353
- while (1) switch (_context.prev = _context.next) {
301
+ function publish(_x7) {
302
+ return _publish.apply(this, arguments);
303
+ }
304
+ function _publish() {
305
+ _publish = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(args) {
306
+ var host, baseUrl, url, packagesToLoad;
307
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
308
+ while (1) switch (_context3.prev = _context3.next) {
354
309
  case 0:
355
- code = 0;
356
- _context.prev = 1;
357
- exec('git rev-parse HEAD', function (error, stdout, stderr) {
358
- if (error) {
359
- console.error("Error executing command: ".concat(error.message));
360
- return;
361
- }
362
- if (stderr) {
363
- console.error("Standard Error: ".concat(stderr));
364
- return;
365
- }
366
- if (!args.suffix && stdout) args.suffix = stdout.toString().substring(0, 8);
367
- });
368
- _context.next = 5;
369
- return utils.delay(100);
370
- case 5:
371
- _context.next = 7;
372
- return processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
373
- case 7:
374
- code = _context.sent;
375
- _context.next = 14;
376
- break;
377
- case 10:
378
- _context.prev = 10;
379
- _context.t0 = _context["catch"](1);
380
- console.error(_context.t0);
381
- code = 1;
310
+ config = _jsYaml["default"].load(_fs["default"].readFileSync(confPath, {
311
+ encoding: 'utf-8'
312
+ }));
313
+ if (!(args.refresh || args.all)) {
314
+ _context3.next = 23;
315
+ break;
316
+ }
317
+ if (_path["default"].basename(curDir) !== 'packages') curDir = _path["default"].dirname(curDir);
318
+ host = config["default"];
319
+ if (args['_'].length === 2) host = args['_'][1];
320
+ utils.setHost(host, config);
321
+ baseUrl = config['servers'][host]['url'];
322
+ url = "".concat(baseUrl, "/info/packages");
323
+ packagesToLoad = ['all'];
324
+ console.log(url);
325
+ if (!args.refresh) {
326
+ _context3.next = 18;
327
+ break;
328
+ }
329
+ _context3.t0 = Object;
330
+ _context3.next = 14;
331
+ return (0, _nodeFetch["default"])(url);
382
332
  case 14:
383
- console.log("Exiting with code ".concat(code));
384
- process.exit(code);
333
+ _context3.next = 16;
334
+ return _context3.sent.json();
385
335
  case 16:
336
+ _context3.t1 = _context3.sent;
337
+ packagesToLoad = _context3.t0.keys.call(_context3.t0, _context3.t1);
338
+ case 18:
339
+ console.log('Loading packages:');
340
+ _context3.next = 21;
341
+ return (0, _testUtils.loadPackages)(curDir, packagesToLoad.join(' '), host, false, false, false, args.release);
342
+ case 21:
343
+ _context3.next = 25;
344
+ break;
345
+ case 23:
346
+ _context3.next = 25;
347
+ return publishPackage(args);
348
+ case 25:
386
349
  case "end":
387
- return _context.stop();
350
+ return _context3.stop();
388
351
  }
389
- }, _callee, null, [[1, 10]]);
390
- })));
391
- return true;
352
+ }, _callee3);
353
+ }));
354
+ return _publish.apply(this, arguments);
355
+ }
356
+ function publishPackage(_x8) {
357
+ return _publishPackage.apply(this, arguments);
358
+ }
359
+ function _publishPackage() {
360
+ _publishPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(args) {
361
+ var nOptions, nArgs, host, urls, key, url, _package, packageName;
362
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
363
+ while (1) switch (_context5.prev = _context5.next) {
364
+ case 0:
365
+ nOptions = Object.keys(args).length - 1;
366
+ nArgs = args['_'].length;
367
+ if (!(nArgs > 2 || nOptions > 5)) {
368
+ _context5.next = 4;
369
+ break;
370
+ }
371
+ return _context5.abrupt("return", false);
372
+ case 4:
373
+ if (Object.keys(args).slice(1).every(function (option) {
374
+ return ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option);
375
+ })) {
376
+ _context5.next = 6;
377
+ break;
378
+ }
379
+ return _context5.abrupt("return", false);
380
+ case 6:
381
+ if (!(args.build && args.rebuild)) {
382
+ _context5.next = 9;
383
+ break;
384
+ }
385
+ color.error('Incompatible options: --build and --rebuild');
386
+ return _context5.abrupt("return", false);
387
+ case 9:
388
+ if (!(args.debug && args.release)) {
389
+ _context5.next = 12;
390
+ break;
391
+ }
392
+ color.error('Incompatible options: --debug and --release');
393
+ return _context5.abrupt("return", false);
394
+ case 12:
395
+ // Create `config.yaml` if it doesn't exist yet
396
+ if (!_fs["default"].existsSync(grokDir)) _fs["default"].mkdirSync(grokDir);
397
+ if (!_fs["default"].existsSync(confPath)) _fs["default"].writeFileSync(confPath, _jsYaml["default"].dump(confTemplate));
398
+ host = config["default"];
399
+ urls = utils.mapURL(config);
400
+ if (nArgs === 2) host = args['_'][1];
401
+ key = '';
402
+ url = ''; // The host can be passed either as a URL or an alias
403
+ _context5.prev = 19;
404
+ url = new URL(host).href;
405
+ if (url.endsWith('/')) url = url.slice(0, -1);
406
+ if (url in urls) key = config['servers'][urls[url]]['key'];
407
+ _context5.next = 31;
408
+ break;
409
+ case 25:
410
+ _context5.prev = 25;
411
+ _context5.t0 = _context5["catch"](19);
412
+ if (host in config.servers) {
413
+ _context5.next = 29;
414
+ break;
415
+ }
416
+ return _context5.abrupt("return", color.error("Unknown server alias. Please add it to ".concat(confPath)));
417
+ case 29:
418
+ url = config['servers'][host]['url'];
419
+ key = config['servers'][host]['key'];
420
+ case 31:
421
+ // Update the developer key
422
+ if (args.key) key = args.key;
423
+ if (!(key === '')) {
424
+ _context5.next = 34;
425
+ break;
426
+ }
427
+ return _context5.abrupt("return", color.warn('Please provide the key with `--key` option or add it by running `grok config`'));
428
+ case 34:
429
+ if (_fs["default"].existsSync(packDir)) {
430
+ _context5.next = 36;
431
+ break;
432
+ }
433
+ return _context5.abrupt("return", color.error('`package.json` doesn\'t exist'));
434
+ case 36:
435
+ _package = JSON.parse(_fs["default"].readFileSync(packDir, {
436
+ encoding: 'utf-8'
437
+ }));
438
+ packageName = _package.name; // Upload the package
439
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
440
+ process.on('beforeExit', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
441
+ var code;
442
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
443
+ while (1) switch (_context4.prev = _context4.next) {
444
+ case 0:
445
+ code = 0;
446
+ _context4.prev = 1;
447
+ exec('git rev-parse HEAD', function (error, stdout, stderr) {
448
+ if (error) {
449
+ console.error("Error executing command: ".concat(error.message));
450
+ return;
451
+ }
452
+ if (stderr) {
453
+ console.error("Standard Error: ".concat(stderr));
454
+ return;
455
+ }
456
+ if (!args.suffix && stdout) args.suffix = stdout.toString().substring(0, 8);
457
+ });
458
+ _context4.next = 5;
459
+ return utils.delay(100);
460
+ case 5:
461
+ _context4.next = 7;
462
+ return processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
463
+ case 7:
464
+ code = _context4.sent;
465
+ _context4.next = 14;
466
+ break;
467
+ case 10:
468
+ _context4.prev = 10;
469
+ _context4.t0 = _context4["catch"](1);
470
+ console.error(_context4.t0);
471
+ code = 1;
472
+ case 14:
473
+ console.log("Exiting with code ".concat(code));
474
+ process.exit(code);
475
+ case 16:
476
+ case "end":
477
+ return _context4.stop();
478
+ }
479
+ }, _callee4, null, [[1, 10]]);
480
+ })));
481
+ return _context5.abrupt("return", true);
482
+ case 41:
483
+ case "end":
484
+ return _context5.stop();
485
+ }
486
+ }, _callee5, null, [[19, 25]]);
487
+ }));
488
+ return _publishPackage.apply(this, arguments);
392
489
  }