datagrok-tools 4.13.74 → 4.13.76
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 +96 -106
- package/bin/commands/api.js +65 -107
- package/bin/commands/check.js +264 -396
- package/bin/commands/config.js +82 -158
- package/bin/commands/create.js +65 -80
- package/bin/commands/help.js +194 -12
- package/bin/commands/init.js +73 -95
- package/bin/commands/link.js +70 -176
- package/bin/commands/publish.js +283 -484
- package/bin/commands/test-all.js +77 -291
- package/bin/commands/test.js +169 -391
- package/bin/utils/color-utils.js +8 -11
- package/bin/utils/ent-helpers.js +52 -42
- package/bin/utils/func-generation.js +25 -57
- package/bin/utils/interfaces.js +5 -1
- package/bin/utils/order-functions.js +47 -118
- package/bin/utils/test-utils.js +322 -750
- package/bin/utils/utils.js +123 -235
- package/bin/validators/config-validator.js +12 -14
- package/package.json +13 -4
package/bin/commands/add.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -11,67 +10,64 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
11
10
|
var _entHelpers = require("../utils/ent-helpers");
|
|
12
11
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
13
12
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
14
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
15
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
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
|
+
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; }
|
|
16
15
|
function add(args) {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const nOptions = Object.keys(args).length - 1;
|
|
17
|
+
const nArgs = args['_'].length;
|
|
19
18
|
if (nArgs < 2 || nArgs > 5 || nOptions > 0) return false;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
const entity = args['_'][1];
|
|
20
|
+
const curDir = process.cwd();
|
|
21
|
+
const curFolder = _path.default.basename(curDir);
|
|
22
|
+
const srcDir = _path.default.join(curDir, 'src');
|
|
23
|
+
const jsPath = _path.default.join(srcDir, 'package.js');
|
|
24
|
+
const tsPath = _path.default.join(srcDir, 'package.ts');
|
|
25
|
+
const detectorsPath = _path.default.join(curDir, 'detectors.js');
|
|
26
|
+
const webpackConfigPath = _path.default.join(curDir, 'webpack.config.js');
|
|
27
|
+
const scriptsDir = _path.default.join(curDir, 'scripts');
|
|
28
|
+
const queryDir = _path.default.join(curDir, 'queries');
|
|
29
|
+
const queryPath = _path.default.join(queryDir, 'queries.sql');
|
|
30
|
+
const connectDir = _path.default.join(curDir, 'connections');
|
|
31
|
+
const packagePath = _path.default.join(curDir, 'package.json');
|
|
32
|
+
const templateDir = _path.default.join(_path.default.dirname(_path.default.dirname(__dirname)));
|
|
34
33
|
|
|
35
34
|
// Package directory check
|
|
36
|
-
if (!_fs
|
|
35
|
+
if (!_fs.default.existsSync(packagePath)) return color.error('`package.json` not found');
|
|
37
36
|
try {
|
|
38
|
-
JSON.parse(_fs
|
|
37
|
+
JSON.parse(_fs.default.readFileSync(packagePath, {
|
|
39
38
|
encoding: 'utf-8'
|
|
40
39
|
}));
|
|
41
40
|
} catch (error) {
|
|
42
|
-
color.error(
|
|
41
|
+
color.error(`Error while reading ${packagePath}:`);
|
|
43
42
|
console.error(error);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
// TypeScript package check
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const ts = _fs.default.existsSync(_path.default.join(curDir, 'tsconfig.json'));
|
|
47
|
+
const packageEntry = ts ? tsPath : jsPath;
|
|
48
|
+
const ext = ts ? '.ts' : '.js';
|
|
50
49
|
function validateName(name) {
|
|
51
50
|
if (!/^([A-Za-z])+([A-Za-z\d])*$/.test(name)) return color.error('The name may only include letters and numbers. It cannot start with a digit');
|
|
52
51
|
return true;
|
|
53
52
|
}
|
|
54
53
|
function insertName(name, data) {
|
|
55
|
-
for (
|
|
56
|
-
var repl = _arr[_i];
|
|
57
|
-
data = utils.replacers[repl](data, name);
|
|
58
|
-
}
|
|
54
|
+
for (const repl of ['NAME', 'NAME_TITLECASE', 'NAME_LOWERCASE']) data = utils.replacers[repl](data, name);
|
|
59
55
|
return data;
|
|
60
56
|
}
|
|
61
57
|
function createPackageEntryFile() {
|
|
62
|
-
if (!_fs
|
|
63
|
-
if (!_fs
|
|
64
|
-
|
|
65
|
-
_fs
|
|
58
|
+
if (!_fs.default.existsSync(srcDir)) _fs.default.mkdirSync(srcDir);
|
|
59
|
+
if (!_fs.default.existsSync(packageEntry)) {
|
|
60
|
+
const contents = _fs.default.readFileSync(_path.default.join(templateDir, 'package-template', 'src', 'package.js'), 'utf8');
|
|
61
|
+
_fs.default.writeFileSync(packageEntry, contents, 'utf8');
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
let name;
|
|
65
|
+
let tag;
|
|
66
|
+
let contents;
|
|
71
67
|
switch (entity) {
|
|
72
68
|
case 'script':
|
|
73
69
|
if (nArgs < 4 || nArgs > 5) return false;
|
|
74
|
-
|
|
70
|
+
let lang = args['_'][2];
|
|
75
71
|
name = args['_'][3];
|
|
76
72
|
if (nArgs === 5) {
|
|
77
73
|
tag = args['_'][2];
|
|
@@ -79,7 +75,7 @@ function add(args) {
|
|
|
79
75
|
name = args['_'][4];
|
|
80
76
|
}
|
|
81
77
|
if (!Object.keys(utils.scriptLangExtMap).includes(lang)) {
|
|
82
|
-
color.error(
|
|
78
|
+
color.error(`Unsupported language: ${lang}`);
|
|
83
79
|
console.log('You can add a script in one of the following languages:');
|
|
84
80
|
console.log(Object.keys(utils.scriptLangExtMap).join(', '));
|
|
85
81
|
return false;
|
|
@@ -90,19 +86,19 @@ function add(args) {
|
|
|
90
86
|
if (tag && tag !== 'panel') return color.error('Currently, you can only add the `panel` tag');
|
|
91
87
|
|
|
92
88
|
// Create the folder `scripts` if it doesn't exist yet
|
|
93
|
-
if (!_fs
|
|
94
|
-
|
|
95
|
-
if (_fs
|
|
89
|
+
if (!_fs.default.existsSync(scriptsDir)) _fs.default.mkdirSync(scriptsDir);
|
|
90
|
+
const scriptPath = _path.default.join(scriptsDir, name + '.' + utils.scriptLangExtMap[lang]);
|
|
91
|
+
if (_fs.default.existsSync(scriptPath)) return color.error(`The file with the script already exists: ${scriptPath}`);
|
|
96
92
|
|
|
97
93
|
// Copy the script template
|
|
98
|
-
|
|
99
|
-
templatePath = _path
|
|
100
|
-
contents = _fs
|
|
94
|
+
let templatePath = _path.default.join(templateDir, 'script-template');
|
|
95
|
+
templatePath = _path.default.join(templatePath, lang + '.' + utils.scriptLangExtMap[lang]);
|
|
96
|
+
contents = _fs.default.readFileSync(templatePath, 'utf8');
|
|
101
97
|
if (tag) {
|
|
102
|
-
|
|
98
|
+
const ind = contents.indexOf('tags: ') + 6;
|
|
103
99
|
contents = contents.slice(0, ind) + 'panel, ' + contents.slice(ind);
|
|
104
100
|
}
|
|
105
|
-
_fs
|
|
101
|
+
_fs.default.writeFileSync(scriptPath, insertName(name, contents), 'utf8');
|
|
106
102
|
|
|
107
103
|
// Provide a JS wrapper for the script
|
|
108
104
|
console.log(_entHelpers.help.script(name, curFolder));
|
|
@@ -118,8 +114,8 @@ function add(args) {
|
|
|
118
114
|
createPackageEntryFile();
|
|
119
115
|
|
|
120
116
|
// Add an app template to package.js
|
|
121
|
-
|
|
122
|
-
_fs
|
|
117
|
+
const app = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'app.js'), 'utf8');
|
|
118
|
+
_fs.default.appendFileSync(packageEntry, insertName(name, app));
|
|
123
119
|
console.log(_entHelpers.help.app(name));
|
|
124
120
|
break;
|
|
125
121
|
case 'function':
|
|
@@ -136,9 +132,9 @@ function add(args) {
|
|
|
136
132
|
createPackageEntryFile();
|
|
137
133
|
|
|
138
134
|
// Add a function to package.js
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
_fs
|
|
135
|
+
const filename = tag === 'panel' ? 'panel' + ext : tag === 'init' ? 'init.js' : 'function' + ext;
|
|
136
|
+
const func = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', filename), 'utf8');
|
|
137
|
+
_fs.default.appendFileSync(packageEntry, insertName(name, func));
|
|
142
138
|
console.log(_entHelpers.help.func(name, tag === 'panel'));
|
|
143
139
|
break;
|
|
144
140
|
case 'connection':
|
|
@@ -149,11 +145,11 @@ function add(args) {
|
|
|
149
145
|
if (!validateName(name)) return false;
|
|
150
146
|
|
|
151
147
|
// Create the `connections` folder if it doesn't exist yet
|
|
152
|
-
if (!_fs
|
|
153
|
-
|
|
154
|
-
if (_fs
|
|
155
|
-
|
|
156
|
-
_fs
|
|
148
|
+
if (!_fs.default.existsSync(connectDir)) _fs.default.mkdirSync(connectDir);
|
|
149
|
+
const connectPath = _path.default.join(connectDir, `${name}.json`);
|
|
150
|
+
if (_fs.default.existsSync(connectPath)) return color.error(`The connection file already exists: ${connectPath}`);
|
|
151
|
+
const connectionTemplate = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'connection.json'), 'utf8');
|
|
152
|
+
_fs.default.writeFileSync(connectPath, insertName(name, connectionTemplate), 'utf8');
|
|
157
153
|
console.log(_entHelpers.help.connection(name));
|
|
158
154
|
break;
|
|
159
155
|
case 'query':
|
|
@@ -164,27 +160,24 @@ function add(args) {
|
|
|
164
160
|
if (!validateName(name)) return false;
|
|
165
161
|
|
|
166
162
|
// Create the `queries` folder if it doesn't exist yet
|
|
167
|
-
if (!_fs
|
|
163
|
+
if (!_fs.default.existsSync(queryDir)) _fs.default.mkdirSync(queryDir);
|
|
168
164
|
|
|
169
165
|
// Add a query to queries.sql
|
|
170
|
-
|
|
166
|
+
const query = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'queries.sql'), 'utf8');
|
|
171
167
|
contents = insertName(name, query);
|
|
172
|
-
|
|
173
|
-
if (_fs
|
|
174
|
-
var _fs$readdirSync$find;
|
|
168
|
+
let connection;
|
|
169
|
+
if (_fs.default.existsSync(connectDir) && _fs.default.readdirSync(connectDir).length !== 0) {
|
|
175
170
|
// Use the name of the first found connection
|
|
176
|
-
connection =
|
|
177
|
-
return /.+\.json$/.test(c);
|
|
178
|
-
})) === null || _fs$readdirSync$find === void 0 ? void 0 : _fs$readdirSync$find.slice(0, -5);
|
|
171
|
+
connection = _fs.default.readdirSync(connectDir).find(c => /.+\.json$/.test(c))?.slice(0, -5);
|
|
179
172
|
} else {
|
|
180
173
|
// Create the default connection file
|
|
181
|
-
if (!_fs
|
|
182
|
-
connection = _fs
|
|
183
|
-
_fs
|
|
174
|
+
if (!_fs.default.existsSync(connectDir)) _fs.default.mkdirSync(connectDir);
|
|
175
|
+
connection = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'connection.json'), 'utf8');
|
|
176
|
+
_fs.default.writeFileSync(_path.default.join(connectDir, 'connection.json'), insertName('connection', connection), 'utf8');
|
|
184
177
|
connection = 'connection';
|
|
185
178
|
}
|
|
186
179
|
contents = contents.replace('#{CONNECTION}', connection);
|
|
187
|
-
_fs
|
|
180
|
+
_fs.default.appendFileSync(queryPath, contents);
|
|
188
181
|
console.log(_entHelpers.help.query(name));
|
|
189
182
|
break;
|
|
190
183
|
case 'view':
|
|
@@ -199,17 +192,17 @@ function add(args) {
|
|
|
199
192
|
createPackageEntryFile();
|
|
200
193
|
|
|
201
194
|
// Add a new JS file with a view class
|
|
202
|
-
|
|
203
|
-
if (_fs
|
|
204
|
-
|
|
205
|
-
_fs
|
|
195
|
+
const viewPath = _path.default.join(srcDir, utils.camelCaseToKebab(name) + ext);
|
|
196
|
+
if (_fs.default.existsSync(viewPath)) return color.error(`The view file already exists: ${viewPath}`);
|
|
197
|
+
const viewClass = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'view-class' + ext), 'utf8');
|
|
198
|
+
_fs.default.writeFileSync(viewPath, insertName(name, viewClass), 'utf8');
|
|
206
199
|
|
|
207
200
|
// Add a view function to package.js
|
|
208
|
-
|
|
209
|
-
contents = insertName(name,
|
|
210
|
-
contents += _fs
|
|
201
|
+
const view = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'view.js'), 'utf8');
|
|
202
|
+
contents = insertName(name, `import {#{NAME}} from './${utils.camelCaseToKebab(name)}';\n`);
|
|
203
|
+
contents += _fs.default.readFileSync(packageEntry, 'utf8');
|
|
211
204
|
contents += insertName(name, view);
|
|
212
|
-
_fs
|
|
205
|
+
_fs.default.writeFileSync(packageEntry, contents, 'utf8');
|
|
213
206
|
console.log(_entHelpers.help.view(name));
|
|
214
207
|
break;
|
|
215
208
|
case 'viewer':
|
|
@@ -224,65 +217,62 @@ function add(args) {
|
|
|
224
217
|
createPackageEntryFile();
|
|
225
218
|
|
|
226
219
|
// Add a new JS file with a viewer class
|
|
227
|
-
|
|
228
|
-
if (_fs
|
|
229
|
-
|
|
230
|
-
_fs
|
|
220
|
+
const viewerPath = _path.default.join(srcDir, utils.camelCaseToKebab(name) + ext);
|
|
221
|
+
if (_fs.default.existsSync(viewerPath)) return color.error(`The viewer file already exists: ${viewerPath}`);
|
|
222
|
+
const viewerClass = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'viewer-class' + ext), 'utf8');
|
|
223
|
+
_fs.default.writeFileSync(viewerPath, insertName(name, viewerClass), 'utf8');
|
|
231
224
|
console.log(_entHelpers.help.viewer(name));
|
|
232
225
|
break;
|
|
233
226
|
case 'detector':
|
|
234
227
|
if (nArgs !== 3) return false;
|
|
235
228
|
name = args['_'][2];
|
|
236
|
-
if (!_fs
|
|
237
|
-
|
|
229
|
+
if (!_fs.default.existsSync(detectorsPath)) {
|
|
230
|
+
let temp = _fs.default.readFileSync(_path.default.join(templateDir, 'package-template', 'detectors.js'), 'utf8');
|
|
238
231
|
// eslint-disable-next-line new-cap
|
|
239
232
|
temp = utils.replacers['PACKAGE_DETECTORS_NAME'](temp, curFolder);
|
|
240
|
-
_fs
|
|
233
|
+
_fs.default.writeFileSync(detectorsPath, temp, 'utf8');
|
|
241
234
|
}
|
|
242
|
-
|
|
243
|
-
contents = _fs
|
|
244
|
-
|
|
235
|
+
const detector = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'sem-type-detector.js'), 'utf8');
|
|
236
|
+
contents = _fs.default.readFileSync(detectorsPath, 'utf8');
|
|
237
|
+
const idx = contents.search(/(?<=PackageDetectors extends DG.Package\s*{\s*(\r\n|\r|\n)).*/);
|
|
245
238
|
if (idx === -1) return color.error('Detectors class not found');
|
|
246
239
|
contents = contents.slice(0, idx) + detector + contents.slice(idx);
|
|
247
|
-
for (
|
|
248
|
-
|
|
249
|
-
contents = utils.replacers[repl](contents, name);
|
|
250
|
-
}
|
|
251
|
-
_fs["default"].writeFileSync(detectorsPath, contents, 'utf8');
|
|
240
|
+
for (const repl of ['NAME', 'NAME_PREFIX', 'PACKAGE_DETECTORS_NAME']) contents = utils.replacers[repl](contents, name);
|
|
241
|
+
_fs.default.writeFileSync(detectorsPath, contents, 'utf8');
|
|
252
242
|
console.log(_entHelpers.help.detector(name));
|
|
253
243
|
break;
|
|
254
244
|
case 'tests':
|
|
255
|
-
if (!_fs
|
|
245
|
+
if (!_fs.default.existsSync(tsPath)) {
|
|
256
246
|
color.error('Only TypeScript packages are supported');
|
|
257
247
|
return false;
|
|
258
248
|
}
|
|
259
|
-
if (!_fs
|
|
249
|
+
if (!_fs.default.existsSync(webpackConfigPath)) {
|
|
260
250
|
color.error('Webpack configuration not found');
|
|
261
251
|
return false;
|
|
262
252
|
}
|
|
263
|
-
|
|
253
|
+
const config = _fs.default.readFileSync(webpackConfigPath, 'utf8');
|
|
264
254
|
if (!/(?<=entry:\s*{\s*(\r\n|\r|\n))[^}]*test:/.test(config)) {
|
|
265
|
-
|
|
255
|
+
const entryIdx = config.search(/(?<=entry:\s*{\s*(\r\n|\r|\n)).*/);
|
|
266
256
|
if (entryIdx === -1) return color.error('Entry point not found during config parsing');
|
|
267
|
-
|
|
268
|
-
_fs
|
|
257
|
+
const testEntry = ' test: {filename: \'package-test.js\', library: ' + '{type: \'var\', name:`${packageName}_test`}, import: \'./src/package-test.ts\'},';
|
|
258
|
+
_fs.default.writeFileSync(webpackConfigPath, config.slice(0, entryIdx) + testEntry + config.slice(entryIdx), 'utf8');
|
|
269
259
|
}
|
|
270
|
-
|
|
260
|
+
const packageObj = JSON.parse(_fs.default.readFileSync(packagePath, 'utf8'));
|
|
271
261
|
Object.assign(packageObj.dependencies, {
|
|
272
262
|
'@datagrok-libraries/utils': 'latest'
|
|
273
263
|
});
|
|
274
264
|
Object.assign(packageObj.scripts, {
|
|
275
265
|
'test': 'grok test'
|
|
276
266
|
});
|
|
277
|
-
_fs
|
|
278
|
-
|
|
279
|
-
if (!_fs
|
|
280
|
-
_fs
|
|
267
|
+
_fs.default.writeFileSync(packagePath, JSON.stringify(packageObj, null, 2), 'utf8');
|
|
268
|
+
const packageTestPath = _path.default.join(srcDir, 'package-test.ts');
|
|
269
|
+
if (!_fs.default.existsSync(packageTestPath)) {
|
|
270
|
+
_fs.default.writeFileSync(packageTestPath, _fs.default.readFileSync(_path.default.join(templateDir, 'package-template', 'src', 'package-test.ts')));
|
|
281
271
|
}
|
|
282
|
-
|
|
283
|
-
if (!_fs
|
|
284
|
-
_fs
|
|
285
|
-
_fs
|
|
272
|
+
const testsDir = _path.default.join(srcDir, 'tests');
|
|
273
|
+
if (!_fs.default.existsSync(testsDir)) _fs.default.mkdirSync(testsDir);
|
|
274
|
+
_fs.default.writeFileSync(_path.default.join(testsDir, 'test-examples.ts'), _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'test.ts')));
|
|
275
|
+
_fs.default.writeFileSync(packageTestPath, `import './tests/test-examples';\n` + _fs.default.readFileSync(packageTestPath));
|
|
286
276
|
console.log(_entHelpers.help.test(testsDir));
|
|
287
277
|
break;
|
|
288
278
|
default:
|
package/bin/commands/api.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -11,140 +10,99 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
11
10
|
var _ignoreWalk = _interopRequireDefault(require("ignore-walk"));
|
|
12
11
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
13
12
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
14
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
15
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
16
|
-
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; } } }; }
|
|
17
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
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
|
+
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; }
|
|
19
15
|
function generateQueryWrappers() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!_fs
|
|
23
|
-
color.warn(
|
|
16
|
+
const curDir = process.cwd();
|
|
17
|
+
const queriesDir = _path.default.join(curDir, 'queries');
|
|
18
|
+
if (!_fs.default.existsSync(queriesDir)) {
|
|
19
|
+
color.warn(`Directory ${queriesDir} not found`);
|
|
24
20
|
console.log('Skipping API generation for queries...');
|
|
25
21
|
return;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const packagePath = _path.default.join(curDir, 'package.json');
|
|
24
|
+
const _package = JSON.parse(_fs.default.readFileSync(packagePath, {
|
|
29
25
|
encoding: 'utf-8'
|
|
30
26
|
}));
|
|
31
|
-
|
|
27
|
+
const files = _ignoreWalk.default.sync({
|
|
32
28
|
path: './queries',
|
|
33
29
|
ignoreFiles: ['.npmignore', '.gitignore']
|
|
34
30
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
54
|
-
var q = _step2.value;
|
|
55
|
-
var name = utils.getScriptName(q, utils.commentMap[utils.queryExtension]);
|
|
56
|
-
if (!name) continue;
|
|
57
|
-
var tb = new utils.TemplateBuilder(utils.queryWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
|
|
58
|
-
var inputs = utils.getScriptInputs(q, utils.commentMap[utils.queryExtension]);
|
|
59
|
-
var outputType = utils.getScriptOutputType(q, utils.commentMap[utils.queryExtension]);
|
|
60
|
-
tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs)
|
|
61
|
-
// The query output, if omitted, is a dataframe
|
|
62
|
-
.replace('OUTPUT_TYPE', outputType === 'void' ? utils.dgToTsTypeMap['dataframe'] : outputType);
|
|
63
|
-
wrappers.push(tb.build());
|
|
64
|
-
}
|
|
65
|
-
} catch (err) {
|
|
66
|
-
_iterator2.e(err);
|
|
67
|
-
} finally {
|
|
68
|
-
_iterator2.f();
|
|
69
|
-
}
|
|
31
|
+
const wrappers = [];
|
|
32
|
+
for (const file of files) {
|
|
33
|
+
if (!file.endsWith(utils.queryExtension)) continue;
|
|
34
|
+
const filepath = _path.default.join(queriesDir, file);
|
|
35
|
+
const script = _fs.default.readFileSync(filepath, 'utf8');
|
|
36
|
+
if (!script) continue;
|
|
37
|
+
const queries = script.split('--end').map(q => q.trim()).filter(q => q.length > 0);
|
|
38
|
+
for (const q of queries) {
|
|
39
|
+
const name = utils.getScriptName(q, utils.commentMap[utils.queryExtension]);
|
|
40
|
+
if (!name) continue;
|
|
41
|
+
const tb = new utils.TemplateBuilder(utils.queryWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
|
|
42
|
+
const inputs = utils.getScriptInputs(q, utils.commentMap[utils.queryExtension]);
|
|
43
|
+
const outputType = utils.getScriptOutputType(q, utils.commentMap[utils.queryExtension]);
|
|
44
|
+
tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs)
|
|
45
|
+
// The query output, if omitted, is a dataframe
|
|
46
|
+
.replace('OUTPUT_TYPE', outputType === 'void' ? utils.dgToTsTypeMap['dataframe'] : outputType);
|
|
47
|
+
wrappers.push(tb.build());
|
|
70
48
|
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
_iterator.e(err);
|
|
73
|
-
} finally {
|
|
74
|
-
_iterator.f();
|
|
75
49
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (_fs
|
|
80
|
-
color.warn(
|
|
50
|
+
const srcDir = _path.default.join(curDir, 'src');
|
|
51
|
+
const queryFileName = 'queries-api.ts';
|
|
52
|
+
const queryFilePath = _path.default.join(_fs.default.existsSync(srcDir) ? srcDir : curDir, queryFileName);
|
|
53
|
+
if (_fs.default.existsSync(queryFilePath)) {
|
|
54
|
+
color.warn(`The file ${queryFilePath} already exists`);
|
|
81
55
|
console.log('Rewriting its contents...');
|
|
82
56
|
}
|
|
83
|
-
|
|
84
|
-
_fs
|
|
85
|
-
color.success(
|
|
57
|
+
const sep = '\n';
|
|
58
|
+
_fs.default.writeFileSync(queryFilePath, utils.dgImports + sep + wrappers.join(sep.repeat(2)) + sep, 'utf8');
|
|
59
|
+
color.success(`Successfully generated file ${queryFileName}${sep}`);
|
|
86
60
|
}
|
|
87
61
|
function generateScriptWrappers() {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!_fs
|
|
91
|
-
color.warn(
|
|
62
|
+
const curDir = process.cwd();
|
|
63
|
+
const scriptsDir = _path.default.join(curDir, 'scripts');
|
|
64
|
+
if (!_fs.default.existsSync(scriptsDir)) {
|
|
65
|
+
color.warn(`Directory ${scriptsDir} not found`);
|
|
92
66
|
console.log('Skipping API generation for scripts...');
|
|
93
67
|
return;
|
|
94
68
|
}
|
|
95
|
-
|
|
96
|
-
|
|
69
|
+
const packagePath = _path.default.join(curDir, 'package.json');
|
|
70
|
+
const _package = JSON.parse(_fs.default.readFileSync(packagePath, {
|
|
97
71
|
encoding: 'utf-8'
|
|
98
72
|
}));
|
|
99
|
-
|
|
73
|
+
const files = _ignoreWalk.default.sync({
|
|
100
74
|
path: './scripts',
|
|
101
75
|
ignoreFiles: ['.npmignore', '.gitignore']
|
|
102
76
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (!name) return 0; // continue
|
|
118
|
-
var tb = new utils.TemplateBuilder(utils.scriptWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
|
|
119
|
-
var inputs = utils.getScriptInputs(script);
|
|
120
|
-
var outputType = utils.getScriptOutputType(script);
|
|
121
|
-
tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs).replace('OUTPUT_TYPE', outputType);
|
|
122
|
-
wrappers.push(tb.build(1));
|
|
123
|
-
},
|
|
124
|
-
_ret;
|
|
125
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
126
|
-
_ret = _loop();
|
|
127
|
-
if (_ret === 0) continue;
|
|
128
|
-
}
|
|
129
|
-
} catch (err) {
|
|
130
|
-
_iterator3.e(err);
|
|
131
|
-
} finally {
|
|
132
|
-
_iterator3.f();
|
|
77
|
+
const wrappers = [];
|
|
78
|
+
for (const file of files) {
|
|
79
|
+
let extension;
|
|
80
|
+
if (!utils.scriptExtensions.some(ext => (extension = ext, file.endsWith(ext)))) continue;
|
|
81
|
+
const filepath = _path.default.join(scriptsDir, file);
|
|
82
|
+
const script = _fs.default.readFileSync(filepath, 'utf8');
|
|
83
|
+
if (!script) continue;
|
|
84
|
+
const name = utils.getScriptName(script, utils.commentMap[extension]);
|
|
85
|
+
if (!name) continue;
|
|
86
|
+
const tb = new utils.TemplateBuilder(utils.scriptWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
|
|
87
|
+
const inputs = utils.getScriptInputs(script);
|
|
88
|
+
const outputType = utils.getScriptOutputType(script);
|
|
89
|
+
tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs).replace('OUTPUT_TYPE', outputType);
|
|
90
|
+
wrappers.push(tb.build(1));
|
|
133
91
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (_fs
|
|
138
|
-
color.warn(
|
|
92
|
+
const srcDir = _path.default.join(curDir, 'src');
|
|
93
|
+
const funcFileName = 'scripts-api.ts';
|
|
94
|
+
const funcFilePath = _path.default.join(_fs.default.existsSync(srcDir) ? srcDir : curDir, funcFileName);
|
|
95
|
+
if (_fs.default.existsSync(funcFilePath)) {
|
|
96
|
+
color.warn(`The file ${funcFilePath} already exists`);
|
|
139
97
|
console.log('Rewriting its contents...');
|
|
140
98
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
_fs
|
|
144
|
-
color.success(
|
|
99
|
+
const sep = '\n';
|
|
100
|
+
const scriptApi = new utils.TemplateBuilder(utils.namespaceTemplate).replace('PACKAGE_NAMESPACE', _package.name).replace('NAME', wrappers.join(sep.repeat(2)));
|
|
101
|
+
_fs.default.writeFileSync(funcFilePath, utils.dgImports + sep + scriptApi.build() + sep, 'utf8');
|
|
102
|
+
color.success(`Successfully generated file ${funcFileName}${sep}`);
|
|
145
103
|
}
|
|
146
104
|
function api(args) {
|
|
147
|
-
|
|
105
|
+
const nOptions = Object.keys(args).length - 1;
|
|
148
106
|
if (args['_'].length !== 1 || nOptions > 0) return false;
|
|
149
107
|
if (!utils.isPackageDir(process.cwd())) {
|
|
150
108
|
color.error('File `package.json` not found. Run the command from the package directory');
|