datagrok-tools 4.7.6 → 4.7.8
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 +1 -18
- package/bin/commands/check.js +75 -21
- package/bin/utils/interfaces.js +1 -0
- package/bin/utils/utils.js +13 -2
- package/package.json +1 -1
package/bin/commands/add.js
CHANGED
|
@@ -375,29 +375,12 @@ function add(args) {
|
|
|
375
375
|
Object.assign(packageObj.dependencies, {
|
|
376
376
|
'@datagrok-libraries/utils': 'latest'
|
|
377
377
|
});
|
|
378
|
-
Object.assign(packageObj.devDependencies, {
|
|
379
|
-
'jest-html-reporter': '^3.5.0',
|
|
380
|
-
'jest': '^27.0.0',
|
|
381
|
-
'@types/jest': '^27.0.0',
|
|
382
|
-
'js-yaml': '^4.1.0',
|
|
383
|
-
'@types/js-yaml': "^4.0.5",
|
|
384
|
-
'@types/node-fetch': '^2.6.2',
|
|
385
|
-
'node-fetch': '^2.6.7'
|
|
386
|
-
}, ts ? {
|
|
387
|
-
'ts-jest': '^27.0.0',
|
|
388
|
-
'puppeteer': '^13.7.0'
|
|
389
|
-
} : {});
|
|
390
378
|
Object.assign(packageObj.scripts, {
|
|
391
|
-
'test': '
|
|
379
|
+
'test': 'grok test'
|
|
392
380
|
});
|
|
393
381
|
|
|
394
382
|
_fs["default"].writeFileSync(packagePath, JSON.stringify(packageObj, null, 2), 'utf8');
|
|
395
383
|
|
|
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')));
|
|
397
|
-
if (!_fs["default"].existsSync(_path["default"].join(srcDir, '__jest__'))) _fs["default"].mkdirSync(_path["default"].join(srcDir, '__jest__'));
|
|
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
384
|
var packageTestPath = _path["default"].join(srcDir, 'package-test.ts');
|
|
402
385
|
|
|
403
386
|
if (!_fs["default"].existsSync(packageTestPath)) _fs["default"].writeFileSync(packageTestPath, _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'src', 'package-test.ts')));
|
package/bin/commands/check.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
@@ -12,6 +12,8 @@ exports.checkFuncSignatures = checkFuncSignatures;
|
|
|
12
12
|
exports.checkImportStatements = checkImportStatements;
|
|
13
13
|
exports.extractExternals = extractExternals;
|
|
14
14
|
|
|
15
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
16
|
+
|
|
15
17
|
var _fs = _interopRequireDefault(require("fs"));
|
|
16
18
|
|
|
17
19
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -24,7 +26,7 @@ var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
|
24
26
|
|
|
25
27
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
26
28
|
|
|
27
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
28
30
|
|
|
29
31
|
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; } } }; }
|
|
30
32
|
|
|
@@ -34,7 +36,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
34
36
|
|
|
35
37
|
function check(args) {
|
|
36
38
|
var nOptions = Object.keys(args).length - 1;
|
|
37
|
-
if (args['_'].length !== 1 || nOptions >
|
|
39
|
+
if (args['_'].length !== 1 || nOptions > 0 && (!args.dir || typeof args.dir !== 'string') || nOptions > 1) return false;
|
|
38
40
|
var curDir = process.cwd();
|
|
39
41
|
|
|
40
42
|
if (args.dir && typeof args.dir === 'string') {
|
|
@@ -84,14 +86,11 @@ function check(args) {
|
|
|
84
86
|
});
|
|
85
87
|
|
|
86
88
|
var externals = extractExternals(content);
|
|
87
|
-
if (externals) checkImportStatements(packagePath, jsTsFiles, externals)
|
|
88
|
-
return color.warn(warning);
|
|
89
|
-
});
|
|
89
|
+
if (externals) warn(checkImportStatements(packagePath, jsTsFiles, externals));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
checkFuncSignatures(packagePath, funcFiles)
|
|
93
|
-
|
|
94
|
-
});
|
|
92
|
+
warn(checkFuncSignatures(packagePath, funcFiles));
|
|
93
|
+
warn(checkPackageFile(packagePath));
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
return true;
|
|
@@ -334,11 +333,66 @@ function checkFuncSignatures(packagePath, files) {
|
|
|
334
333
|
return warnings;
|
|
335
334
|
}
|
|
336
335
|
|
|
336
|
+
function checkPackageFile(packagePath) {
|
|
337
|
+
var warnings = [];
|
|
338
|
+
|
|
339
|
+
var packageFilePath = _path["default"].join(packagePath, 'package.json');
|
|
340
|
+
|
|
341
|
+
var json = JSON.parse(_fs["default"].readFileSync(packageFilePath, {
|
|
342
|
+
encoding: 'utf-8'
|
|
343
|
+
}));
|
|
344
|
+
var isPublicPackage = _path["default"].basename(_path["default"].dirname(packagePath)) === 'packages' && _path["default"].basename(_path["default"].dirname(_path["default"].dirname(packagePath))) === 'public';
|
|
345
|
+
if (!json.description) warnings.push('File "package.json": "description" field is empty. Provide a package description.');
|
|
346
|
+
|
|
347
|
+
if (Array.isArray(json.properties) && json.properties.length > 0) {
|
|
348
|
+
var _iterator5 = _createForOfIteratorHelper(json.properties),
|
|
349
|
+
_step5;
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
353
|
+
var propInfo = _step5.value;
|
|
354
|
+
if ((0, _typeof2["default"])(propInfo) !== 'object') warnings.push('File "package.json": Invalid property annotation in the "properties" field.');else if (!propInfo.name) warnings.push('File "package.json": Add a property name for each property in the "properties" field.');else if (!utils.propertyTypes.includes(propInfo.propertyType)) warnings.push("File \"package.json\": Invalid property type for property ".concat(propInfo.name, "."));
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
_iterator5.e(err);
|
|
358
|
+
} finally {
|
|
359
|
+
_iterator5.f();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (json.repository == null && isPublicPackage) warnings.push('File "package.json": add the "repository" field.');
|
|
364
|
+
if (json.author == null && isPublicPackage) warnings.push('File "package.json": add the "author" field.');
|
|
365
|
+
|
|
366
|
+
if (Array.isArray(json.sources) && json.sources.length > 0) {
|
|
367
|
+
var _iterator6 = _createForOfIteratorHelper(json.sources),
|
|
368
|
+
_step6;
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
372
|
+
var source = _step6.value;
|
|
373
|
+
if (typeof source !== 'string') warnings.push("File \"package.json\": Only file paths and URLs are allowed in sources. Modify the source ".concat(source));
|
|
374
|
+
if (source.startsWith('common/') || utils.absUrlRegex.test(source)) continue;
|
|
375
|
+
if (source.startsWith('src/') && _fs["default"].existsSync(_path["default"].join(packagePath, 'webpack.config.js'))) warnings.push('File "package.json": Sources cannot include files from the \`src/\` directory. ' + "Move file ".concat(source, " to another folder."));
|
|
376
|
+
if (!_fs["default"].existsSync(_path["default"].join(packagePath, source))) warnings.push("Source ".concat(source, " not found in the package."));
|
|
377
|
+
}
|
|
378
|
+
} catch (err) {
|
|
379
|
+
_iterator6.e(err);
|
|
380
|
+
} finally {
|
|
381
|
+
_iterator6.f();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return warnings;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function warn(warnings) {
|
|
389
|
+
warnings.forEach(function (w) {
|
|
390
|
+
return color.warn(w);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
337
394
|
function getFuncMetadata(script) {
|
|
338
395
|
var funcData = [];
|
|
339
|
-
var headerTags = ['name', 'description', 'help-url', 'input', 'output', 'tags', 'sample', 'language', 'returns', 'test', 'sidebar', 'condition', 'top-menu', 'environment', 'require', 'editor-for', 'schedule', 'reference', 'editor'];
|
|
340
|
-
var paramRegex = new RegExp("//\\s*(".concat(headerTags.join('|'), "|meta\\.[^:]*): *(\\S+) ?(\\S+)?"));
|
|
341
|
-
var nameRegex = /(?:|static|export\s+function|export\s+async\s+function)\s+([a-zA-Z_][a-zA-Z0-9_$]*)\s*\((.*?)\).*/;
|
|
342
396
|
var isHeader = false;
|
|
343
397
|
var data = {
|
|
344
398
|
name: '',
|
|
@@ -346,14 +400,14 @@ function getFuncMetadata(script) {
|
|
|
346
400
|
outputs: []
|
|
347
401
|
};
|
|
348
402
|
|
|
349
|
-
var
|
|
350
|
-
|
|
403
|
+
var _iterator7 = _createForOfIteratorHelper(script.split('\n')),
|
|
404
|
+
_step7;
|
|
351
405
|
|
|
352
406
|
try {
|
|
353
|
-
for (
|
|
354
|
-
var line =
|
|
407
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
408
|
+
var line = _step7.value;
|
|
355
409
|
if (!line) continue;
|
|
356
|
-
var match = line.match(paramRegex);
|
|
410
|
+
var match = line.match(utils.paramRegex);
|
|
357
411
|
|
|
358
412
|
if (match) {
|
|
359
413
|
if (!isHeader) isHeader = true;
|
|
@@ -368,9 +422,9 @@ function getFuncMetadata(script) {
|
|
|
368
422
|
}
|
|
369
423
|
|
|
370
424
|
if (isHeader) {
|
|
371
|
-
var nm = line.match(nameRegex);
|
|
425
|
+
var nm = line.match(utils.nameRegex);
|
|
372
426
|
|
|
373
|
-
if (nm && !line.match(paramRegex)) {
|
|
427
|
+
if (nm && !line.match(utils.paramRegex)) {
|
|
374
428
|
data.name = data.name || nm[1];
|
|
375
429
|
funcData.push(data);
|
|
376
430
|
data = {
|
|
@@ -383,9 +437,9 @@ function getFuncMetadata(script) {
|
|
|
383
437
|
}
|
|
384
438
|
}
|
|
385
439
|
} catch (err) {
|
|
386
|
-
|
|
440
|
+
_iterator7.e(err);
|
|
387
441
|
} finally {
|
|
388
|
-
|
|
442
|
+
_iterator7.f();
|
|
389
443
|
}
|
|
390
444
|
|
|
391
445
|
return funcData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/bin/utils/utils.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.TemplateBuilder = void 0;
|
|
8
|
+
exports.absUrlRegex = exports.TemplateBuilder = void 0;
|
|
9
9
|
exports.camelCaseToKebab = camelCaseToKebab;
|
|
10
10
|
exports.checkScriptLocation = checkScriptLocation;
|
|
11
11
|
exports.dgToTsTypeMap = exports.dgImports = exports.commentMap = void 0;
|
|
@@ -14,11 +14,12 @@ exports.getParam = getParam;
|
|
|
14
14
|
exports.getScriptInputs = getScriptInputs;
|
|
15
15
|
exports.getScriptName = getScriptName;
|
|
16
16
|
exports.getScriptOutputType = getScriptOutputType;
|
|
17
|
+
exports.headerTags = void 0;
|
|
17
18
|
exports.isEmpty = isEmpty;
|
|
18
19
|
exports.isPackageDir = isPackageDir;
|
|
19
20
|
exports.kebabToCamelCase = kebabToCamelCase;
|
|
20
21
|
exports.mapURL = mapURL;
|
|
21
|
-
exports.queryWrapperTemplate = exports.queryExtension = exports.namespaceTemplate = void 0;
|
|
22
|
+
exports.queryWrapperTemplate = exports.queryExtension = exports.propertyTypes = exports.paramRegex = exports.namespaceTemplate = exports.nameRegex = void 0;
|
|
22
23
|
exports.removeScope = removeScope;
|
|
23
24
|
exports.scriptWrapperTemplate = exports.scriptLangExtMap = exports.scriptExtensions = exports.replacers = void 0;
|
|
24
25
|
exports.spaceToCamelCase = spaceToCamelCase;
|
|
@@ -264,6 +265,16 @@ var dgToTsTypeMap = {
|
|
|
264
265
|
file: 'DG.FileInfo'
|
|
265
266
|
};
|
|
266
267
|
exports.dgToTsTypeMap = dgToTsTypeMap;
|
|
268
|
+
var propertyTypes = ['bool', 'int', 'float', 'string', 'datetime', 'object', 'column', 'dataframe', 'bitset', 'cell', 'string_list', 'map'];
|
|
269
|
+
exports.propertyTypes = propertyTypes;
|
|
270
|
+
var headerTags = ['name', 'description', 'help-url', 'input', 'output', 'tags', 'sample', 'language', 'returns', 'test', 'sidebar', 'condition', 'top-menu', 'environment', 'require', 'editor-for', 'schedule', 'reference', 'editor'];
|
|
271
|
+
exports.headerTags = headerTags;
|
|
272
|
+
var paramRegex = new RegExp("//\\s*(".concat(headerTags.join('|'), "|meta\\.[^:]*): *(\\S+) ?(\\S+)?"));
|
|
273
|
+
exports.paramRegex = paramRegex;
|
|
274
|
+
var nameRegex = /(?:|static|export\s+function|export\s+async\s+function)\s+([a-zA-Z_][a-zA-Z0-9_$]*)\s*\((.*?)\).*/;
|
|
275
|
+
exports.nameRegex = nameRegex;
|
|
276
|
+
var absUrlRegex = new RegExp('^(?:[a-z+]+:)?//', 'i');
|
|
277
|
+
exports.absUrlRegex = absUrlRegex;
|
|
267
278
|
|
|
268
279
|
function getScriptOutputType(script) {
|
|
269
280
|
var comment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '#';
|
package/package.json
CHANGED