datagrok-tools 4.13.31 → 4.13.33

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,20 @@
1
1
  # Datagrok-tools changelog
2
2
 
3
3
 
4
+ ## 4.13.33 (2024-10-31)
5
+
6
+ ### Features
7
+
8
+ * Added Changelog to package template
9
+ * Added ability to reload page on Execution Timeout
10
+
11
+ ## 4.13.32 (2024-10-16)
12
+
13
+ ### Features
14
+
15
+ * Replaced publishAll by publuish variables
16
+ * Added global.d.ts file
17
+
4
18
  ## 4.13.31 (2024-10-15)
5
19
 
6
20
  ### 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,89 @@ 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 = _jsYaml["default"].load(_fs["default"].readFileSync(confPath, {
42
+ encoding: 'utf-8'
43
+ }));
40
44
  function processPackage(_x, _x2, _x3, _x4, _x5, _x6) {
41
45
  return _processPackage.apply(this, arguments);
42
46
  }
43
47
  function _processPackage() {
44
- _processPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(debug, rebuild, host, devKey, packageName, suffix) {
48
+ _processPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(debug, rebuild, host, devKey, packageName, suffix) {
45
49
  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) {
50
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
51
+ while (1) switch (_context2.prev = _context2.next) {
48
52
  case 0:
49
53
  // Get the server timestamps
50
54
  timestamps = {};
51
55
  url = "".concat(host, "/packages/dev/").concat(devKey, "/").concat(packageName);
52
56
  if (!debug) {
53
- _context3.next = 18;
57
+ _context2.next = 19;
54
58
  break;
55
59
  }
56
- _context3.prev = 3;
57
- _context3.next = 6;
60
+ _context2.prev = 3;
61
+ console.log(url);
62
+ _context2.next = 7;
58
63
  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;
64
+ case 7:
65
+ _context2.next = 9;
66
+ return _context2.sent.json();
67
+ case 9:
68
+ timestamps = _context2.sent;
64
69
  if (!(timestamps['#type'] === 'ApiError')) {
65
- _context3.next = 12;
70
+ _context2.next = 13;
66
71
  break;
67
72
  }
68
73
  color.error(timestamps.message);
69
- return _context3.abrupt("return", 1);
70
- case 12:
71
- _context3.next = 18;
74
+ return _context2.abrupt("return", 1);
75
+ case 13:
76
+ _context2.next = 19;
72
77
  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:
78
+ case 15:
79
+ _context2.prev = 15;
80
+ _context2.t0 = _context2["catch"](3);
81
+ console.error(_context2.t0);
82
+ return _context2.abrupt("return", 1);
83
+ case 19:
79
84
  zip = (0, _archiverPromise["default"])('zip', {
80
85
  store: false
81
86
  }); // Gather the files
82
87
  localTimestamps = {};
83
- _context3.next = 22;
88
+ _context2.next = 23;
84
89
  return (0, _ignoreWalk["default"])({
85
90
  path: '.',
86
91
  ignoreFiles: ['.npmignore', '.gitignore', '.grokignore'],
87
92
  includeEmpty: false,
88
93
  follow: true
89
94
  });
90
- case 22:
91
- files = _context3.sent;
95
+ case 23:
96
+ files = _context2.sent;
92
97
  isWebpack = _fs["default"].existsSync('webpack.config.js');
93
98
  if (!(!rebuild && isWebpack)) {
94
- _context3.next = 34;
99
+ _context2.next = 35;
95
100
  break;
96
101
  }
97
102
  if (!_fs["default"].existsSync('dist/package.js')) {
98
- _context3.next = 32;
103
+ _context2.next = 33;
99
104
  break;
100
105
  }
101
- _context3.next = 28;
106
+ _context2.next = 29;
102
107
  return (0, _ignoreWalk["default"])({
103
108
  path: './dist',
104
109
  ignoreFiles: [],
105
110
  includeEmpty: false,
106
111
  follow: true
107
112
  });
108
- case 28:
109
- distFiles = _context3.sent;
113
+ case 29:
114
+ distFiles = _context2.sent;
110
115
  distFiles.forEach(function (df) {
111
116
  files.push("dist/".concat(df));
112
117
  });
113
- _context3.next = 34;
118
+ _context2.next = 35;
114
119
  break;
115
- case 32:
120
+ case 33:
116
121
  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
122
  rebuild = true;
118
- case 34:
123
+ case 35:
119
124
  contentValidationLog = '';
120
125
  console.log('Starting package checks...');
121
126
  checkStart = Date.now();
@@ -205,14 +210,14 @@ function _processPackage() {
205
210
  console.log("Adding ".concat(canonicalRelativePath, "..."));
206
211
  });
207
212
  if (!errs.length) {
208
- _context3.next = 55;
213
+ _context2.next = 56;
209
214
  break;
210
215
  }
211
216
  errs.forEach(function (e) {
212
217
  return color.error(e);
213
218
  });
214
- return _context3.abrupt("return", 1);
215
- case 55:
219
+ return _context2.abrupt("return", 1);
220
+ case 56:
216
221
  zip.append(JSON.stringify(localTimestamps), {
217
222
  name: 'timestamps.json'
218
223
  });
@@ -225,29 +230,29 @@ function _processPackage() {
225
230
  method: 'POST',
226
231
  body: zip
227
232
  }).then( /*#__PURE__*/function () {
228
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(body) {
233
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(body) {
229
234
  var response;
230
- return _regenerator["default"].wrap(function _callee2$(_context2) {
231
- while (1) switch (_context2.prev = _context2.next) {
235
+ return _regenerator["default"].wrap(function _callee$(_context) {
236
+ while (1) switch (_context.prev = _context.next) {
232
237
  case 0:
233
- _context2.prev = 0;
234
- _context2.next = 3;
238
+ _context.prev = 0;
239
+ _context.next = 3;
235
240
  return body.text();
236
241
  case 3:
237
- response = _context2.sent;
238
- return _context2.abrupt("return", JSON.parse(response));
242
+ response = _context.sent;
243
+ return _context.abrupt("return", JSON.parse(response));
239
244
  case 7:
240
- _context2.prev = 7;
241
- _context2.t0 = _context2["catch"](0);
245
+ _context.prev = 7;
246
+ _context.t0 = _context["catch"](0);
242
247
  console.error(response);
243
248
  case 10:
244
249
  case "end":
245
- return _context2.stop();
250
+ return _context.stop();
246
251
  }
247
- }, _callee2, null, [[0, 7]]);
252
+ }, _callee, null, [[0, 7]]);
248
253
  }));
249
- return function (_x7) {
250
- return _ref2.apply(this, arguments);
254
+ return function (_x9) {
255
+ return _ref.apply(this, arguments);
251
256
  };
252
257
  }()).then(function (j) {
253
258
  return resolve(j);
@@ -257,136 +262,227 @@ function _processPackage() {
257
262
  })["catch"](function (error) {
258
263
  console.error(error);
259
264
  });
260
- _context3.next = 61;
265
+ _context2.next = 62;
261
266
  return zip.finalize();
262
- case 61:
263
- _context3.prev = 61;
264
- _context3.next = 64;
267
+ case 62:
268
+ _context2.prev = 62;
269
+ _context2.next = 65;
265
270
  return uploadPromise;
266
- case 64:
267
- log = _context3.sent;
271
+ case 65:
272
+ log = _context2.sent;
268
273
  _fs["default"].unlinkSync('zip');
269
274
  if (!(log['#type'] === 'ApiError')) {
270
- _context3.next = 73;
275
+ _context2.next = 74;
271
276
  break;
272
277
  }
273
278
  color.error(log['message']);
274
279
  console.error(log['innerMessage']);
275
280
  console.log(log);
276
- return _context3.abrupt("return", 1);
277
- case 73:
281
+ return _context2.abrupt("return", 1);
282
+ case 74:
278
283
  console.log(log);
279
284
  color.warn(contentValidationLog);
280
- case 75:
281
- _context3.next = 81;
285
+ case 76:
286
+ _context2.next = 82;
282
287
  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);
288
+ case 78:
289
+ _context2.prev = 78;
290
+ _context2.t1 = _context2["catch"](62);
291
+ console.error(_context2.t1);
292
+ return _context2.abrupt("return", 1);
290
293
  case 82:
294
+ return _context2.abrupt("return", 0);
295
+ case 83:
291
296
  case "end":
292
- return _context3.stop();
297
+ return _context2.stop();
293
298
  }
294
- }, _callee3, null, [[3, 14], [61, 77]]);
299
+ }, _callee2, null, [[3, 15], [62, 78]]);
295
300
  }));
