datagrok-tools 4.5.8 → 4.5.9

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.
@@ -50,7 +50,9 @@ function add(args) {
50
50
 
51
51
  var connectDir = _path["default"].join(curDir, 'connections');
52
52
 
53
- var packagePath = _path["default"].join(curDir, 'package.json'); // Package directory check
53
+ var packagePath = _path["default"].join(curDir, 'package.json');
54
+
55
+ var templateDir = _path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname))); // Package directory check
54
56
 
55
57
 
56
58
  if (!_fs["default"].existsSync(packagePath)) return color.error('`package.json` not found');
@@ -91,7 +93,7 @@ function add(args) {
91
93
  if (!_fs["default"].existsSync(srcDir)) _fs["default"].mkdirSync(srcDir);
92
94
 
93
95
  if (!_fs["default"].existsSync(packageEntry)) {
94
- var _contents = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template', 'src', 'package.js'), 'utf8');
96
+ var _contents = _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'src', 'package.js'), 'utf8');
95
97
 
96
98
  _fs["default"].writeFileSync(packageEntry, _contents, 'utf8');
97
99
  }
@@ -133,7 +135,7 @@ function add(args) {
133
135
  } // Copy the script template
134
136
 
135
137
 
136
- var templatePath = _path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'script-template');
138
+ var templatePath = _path["default"].join(templateDir, 'script-template');
137
139
 
138
140
  templatePath = _path["default"].join(templatePath, lang + '.' + utils.scriptLangExtMap[lang]);
139
141
  contents = _fs["default"].readFileSync(templatePath, 'utf8');
@@ -157,7 +159,7 @@ function add(args) {
157
159
 
158
160
  createPackageEntryFile(); // Add an app template to package.js
159
161
 
160
- var app = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'app.js'), 'utf8');
162
+ var app = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'app.js'), 'utf8');
161
163
 
162
164
  _fs["default"].appendFileSync(packageEntry, insertName(name, app));
163
165
 
@@ -184,7 +186,7 @@ function add(args) {
184
186
 
185
187
  var filename = tag === 'panel' ? 'panel' + ext : tag === 'init' ? 'init.js' : 'function' + ext;
186
188
 
187
- var func = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', filename), 'utf8');
189
+ var func = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', filename), 'utf8');
188
190
 
189
191
  _fs["default"].appendFileSync(packageEntry, insertName(name, func));
190
192
 
@@ -205,7 +207,7 @@ function add(args) {
205
207
  return color.error("The connection file already exists: ".concat(connectPath));
206
208
  }
207
209
 
208
- var connectionTemplate = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'connection.json'), 'utf8');
210
+ var connectionTemplate = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'connection.json'), 'utf8');
209
211
 
210
212
  _fs["default"].writeFileSync(connectPath, insertName(name, connectionTemplate), 'utf8');
211
213
 
@@ -220,7 +222,7 @@ function add(args) {
220
222
 
221
223
  if (!_fs["default"].existsSync(queryDir)) _fs["default"].mkdirSync(queryDir); // Add a query to queries.sql
222
224
 
223
- var query = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'queries.sql'), 'utf8');
225
+ var query = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'queries.sql'), 'utf8');
224
226
 
225
227
  contents = insertName(name, query);
226
228
  var connection;
@@ -235,7 +237,7 @@ function add(args) {
235
237
  } else {
236
238
  // Create the default connection file
237
239
  if (!_fs["default"].existsSync(connectDir)) _fs["default"].mkdirSync(connectDir);
238
- connection = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'connection.json'), 'utf8');
240
+ connection = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'connection.json'), 'utf8');
239
241
 
240
242
  _fs["default"].writeFileSync(_path["default"].join(connectDir, 'connection.json'), insertName('connection', connection), 'utf8');
241
243
 
@@ -268,12 +270,12 @@ function add(args) {
268
270
  return color.error("The view file already exists: ".concat(viewPath));
269
271
  }
270
272
 
