datagrok-tools 4.5.2 → 4.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,6 +74,7 @@ Read more about package development in [Datagrok's documentation](https://datagr
74
74
  grok add script [tag] <language> <name>
75
75
  grok add view <name>
76
76
  grok add viewer <name>
77
+ grok add tests
77
78
  ```
78
79
 
79
80
  In general, entity names follow naming rules for functions. Views and viewers should have class names, we recommend
@@ -40,6 +40,8 @@ function add(args) {
40
40
 
41
41
  var detectorsPath = _path["default"].join(curDir, 'detectors.js');
42
42
 
43
+ var webpackConfigPath = _path["default"].join(curDir, 'webpack.config.js');
44
+
43
45
  var scriptsDir = _path["default"].join(curDir, 'scripts');
44
46
 
45
47
  var queryDir = _path["default"].join(curDir, 'queries');
@@ -346,6 +348,45 @@ function add(args) {
346
348
  console.log(_entHelpers.help.detector(name));
347
349
  break;
348
350
 
351
+ case 'tests':
352
+ if (!_fs["default"].existsSync(webpackConfigPath) || !_fs["default"].existsSync(tsPath)) return false;
353
+
354
+ var config = _fs["default"].readFileSync(webpackConfigPath, 'utf8');
355
+
356
+ if (!/(?<=entry:\s*{\s*(\r\n|\r|\n))[^}]*test:/.test(config)) {
357
+ var entryIdx = config.search(/(?<=entry:\s*{\s*(\r\n|\r|\n)).*/);
358
+ if (entryIdx === -1) return color.error('Entry point not found during config parsing');
359
+ var testEntry = " test: {filename: 'package-test.js', library: " + "{type: 'var', name:`${packageName}_test`}, import: './src/package-test.ts'},\n";
360
+
361
+ _fs["default"].writeFileSync(webpackConfigPath, config.slice(0, entryIdx) + testEntry + config.slice(entryIdx), 'utf8');
362
+ }
363
+
364
+ var packageObj = JSON.parse(_fs["default"].readFileSync(packagePath, 'utf8'));
365
+ Object.assign(packageObj.devDependencies, {
366
+ 'jest-html-reporter': '^3.5.0',
367
+ 'jest': '^27.0.0',
368
+ '@types/jest': '^27.0.0',
369
+ 'js-yaml': '^4.1.0',
370
+ '@types/js-yaml': "^4.0.5",
371
+ '@types/node-fetch': '^2.6.2',
372
+ 'node-fetch': '^2.6.7'
373
+ }, ts ? {
374
+ 'ts-jest': '^27.0.0',
375
+ 'puppeteer': '^13.7.0'
376
+ } : {});
377
+ Object.assign(packageObj.scripts, {
378
+ 'test': 'jest'
379
+ });
380
+
381
+ _fs["default"].writeFileSync(packagePath, JSON.stringify(packageObj, null, 2), 'utf8');
382
+
383
+ if (!_fs["default"].existsSync(_path["default"].join(curDir, 'jest.config.js'))) _fs["default"].writeFileSync(_path["default"].join(curDir, 'jest.config.js'), _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template', 'jest.config.js')));
384
+ if (!_fs["default"].existsSync(_path["default"].join(srcDir, '__jest__', 'remote.test.ts'))) _fs["default"].writeFileSync(_path["default"].join(srcDir, '__jest__', 'remote.test.ts'), _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template', 'src', '__jest__', 'remote.test.ts')));
385
+ if (!_fs["default"].existsSync(_path["default"].join(srcDir, '__jest__', 'test-node.ts'))) _fs["default"].writeFileSync(_path["default"].join(srcDir, '__jest__', 'test-node.ts'), _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template', 'src', '__jest__', 'test-node.ts')));
386
+ if (!_fs["default"].existsSync(_path["default"].join(srcDir, 'package-test.ts'))) _fs["default"].writeFileSync(_path["default"].join(srcDir, 'package-test.ts'), _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template', 'src', 'package-test.ts')));
387
+ console.log('Run `npm install` to get newly added packages');
388
+ break;
389
+
349
390
  default:
350
391
  return false;
351
392
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.help = void 0;
7
7
  var HELP = "\nUsage: grok <command>\n\nDatagrok's package management tool\n\nCommands:\n add Add an object template\n api Create wrapper functions\n config Create and manage config files\n create Create a package\n publish Upload a package\n migrate Switch to `grok` tools\n\nTo get help on a particular command, use:\n grok <command> --help\n\nRead more about the package development workflow:\nhttps://datagrok.ai/help/develop/develop\n";
8
- var HELP_ADD = "\nUsage: grok add <entity> <name>\n\nAdd an object template to your package:\n\ngrok add app <name>\ngrok add connection <name>\ngrok add detector <semantic-type-name>\ngrok add function [tag] <name>\ngrok add query <name>\ngrok add script [tag] <language> <name>\ngrok add view <name>\ngrok add viewer <name>\n\nPlease note that entity names may only include letters and numbers\n\nSupported languages for scripts:\njavascript, julia, node, octave, python, r\n\nAvailable tags:\npanel, init\n";
8
+ var HELP_ADD = "\nUsage: grok add <entity> <name>\n\nAdd an object template to your package:\n\ngrok add app <name>\ngrok add connection <name>\ngrok add detector <semantic-type-name>\ngrok add function [tag] <name>\ngrok add query <name>\ngrok add script [tag] <language> <name>\ngrok add view <name>\ngrok add viewer <name>\ngrok add tests\n\nPlease note that entity names may only include letters and numbers\n\nSupported languages for scripts:\njavascript, julia, node, octave, python, r\n\nAvailable tags:\npanel, init\n";
9
9
  var HELP_API = "\nUsage: grok api\n\nCreate wrapper functions for package scripts and queries\n";
10
10
  var HELP_CONFIG = "\nUsage: grok config\n\nCreate or update a configuration file\n\nOptions:\n[--reset] [--server] [--alias] [--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";
11
11
  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] [--jest]\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--jest Add a configuration for jest\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.5.2",
3
+ "version": "4.5.3",
4
4
  "description": "Utility to upload and publish packages to Datagrok",
5
5
  "homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
6
6
  "dependencies": {