296
301
  return _processPackage.apply(this, arguments);
297
302
  }
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'
303
+ function publish(_x7) {
304
+ return _publish.apply(this, arguments);
305
+ }
306
+ function _publish() {
307
+ _publish = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(args) {
308
+ var host, baseUrl, url, packagesToLoad;
309
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
310
+ while (1) switch (_context3.prev = _context3.next) {
311
+ case 0:
312
+ if (!(args.refresh || args.all)) {
313
+ _context3.next = 22;
314
+ break;
315
+ }
316
+ if (_path["default"].basename(curDir) !== 'packages') curDir = _path["default"].dirname(curDir);
317
+ host = config["default"];
318
+ if (args['_'].length === 2) host = args['_'][1];
319
+ utils.setHost(host, config);
320
+ baseUrl = config['servers'][host]['url'];
321
+ url = "".concat(baseUrl, "/info/packages");
322
+ packagesToLoad = ['all'];
323
+ console.log(url);
324
+ if (!args.refresh) {
325
+ _context3.next = 17;
326
+ break;
327
+ }
328
+ _context3.t0 = Object;
329
+ _context3.next = 13;
330
+ return (0, _nodeFetch["default"])(url);
331
+ case 13:
332
+ _context3.next = 15;
333
+ return _context3.sent.json();
334
+ case 15:
335
+ _context3.t1 = _context3.sent;
336
+ packagesToLoad = _context3.t0.keys.call(_context3.t0, _context3.t1);
337
+ case 17:
338
+ console.log('Loading packages:');
339
+ _context3.next = 20;
340
+ return (0, _testUtils.loadPackages)(curDir, packagesToLoad.join(' '), host, false, false, false, args.release);
341
+ case 20:
342
+ _context3.next = 24;
343
+ break;
344
+ case 22:
345
+ _context3.next = 24;
346
+ return publishPackage(args);
347
+ case 24:
348
+ case "end":
349
+ return _context3.stop();
350
+ }
351
+ }, _callee3);
345
352
  }));
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) {
353
+ return _publish.apply(this, arguments);
354
+ }
355
+ function publishPackage(_x8) {
356
+ return _publishPackage.apply(this, arguments);
357
+ }
358
+ function _publishPackage() {
359
+ _publishPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(args) {
360
+ var nOptions, nArgs, host, urls, key, url, _package, packageName;
361
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
362
+ while (1) switch (_context5.prev = _context5.next) {
354
363
  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;
364
+ nOptions = Object.keys(args).length - 1;
365
+ nArgs = args['_'].length;
366
+ if (!(nArgs > 2 || nOptions > 5)) {
367
+ _context5.next = 4;
368
+ break;
369
+ }
370
+ return _context5.abrupt("return", false);
371
+ case 4:
372
+ if (Object.keys(args).slice(1).every(function (option) {
373
+ return ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option);
374
+ })) {
375
+ _context5.next = 6;
376
+ break;
377
+ }
378
+ return _context5.abrupt("return", false);
379
+ case 6:
380
+ if (!(args.build && args.rebuild)) {
381
+ _context5.next = 9;
382
+ break;
383
+ }
384
+ color.error('Incompatible options: --build and --rebuild');
385
+ return _context5.abrupt("return", false);
386
+ case 9:
387
+ if (!(args.debug && args.release)) {
388
+ _context5.next = 12;
389
+ break;
390
+ }
391
+ color.error('Incompatible options: --debug and --release');
392
+ return _context5.abrupt("return", false);
393
+ case 12:
394
+ // Create `config.yaml` if it doesn't exist yet
395
+ if (!_fs["default"].existsSync(grokDir)) _fs["default"].mkdirSync(grokDir);
396
+ if (!_fs["default"].existsSync(confPath)) _fs["default"].writeFileSync(confPath, _jsYaml["default"].dump(confTemplate));
397
+ host = config["default"];
398
+ urls = utils.mapURL(config);
399
+ if (nArgs === 2) host = args['_'][1];
400
+ key = '';
401
+ url = ''; // The host can be passed either as a URL or an alias
402
+ _context5.prev = 19;
403
+ url = new URL(host).href;
404
+ if (url.endsWith('/')) url = url.slice(0, -1);
405
+ if (url in urls) key = config['servers'][urls[url]]['key'];
406
+ _context5.next = 31;
376
407
  break;
377
- case 10:
378
- _context.prev = 10;
379
- _context.t0 = _context["catch"](1);
380
- console.error(_context.t0);
381
- code = 1;
382
- case 14:
383
- console.log("Exiting with code ".concat(code));
384
- process.exit(code);
385
- case 16:
408
+ case 25:
409
+ _context5.prev = 25;
410
+ _context5.t0 = _context5["catch"](19);
411
+ if (host in config.servers) {
412
+ _context5.next = 29;
413
+ break;
414
+ }
415
+ return _context5.abrupt("return", color.error("Unknown server alias. Please add it to ".concat(confPath)));
416
+ case 29:
417
+ url = config['servers'][host]['url'];
418
+ key = config['servers'][host]['key'];
419
+ case 31:
420
+ // Update the developer key
421
+ if (args.key) key = args.key;
422
+ if (!(key === '')) {
423
+ _context5.next = 34;
424
+ break;
425
+ }
426
+ return _context5.abrupt("return", color.warn('Please provide the key with `--key` option or add it by running `grok config`'));
427
+ case 34:
428
+ if (_fs["default"].existsSync(packDir)) {
429
+ _context5.next = 36;
430
+ break;
431
+ }
432
+ return _context5.abrupt("return", color.error('`package.json` doesn\'t exist'));
433
+ case 36:
434
+ _package = JSON.parse(_fs["default"].readFileSync(packDir, {
435
+ encoding: 'utf-8'
436
+ }));
437
+ packageName = _package.name; // Upload the package
438
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
439
+ process.on('beforeExit', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
440
+ var code;
441
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
442
+ while (1) switch (_context4.prev = _context4.next) {
443
+ case 0:
444
+ code = 0;
445
+ _context4.prev = 1;
446
+ exec('git rev-parse HEAD', function (error, stdout, stderr) {
447
+ if (error) {
448
+ console.error("Error executing command: ".concat(error.message));
449
+ return;
450
+ }
451
+ if (stderr) {
452
+ console.error("Standard Error: ".concat(stderr));
453
+ return;
454
+ }
455
+ if (!args.suffix && stdout) args.suffix = stdout.toString().substring(0, 8);
456
+ });
457
+ _context4.next = 5;
458
+ return utils.delay(100);
459
+ case 5:
460
+ _context4.next = 7;
461
+ return processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
462
+ case 7:
463
+ code = _context4.sent;
464
+ _context4.next = 14;
465
+ break;
466
+ case 10:
467
+ _context4.prev = 10;
468
+ _context4.t0 = _context4["catch"](1);
469
+ console.error(_context4.t0);
470
+ code = 1;
471
+ case 14:
472
+ console.log("Exiting with code ".concat(code));
473
+ process.exit(code);
474
+ case 16:
475
+ case "end":
476
+ return _context4.stop();
477
+ }
478
+ }, _callee4, null, [[1, 10]]);
479
+ })));
480
+ return _context5.abrupt("return", true);
481
+ case 41:
386
482
  case "end":
387
- return _context.stop();
483
+ return _context5.stop();
388
484
  }
389
- }, _callee, null, [[1, 10]]);
390
- })));
391
- return true;
485
+ }, _callee5, null, [[19, 25]]);
486
+ }));
487
+ return _publishPackage.apply(this, arguments);
392
488
  }