271
- var viewClass = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'view-class' + ext), 'utf8');
273
+ var viewClass = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'view-class' + ext), 'utf8');
272
274
 
273
275
  _fs["default"].writeFileSync(viewPath, insertName(name, viewClass), 'utf8'); // Add a view function to package.js
274
276
 
275
277
 
276
- var view = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'view.js'), 'utf8');
278
+ var view = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'view.js'), 'utf8');
277
279
 
278
280
  contents = insertName(name, "import {#{NAME}} from './".concat(utils.camelCaseToKebab(name), "';\n"));
279
281
  contents += _fs["default"].readFileSync(packageEntry, 'utf8');
@@ -303,12 +305,12 @@ function add(args) {
303
305
  return color.error("The viewer file already exists: ".concat(viewerPath));
304
306
  }
305
307
 
306
- var viewerClass = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'viewer-class' + ext), 'utf8');
308
+ var viewerClass = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'viewer-class' + ext), 'utf8');
307
309
 
308
310
  _fs["default"].writeFileSync(viewerPath, insertName(name, viewerClass), 'utf8'); // Add a viewer function to package.js
309
311
 
310
312
 
311
- var viewer = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'viewer.js'), 'utf8');
313
+ var viewer = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'viewer.js'), 'utf8');
312
314
 
313
315
  contents = insertName(name, "import {#{NAME}} from './".concat(utils.camelCaseToKebab(name), "';\n"));
314
316
  contents += _fs["default"].readFileSync(packageEntry, 'utf8');
@@ -324,14 +326,14 @@ function add(args) {
324
326
  name = args['_'][2];
325
327
 
326
328
  if (!_fs["default"].existsSync(detectorsPath)) {
327
- var temp = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template', 'detectors.js'), 'utf8');
329
+ var temp = _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'detectors.js'), 'utf8');
328
330
 
329
331
  temp = utils.replacers['PACKAGE_DETECTORS_NAME'](temp, curFolder);
330
332
 
331
333
  _fs["default"].writeFileSync(detectorsPath, temp, 'utf8');
332
334
  }
333
335
 
334
- var detector = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'sem-type-detector.js'), 'utf8');
336
+ var detector = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'sem-type-detector.js'), 'utf8');
335
337
 
336
338
  contents = _fs["default"].readFileSync(detectorsPath, 'utf8');
337
339
  var idx = contents.search(/(?<=PackageDetectors extends DG.Package\s*{\s*(\r\n|\r|\n)).*/);
@@ -349,7 +351,15 @@ function add(args) {
349
351
  break;
350
352
 
351
353
  case 'tests':
352
- if (!_fs["default"].existsSync(webpackConfigPath) || !_fs["default"].existsSync(tsPath)) return false;
354
+ if (!_fs["default"].existsSync(tsPath)) {
355
+ color.error('Only TypeScript packages are supported');
356
+ return false;
357
+ }
358
+
359
+ if (!_fs["default"].existsSync(webpackConfigPath)) {
360
+ color.error('Webpack configuration not found');
361
+ return false;
362
+ }
353
363
 
354
364
  var config = _fs["default"].readFileSync(webpackConfigPath, 'utf8');
355
365
 
@@ -383,12 +393,24 @@ function add(args) {
383
393
 
384
394
  _fs["default"].writeFileSync(packagePath, JSON.stringify(packageObj, null, 2), 'utf8');
385
395
 
386
- 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')));
396
+ 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(templateDir, 'package-template', 'jest.config.js')));
387
397
  if (!_fs["default"].existsSync(_path["default"].join(srcDir, '__jest__'))) _fs["default"].mkdirSync(_path["default"].join(srcDir, '__jest__'));
388
- 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')));
389
- 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')));
390
- 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')));
391
- console.log('Run `npm install` to get newly added packages');
398
+ 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(templateDir, 'package-template', 'src', '__jest__', 'remote.test.ts')));
399
+ 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(templateDir, 'package-template', 'src', '__jest__', 'test-node.ts')));
400
+
401
+ var packageTestPath = _path["default"].join(srcDir, 'package-test.ts');
402
+
403
+ if (!_fs["default"].existsSync(packageTestPath)) _fs["default"].writeFileSync(packageTestPath, _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'src', 'package-test.ts')));
404
+
405
+ var testsDir = _path["default"].join(srcDir, 'tests');
406
+
407
+ if (!_fs["default"].existsSync(testsDir)) _fs["default"].mkdirSync(testsDir);
408
+
409
+ _fs["default"].writeFileSync(_path["default"].join(testsDir, 'test-examples.ts'), _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'test.ts')));
410
+
411
+ _fs["default"].writeFileSync(packageTestPath, "import './tests/test-examples';\n" + _fs["default"].readFileSync(packageTestPath));
412
+
413
+ console.log(_entHelpers.help.test(testsDir));
392
414
  break;
