datagrok-tools 4.14.25 → 4.14.27
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 +9 -0
- package/bin/commands/api.js +3 -1
- package/bin/commands/publish.js +5 -2
- package/bin/grok.js +7 -1
- package/bin/utils/func-generation.js +3 -1
- package/bin/utils/utils.js +36 -2
- package/package.json +1 -1
- package/plugins/func-gen-plugin.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Datagrok-tools changelog
|
|
2
2
|
|
|
3
|
+
## 4.14.26 (2025-07-10)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* Grok Decorators added support for ViewBase type
|
|
8
|
+
* Grok Decorators updated comments and line feeds
|
|
9
|
+
* Grok Api updated comments and line feeds
|
|
10
|
+
* Grok Api minor type update
|
|
11
|
+
|
|
3
12
|
## 4.14.19 (2025-06-23)
|
|
4
13
|
|
|
5
14
|
### Features
|
package/bin/commands/api.js
CHANGED
|
@@ -12,6 +12,7 @@ var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
|
12
12
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
13
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
14
|
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; }
|
|
15
|
+
const annotationForApiFile = `/**\nThis file is auto-generated by the grok api command.\nIf you notice any changes, please push them to the repository.\nDo not edit this file manually.\n*/\n`;
|
|
15
16
|
const sep = '\n';
|
|
16
17
|
const packageFuncDirs = ['package.ts', 'package.g.ts'];
|
|
17
18
|
const apiFile = 'package-api.ts';
|
|
@@ -112,6 +113,7 @@ function generateFunctionWrappers() {
|
|
|
112
113
|
saveWrappersToFile('funcs', wrappers);
|
|
113
114
|
}
|
|
114
115
|
function saveWrappersToFile(namespaceName, wrappers) {
|
|
116
|
+
if (wrappers.length === 0) return;
|
|
115
117
|
if (!_fs.default.existsSync(funcFilePath)) createApiFile();
|
|
116
118
|
const scriptApi = new utils.TemplateBuilder(utils.namespaceTemplate).replace('PACKAGE_NAMESPACE', namespaceName).replace('NAME', wrappers.join(sep.repeat(2)));
|
|
117
119
|
_fs.default.appendFileSync(funcFilePath, sep + scriptApi.build() + sep);
|
|
@@ -122,7 +124,7 @@ function createApiFile() {
|
|
|
122
124
|
color.warn(`The file ${funcFilePath} already exists`);
|
|
123
125
|
console.log('Rewriting its contents...');
|
|
124
126
|
}
|
|
125
|
-
_fs.default.writeFileSync(funcFilePath, utils.dgImports + sep, 'utf8');
|
|
127
|
+
_fs.default.writeFileSync(funcFilePath, annotationForApiFile + utils.dgImports + sep, 'utf8');
|
|
126
128
|
}
|
|
127
129
|
function checkNameColision(name) {
|
|
128
130
|
if (names.has(name)) console.log('There is collision in name ' + name);
|
package/bin/commands/publish.js
CHANGED
|
@@ -207,13 +207,14 @@ async function processPackage(debug, rebuild, host, devKey, packageName, suffix)
|
|
|
207
207
|
return 0;
|
|
208
208
|
}
|
|
209
209
|
async function publish(args) {
|
|
210
|
-
|
|
210
|
+
console.log('publish');
|
|
211
|
+
if (!args['skip-check'] && !args['all']) (0, _check.check)({
|
|
211
212
|
_: ['check']
|
|
212
213
|
});
|
|
213
214
|
config = _jsYaml.default.load(_fs.default.readFileSync(confPath, {
|
|
214
215
|
encoding: 'utf-8'
|
|
215
216
|
}));
|
|
216
|
-
if (args.refresh
|
|
217
|
+
if (args.refresh) {
|
|
217
218
|
if (_path.default.basename(curDir) !== 'packages') curDir = _path.default.dirname(curDir);
|
|
218
219
|
let host = config.default;
|
|
219
220
|
if (args['_'].length === 2) host = args['_'][1];
|
|
@@ -249,6 +250,8 @@ async function publishPackage(args) {
|
|
|
249
250
|
if (nArgs > 2 || nOptions > 5) return false;
|
|
250
251
|
if (!Object.keys(args).slice(1).every(option => ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option))) return false;
|
|
251
252
|
if (args.build && args.rebuild) {
|
|
253
|
+
utils.runScript('npm install', curDir, false);
|
|
254
|
+
utils.runScript('npm run build', curDir, false);
|
|
252
255
|
color.error('Incompatible options: --build and --rebuild');
|
|
253
256
|
return false;
|
|
254
257
|
}
|
package/bin/grok.js
CHANGED
|
@@ -3,6 +3,7 @@ const argv = require('minimist')(process.argv.slice(2), {
|
|
|
3
3
|
alias: {k: 'key', h: 'help', r: 'recursive'},
|
|
4
4
|
});
|
|
5
5
|
const help = require('./commands/help').help;
|
|
6
|
+
const runAllCommand = require('./utils/utils').runAll;
|
|
6
7
|
|
|
7
8
|
const commands = {
|
|
8
9
|
add: require('./commands/add').add,
|
|
@@ -17,13 +18,18 @@ const commands = {
|
|
|
17
18
|
testall: require('./commands/test-all').testAll,
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
+
const onPackageCommandNames = ['api', 'check', 'link', 'publish', 'test'];
|
|
22
|
+
|
|
23
|
+
const command = argv['_'][0];
|
|
21
24
|
if (command in commands) {
|
|
22
25
|
try {
|
|
23
26
|
if(argv["help"]){
|
|
24
27
|
console.log(help[command]);
|
|
25
28
|
exitWithCode(1);
|
|
26
29
|
}
|
|
30
|
+
else if (argv.all && onPackageCommandNames.includes(command)){
|
|
31
|
+
runAllCommand(process.cwd(), `grok ${process.argv.slice(2).join(' ')}`.replace('--all', ''), {});
|
|
32
|
+
}
|
|
27
33
|
else if (!commands[command](argv)) {
|
|
28
34
|
console.log(help[command]);
|
|
29
35
|
exitWithCode(1);
|
|
@@ -106,7 +106,9 @@ const typesToAnnotation = exports.typesToAnnotation = {
|
|
|
106
106
|
'Dayjs': 'datetime',
|
|
107
107
|
'graphics': 'graphics',
|
|
108
108
|
'DG.View': 'view',
|
|
109
|
+
'DG.ViewBase': 'view',
|
|
109
110
|
'View': 'view',
|
|
111
|
+
'ViewBase': 'view',
|
|
110
112
|
'DG.Widget': 'widget',
|
|
111
113
|
'Widget': 'widget',
|
|
112
114
|
'DG.FuncCall': 'funccall',
|
|
@@ -428,7 +430,7 @@ const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean
|
|
|
428
430
|
function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
|
|
429
431
|
let funcSigNature = inputs.map(e => `${e.name}: ${primitives.has(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] ? e.type : 'any'}`).join(', ');
|
|
430
432
|
let funcArguments = inputs.map(e => e.name).join(', ');
|
|
431
|
-
return annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep
|
|
433
|
+
return sep + annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep}`;
|
|
432
434
|
}
|
|
433
435
|
function generateImport(className, path, sep = '\n') {
|
|
434
436
|
return `import {${className}} from '${path}';${sep}`;
|
package/bin/utils/utils.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.mapURL = mapURL;
|
|
|
27
27
|
exports.queryWrapperTemplate = exports.queryExtension = exports.propertyTypes = exports.namespaceTemplate = exports.nameRegex = exports.nameAnnRegex = void 0;
|
|
28
28
|
exports.removeScope = removeScope;
|
|
29
29
|
exports.replacers = void 0;
|
|
30
|
+
exports.runAll = runAll;
|
|
30
31
|
exports.runScript = runScript;
|
|
31
32
|
exports.scriptWrapperTemplate = exports.scriptLangExtMap = exports.scriptExtensions = void 0;
|
|
32
33
|
exports.setHost = setHost;
|
|
@@ -54,7 +55,7 @@ function kebabToCamelCase(s, firstUpper = true) {
|
|
|
54
55
|
}
|
|
55
56
|
function descriptionToComment(s) {
|
|
56
57
|
if (s.length === 0) return '';
|
|
57
|
-
return '
|
|
58
|
+
return '/**\n' + s + '\n*/\n';
|
|
58
59
|
}
|
|
59
60
|
function spaceToCamelCase(s, firstUpper = true) {
|
|
60
61
|
s = s.replace(/\s+./g, x => x[x.length - 1].toUpperCase());
|
|
@@ -241,7 +242,7 @@ function getScriptDescription(script, comment = '#') {
|
|
|
241
242
|
return desc;
|
|
242
243
|
}
|
|
243
244
|
;
|
|
244
|
-
const dgImports = exports.dgImports = `import * as grok from 'datagrok-api/grok';\nimport * as DG from 'datagrok-api/dg';\n
|
|
245
|
+
const dgImports = exports.dgImports = `import * as grok from 'datagrok-api/grok';\nimport * as DG from 'datagrok-api/dg';\n`;
|
|
245
246
|
const scriptWrapperTemplate = exports.scriptWrapperTemplate = `#{FUNC_DESCRIPTION}export async function #{FUNC_NAME_LOWERCASE}(#{TYPED_PARAMS}): Promise<#{OUTPUT_TYPE}> {
|
|
246
247
|
return await grok.functions.call('#{PACKAGE_NAMESPACE}:#{FUNC_NAME}', #{PARAMS_OBJECT});
|
|
247
248
|
}`;
|
|
@@ -281,4 +282,37 @@ function setHost(host, configFile) {
|
|
|
281
282
|
process.env.HOST = configFile.default;
|
|
282
283
|
console.log('Environment variable `HOST` is set to', configFile.default);
|
|
283
284
|
}
|
|
285
|
+
}
|
|
286
|
+
async function runAll(packagesDir, command, options, packagesToLoad = ['all']) {
|
|
287
|
+
const packages = _fs.default.readdirSync(packagesDir);
|
|
288
|
+
const commandToRun = `${command} ${optionsToString(options)}`;
|
|
289
|
+
for (const packageName of packages) {
|
|
290
|
+
const packagePath = _path.default.join(...[packagesDir, packageName]);
|
|
291
|
+
const packageJsonPath = _path.default.join(...[packagesDir, packageName, 'package.json']);
|
|
292
|
+
if (_fs.default.statSync(packagePath).isDirectory() && _fs.default.existsSync(packageJsonPath)) {
|
|
293
|
+
try {
|
|
294
|
+
console.log(`${packagePath}: ${commandToRun} - Started`);
|
|
295
|
+
await runScript(commandToRun, packagePath, options.verbose);
|
|
296
|
+
console.log(`${packagePath}: ${commandToRun} - Finished`);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
console.log(`${packagePath}: ${commandToRun} - Error`);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
function optionsToString(options) {
|
|
306
|
+
const parts = [];
|
|
307
|
+
for (const [key, value] of Object.entries(options)) {
|
|
308
|
+
if (key === '_' || key === 'all') continue;
|
|
309
|
+
if (typeof value === 'boolean') {
|
|
310
|
+
if (value) {
|
|
311
|
+
parts.push(`--${key}`);
|
|
312
|
+
}
|
|
313
|
+
} else if (value !== undefined && value !== null) {
|
|
314
|
+
parts.push(`--${key}="${value}"`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return parts.join(' ');
|
|
284
318
|
}
|
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
} = require("../bin/utils/func-generation");
|
|
15
15
|
|
|
16
16
|
const baseImport = "import * as DG from 'datagrok-api/dg';\n";
|
|
17
|
+
const annotationForGeneratedFile = `/**\nThis file is auto-generated by the webpack command.\nIf you notice any changes, please push them to the repository.\nDo not edit this file manually.\n*/\n`;
|
|
17
18
|
|
|
18
19
|
class FuncGeneratorPlugin {
|
|
19
20
|
constructor(options = { outputPath: "./src/package.g.ts" }) {
|
|
@@ -252,7 +253,7 @@ class FuncGeneratorPlugin {
|
|
|
252
253
|
let params =
|
|
253
254
|
baseParam.typeAnnotation.typeAnnotation.typeArguments?.params;
|
|
254
255
|
if (type !== "any" && params && params.length > 0)
|
|
255
|
-
type += `<${params.map((e) => e.typeName
|
|
256
|
+
type += `<${params.map((e) => e.typeName?.name ?? 'any').join(",")}>`;
|
|
256
257
|
|
|
257
258
|
return { name: name, type: type, options: options };
|
|
258
259
|
}
|
|
@@ -445,7 +446,7 @@ class FuncGeneratorPlugin {
|
|
|
445
446
|
const importStatement = imports[i];
|
|
446
447
|
const exportStatement = exp[i];
|
|
447
448
|
if (!content.includes(importStatement.trim()))
|
|
448
|
-
content = importStatement + content + exportStatement;
|
|
449
|
+
content = annotationForGeneratedFile + importStatement + content + exportStatement;
|
|
449
450
|
}
|
|
450
451
|
fs.writeFileSync(filePath, content, "utf-8");
|
|
451
452
|
}
|