393
415
 
394
416
  default:
@@ -175,12 +175,14 @@ function config(args) {
175
175
  url: args.server,
176
176
  key: args.key
177
177
  };
178
- color.success('Successfully added the server.');
178
+ color.success("Successfully added the server to ".concat(confPath, "."));
179
179
  console.log("Use this command to deploy packages: grok publish ".concat(args.alias));
180
180
 
181
181
  if (args["default"]) {
182
182
  config["default"] = args.alias;
183
183
  }
184
+
185
+ return true;
184
186
  }
185
187
 
186
188
  console.log("Your config file (".concat(confPath, "):"));
@@ -19,7 +19,7 @@ var detector = function detector(semType) {
19
19
 
20
20
  var func = function func(funcName) {
21
21
  var isPanel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
22
- return "\nThe function ".concat(funcName, " has been added successfully\n") + 'Read more at https://datagrok.ai/help/overview/functions/function' + (isPanel ? ',\nhttps://datagrok.ai/help/develop/how-to/add-info-panel\n' : '\n') + 'See examples at https://public.datagrok.ai/functions' + (isPanel ? ',\nhttps://public.datagrok.ai/js/samples/functions/info-panels/info-panels' : '');
22
+ return "\nThe function ".concat(funcName, " has been added successfully\n") + 'Read more at https://datagrok.ai/help/datagrok/functions/function' + (isPanel ? ',\nhttps://datagrok.ai/help/develop/how-to/add-info-panel\n' : '\n') + 'See examples at https://public.datagrok.ai/functions' + (isPanel ? ',\nhttps://public.datagrok.ai/js/samples/functions/info-panels/info-panels' : '');
23
23
  };
24
24
 
25
25
  var query = function query(queryName) {
@@ -42,6 +42,10 @@ var _package = function _package(ts) {
42
42
  return ts ? '' : 'Consider TypeScript as a language for package development, to start over, run `grok create` with the `--ts` flag\n' + 'Likely next steps: `grok add` to add functionality, `grok publish` to upload the package';
43
43
  };
44
44
 
45
+ var test = function test(dir) {
46
+ return "Tests have been added successfully to ".concat(dir, "\nRun 'npm install' to get newly added packages\nRead more about package testing at https://datagrok.ai/help/develop/how-to/test-packages");
47
+ };
48
+
45
49
  var help = {
46
50
  app: app,
47
51
  connection: connection,
@@ -51,6 +55,7 @@ var help = {
51
55
  script: script,
52
56
  view: view,
53
57
  viewer: viewer,
54
- "package": _package
58
+ "package": _package,
59
+ test: test
55
60
  };
56
61
  exports.help = help;
@@ -0,0 +1,12 @@
1
+ import { category, expect, test } from '@datagrok-libraries/utils/src/test';
2
+
3
+
4
+ category('Examples', () => {
5
+ test('Success', async () => {
6
+ expect(1, 1);
7
+ });
8
+
9
+ test('Fail', () => {
10
+ throw 'Exception';
11
+ });
12
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.5.8",
3
+ "version": "4.5.9",
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": {