datagrok-tools 4.6.0 → 4.6.2
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/check.js +63 -38
- package/bin/commands/help.js +1 -1
- package/bin/commands/publish.js +46 -17
- package/package-template/webpack.config.js +1 -0
- package/package.json +1 -1
package/bin/commands/check.js
CHANGED
|
@@ -8,6 +8,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
10
|
exports.check = check;
|
|
11
|
+
exports.checkFuncSignatures = checkFuncSignatures;
|
|
12
|
+
exports.checkImportStatements = checkImportStatements;
|
|
13
|
+
exports.extractExternals = extractExternals;
|
|
11
14
|
|
|
12
15
|
var _fs = _interopRequireDefault(require("fs"));
|
|
13
16
|
|
|
@@ -31,44 +34,66 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
31
34
|
|
|
32
35
|
function check(args) {
|
|
33
36
|
var nOptions = Object.keys(args).length - 1;
|
|
34
|
-
if (args['_'].length !== 1 || nOptions >
|
|
37
|
+
if (args['_'].length !== 1 || nOptions > 1 && (!args.dir || typeof args.dir !== 'string') || nOptions > 2) return false;
|
|
35
38
|
var curDir = process.cwd();
|
|
36
39
|
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
if (args.dir && typeof args.dir === 'string') {
|
|
41
|
+
var packagesDir = _path["default"].isAbsolute(args.dir) ? args.dir : _path["default"].join(curDir, args.dir);
|
|
42
|
+
|
|
43
|
+
_fs["default"].readdirSync(packagesDir).forEach(function (file) {
|
|
44
|
+
var filepath = _path["default"].join(packagesDir, file);
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
ignoreFiles: ['.npmignore', '.gitignore']
|
|
44
|
-
});
|
|
46
|
+
var stats = _fs["default"].statSync(filepath);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
if (stats.isDirectory() && utils.isPackageDir(filepath)) {
|
|
49
|
+
console.log("Checking package ".concat(file, "..."));
|
|
50
|
+
runChecks(filepath);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
if (!utils.isPackageDir(curDir)) {
|
|
55
|
+
color.error('File `package.json` not found. Run the command from the package directory');
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
console.log("Checking package ".concat(_path["default"].basename(curDir), "..."));
|
|
60
|
+
runChecks(curDir);
|
|
61
|
+
}
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
function runChecks(packagePath) {
|
|
64
|
+
var files = _ignoreWalk["default"].sync({
|
|
65
|
+
path: packagePath,
|
|
66
|
+
ignoreFiles: ['.npmignore', '.gitignore']
|
|
67
|
+
});
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
var jsTsFiles = files.filter(function (f) {
|
|
70
|
+
return !f.startsWith('dist/') && (f.endsWith('.js') || f.endsWith('.ts'));
|
|
71
|
+
});
|
|
72
|
+
var packageFiles = ['src/package.ts', 'src/detectors.ts', 'src/package.js', 'src/detectors.js', 'src/package-test.ts', 'src/package-test.js', 'package.js', 'detectors.js'];
|
|
73
|
+
var funcFiles = jsTsFiles.filter(function (f) {
|
|
74
|
+
return packageFiles.includes(f);
|
|
61
75
|
});
|
|
62
76
|
|
|
63
|
-
var
|
|
64
|
-
|
|
77
|
+
var webpackConfigPath = _path["default"].join(packagePath, 'webpack.config.js');
|
|
78
|
+
|
|
79
|
+
var isWebpack = _fs["default"].existsSync(webpackConfigPath);
|
|
80
|
+
|
|
81
|
+
if (isWebpack) {
|
|
82
|
+
var content = _fs["default"].readFileSync(webpackConfigPath, {
|
|
83
|
+
encoding: 'utf-8'
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
var externals = extractExternals(content);
|
|
87
|
+
if (externals) checkImportStatements(packagePath, jsTsFiles, externals).forEach(function (warning) {
|
|
88
|
+
return color.warn(warning);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
checkFuncSignatures(packagePath, funcFiles).forEach(function (warning) {
|
|
65
93
|
return color.warn(warning);
|
|
66
94
|
});
|
|
67
95
|
}
|
|
68
96
|
|
|
69
|
-
checkFuncSignatures(funcFiles).forEach(function (warning) {
|
|
70
|
-
return color.warn(warning);
|
|
71
|
-
});
|
|
72
97
|
return true;
|
|
73
98
|
}
|
|
74
99
|
|
|
@@ -91,7 +116,7 @@ function extractExternals(config) {
|
|
|
91
116
|
return null;
|
|
92
117
|
}
|
|
93
118
|
|
|
94
|
-
function checkImportStatements(files, externals) {
|
|
119
|
+
function checkImportStatements(packagePath, files, externals) {
|
|
95
120
|
var modules = [];
|
|
96
121
|
|
|
97
122
|
for (var key in externals) {
|
|
@@ -119,7 +144,7 @@ function checkImportStatements(files, externals) {
|
|
|
119
144
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
120
145
|
var file = _step.value;
|
|
121
146
|
|
|
122
|
-
var content = _fs["default"].readFileSync(_path["default"].join(
|
|
147
|
+
var content = _fs["default"].readFileSync(_path["default"].join(packagePath, file), {
|
|
123
148
|
encoding: 'utf-8'
|
|
124
149
|
});
|
|
125
150
|
|
|
@@ -151,7 +176,7 @@ function checkImportStatements(files, externals) {
|
|
|
151
176
|
return warnings;
|
|
152
177
|
}
|
|
153
178
|
|
|
154
|
-
function checkFuncSignatures(files) {
|
|
179
|
+
function checkFuncSignatures(packagePath, files) {
|
|
155
180
|
var warnings = [];
|
|
156
181
|
var checkFunctions = {
|
|
157
182
|
semTypeDetector: function semTypeDetector(_ref) {
|
|
@@ -162,12 +187,12 @@ function checkFuncSignatures(files) {
|
|
|
162
187
|
|
|
163
188
|
if (inputs.length !== 1 || inputs[0].type !== 'column') {
|
|
164
189
|
value = false;
|
|
165
|
-
message += 'Semantic type detectors must have one input of type "column"';
|
|
190
|
+
message += 'Semantic type detectors must have one input of type "column"\n';
|
|
166
191
|
}
|
|
167
192
|
|
|
168
193
|
if (outputs.length !== 1 || outputs[0].type !== 'string') {
|
|
169
194
|
value = false;
|
|
170
|
-
message += 'Semantic type detectors must have one output of type "string"';
|
|
195
|
+
message += 'Semantic type detectors must have one output of type "string"\n';
|
|
171
196
|
}
|
|
172
197
|
|
|
173
198
|
return {
|
|
@@ -183,12 +208,12 @@ function checkFuncSignatures(files) {
|
|
|
183
208
|
|
|
184
209
|
if (inputs.length !== 0) {
|
|
185
210
|
value = false;
|
|
186
|
-
message += 'Cell renderer functions should take no arguments';
|
|
211
|
+
message += 'Cell renderer functions should take no arguments\n';
|
|
187
212
|
}
|
|
188
213
|
|
|
189
214
|
if (outputs.length !== 1 || outputs[0].type !== 'grid_cell_renderer') {
|
|
190
215
|
value = false;
|
|
191
|
-
message += 'Cell renderer functions must have one output of type "grid_cell_renderer"';
|
|
216
|
+
message += 'Cell renderer functions must have one output of type "grid_cell_renderer"\n';
|
|
192
217
|
}
|
|
193
218
|
|
|
194
219
|
return {
|
|
@@ -207,17 +232,17 @@ function checkFuncSignatures(files) {
|
|
|
207
232
|
return t.startsWith('fileViewer');
|
|
208
233
|
}).length < 2) {
|
|
209
234
|
value = false;
|
|
210
|
-
message += 'File viewers must have at least two special tags: "fileViewer" and "fileViewer-<extension>"';
|
|
235
|
+
message += 'File viewers must have at least two special tags: "fileViewer" and "fileViewer-<extension>"\n';
|
|
211
236
|
}
|
|
212
237
|
|
|
213
238
|
if (inputs.length !== 1 || inputs[0].type !== 'file') {
|
|
214
239
|
value = false;
|
|
215
|
-
message += 'File viewers must have one input of type "file"';
|
|
240
|
+
message += 'File viewers must have one input of type "file"\n';
|
|
216
241
|
}
|
|
217
242
|
|
|
218
243
|
if (outputs.length !== 1 || outputs[0].type !== 'view') {
|
|
219
244
|
value = false;
|
|
220
|
-
message += 'File viewers must have one output of type "view"';
|
|
245
|
+
message += 'File viewers must have one output of type "view"\n';
|
|
221
246
|
}
|
|
222
247
|
|
|
223
248
|
return {
|
|
@@ -232,7 +257,7 @@ function checkFuncSignatures(files) {
|
|
|
232
257
|
|
|
233
258
|
if (description == null || description === '') {
|
|
234
259
|
value = false;
|
|
235
|
-
message += 'File exporters should have a description parameter';
|
|
260
|
+
message += 'File exporters should have a description parameter\n';
|
|
236
261
|
}
|
|
237
262
|
|
|
238
263
|
return {
|
|
@@ -247,7 +272,7 @@ function checkFuncSignatures(files) {
|
|
|
247
272
|
|
|
248
273
|
if (outputs.length === 1 && outputs[0].type === 'widget') {
|
|
249
274
|
value = false;
|
|
250
|
-
message += 'Package settings editors must have one output of type "widget"';
|
|
275
|
+
message += 'Package settings editors must have one output of type "widget"\n';
|
|
251
276
|
}
|
|
252
277
|
|
|
253
278
|
return {
|
|
@@ -265,7 +290,7 @@ function checkFuncSignatures(files) {
|
|
|
265
290
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
266
291
|
var file = _step3.value;
|
|
267
292
|
|
|
268
|
-
var content = _fs["default"].readFileSync(_path["default"].join(
|
|
293
|
+
var content = _fs["default"].readFileSync(_path["default"].join(packagePath, file), {
|
|
269
294
|
encoding: 'utf-8'
|
|
270
295
|
});
|
|
271
296
|
|
package/bin/commands/help.js
CHANGED
|
@@ -10,7 +10,7 @@ var HELP_API = "\nUsage: grok api\n\nCreate wrapper functions for package script
|
|
|
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";
|
|
12
12
|
var HELP_PUBLISH = "\nUsage: grok publish [host]\n\nUpload a package\n\nOptions:\n[--build|--rebuild] [--debug|--release] [--key] [--suffix]\n\nRunning `grok publish` is the same as running `grok publish defaultHost --build --debug`\n";
|
|
13
|
-
var HELP_CHECK = "\nUsage: grok check\n\nCheck package content (function signatures, import statements of external modules, etc.)\n";
|
|
13
|
+
var HELP_CHECK = "\nUsage: grok check\n\nOptions:\n[--dir]\n\n--dir Check all packages in a specified directory\n\nCheck package content (function signatures, import statements of external modules, etc.)\n";
|
|
14
14
|
var HELP_MIGRATE = "\nUsage: grok migrate\n\nSwitch to `grok` tools by copying your keys to the config\nfile and converting your scripts in the `package.json` file\n";
|
|
15
15
|
var help = {
|
|
16
16
|
add: HELP_ADD,
|
package/bin/commands/publish.js
CHANGED
|
@@ -28,6 +28,8 @@ var _ignoreWalk = _interopRequireDefault(require("ignore-walk"));
|
|
|
28
28
|
|
|
29
29
|
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
30
30
|
|
|
31
|
+
var _check = require("./check");
|
|
32
|
+
|
|
31
33
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
32
34
|
|
|
33
35
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
@@ -52,13 +54,15 @@ var curDir = process.cwd();
|
|
|
52
54
|
|
|
53
55
|
var packDir = _path["default"].join(curDir, 'package.json');
|
|
54
56
|
|
|
57
|
+
var packageFiles = ['src/package.ts', 'src/detectors.ts', 'src/package.js', 'src/detectors.js', 'src/package-test.ts', 'src/package-test.js', 'package.js', 'detectors.js'];
|
|
58
|
+
|
|
55
59
|
function processPackage(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
56
60
|
return _processPackage.apply(this, arguments);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
function _processPackage() {
|
|
60
64
|
_processPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(debug, rebuild, host, devKey, packageName, suffix) {
|
|
61
|
-
var timestamps, url, zip, localTimestamps, files, isWebpack, distFiles, contentValidationLog, uploadPromise, log;
|
|
65
|
+
var timestamps, url, zip, localTimestamps, files, isWebpack, distFiles, contentValidationLog, checkStart, jsTsFiles, webpackConfigPath, content, externals, importWarnings, funcFiles, funcWarnings, uploadPromise, log;
|
|
62
66
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
63
67
|
while (1) {
|
|
64
68
|
switch (_context3.prev = _context3.next) {
|
|
@@ -151,6 +155,31 @@ function _processPackage() {
|
|
|
151
155
|
|
|
152
156
|
case 34:
|
|
153
157
|
contentValidationLog = '';
|
|
158
|
+
console.log('Starting package checks...');
|
|
159
|
+
checkStart = Date.now();
|
|
160
|
+
jsTsFiles = files.filter(function (f) {
|
|
161
|
+
return !f.startsWith('dist/') && (f.endsWith('.js') || f.endsWith('.ts'));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (isWebpack) {
|
|
165
|
+
webpackConfigPath = _path["default"].join(curDir, 'webpack.config.js');
|
|
166
|
+
content = _fs["default"].readFileSync(webpackConfigPath, {
|
|
167
|
+
encoding: 'utf-8'
|
|
168
|
+
});
|
|
169
|
+
externals = (0, _check.extractExternals)(content);
|
|
170
|
+
|
|
171
|
+
if (externals) {
|
|
172
|
+
importWarnings = (0, _check.checkImportStatements)(curDir, jsTsFiles, externals);
|
|
173
|
+
contentValidationLog += importWarnings.join('\n') + (importWarnings.length ? '\n' : '');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
funcFiles = jsTsFiles.filter(function (f) {
|
|
178
|
+
return packageFiles.includes(f);
|
|
179
|
+
});
|
|
180
|
+
funcWarnings = (0, _check.checkFuncSignatures)(curDir, funcFiles);
|
|
181
|
+
contentValidationLog += funcWarnings.join('\n') + (funcWarnings.length ? '\n' : '');
|
|
182
|
+
console.log("Checks finished in ".concat(Date.now() - checkStart, " ms"));
|
|
154
183
|
files.forEach(function (file) {
|
|
155
184
|
var fullPath = file;
|
|
156
185
|
|
|
@@ -236,21 +265,21 @@ function _processPackage() {
|
|
|
236
265
|
})["catch"](function (error) {
|
|
237
266
|
console.error(error);
|
|
238
267
|
});
|
|
239
|
-
_context3.next =
|
|
268
|
+
_context3.next = 50;
|
|
240
269
|
return zip.finalize();
|
|
241
270
|
|
|
242
|
-
case
|
|
243
|
-
_context3.prev =
|
|
244
|
-
_context3.next =
|
|
271
|
+
case 50:
|
|
272
|
+
_context3.prev = 50;
|
|
273
|
+
_context3.next = 53;
|
|
245
274
|
return uploadPromise;
|
|
246
275
|
|
|
247
|
-
case
|
|
276
|
+
case 53:
|
|
248
277
|
log = _context3.sent;
|
|
249
278
|
|
|
250
279
|
_fs["default"].unlinkSync('zip');
|
|
251
280
|
|
|
252
281
|
if (!(log['#type'] === 'ApiError')) {
|
|
253
|
-
_context3.next =
|
|
282
|
+
_context3.next = 61;
|
|
254
283
|
break;
|
|
255
284
|
}
|
|
256
285
|
|
|
@@ -258,29 +287,29 @@ function _processPackage() {
|
|
|
258
287
|
console.error(log['innerMessage']);
|
|
259
288
|
return _context3.abrupt("return", 1);
|
|
260
289
|
|
|
261
|
-
case
|
|
290
|
+
case 61:
|
|
262
291
|
console.log(log);
|
|
263
292
|
color.warn(contentValidationLog);
|
|
264
293
|
|
|
265
|
-
case
|
|
266
|
-
_context3.next =
|
|
294
|
+
case 63:
|
|
295
|
+
_context3.next = 69;
|
|
267
296
|
break;
|
|
268
297
|
|
|
269
|
-
case
|
|
270
|
-
_context3.prev =
|
|
271
|
-
_context3.t1 = _context3["catch"](
|
|
298
|
+
case 65:
|
|
299
|
+
_context3.prev = 65;
|
|
300
|
+
_context3.t1 = _context3["catch"](50);
|
|
272
301
|
console.error(_context3.t1);
|
|
273
302
|
return _context3.abrupt("return", 1);
|
|
274
303
|
|
|
275
|
-
case
|
|
304
|
+
case 69:
|
|
276
305
|
return _context3.abrupt("return", 0);
|
|
277
306
|
|
|
278
|
-
case
|
|
307
|
+
case 70:
|
|
279
308
|
case "end":
|
|
280
309
|
return _context3.stop();
|
|
281
310
|
}
|
|
282
311
|
}
|
|
283
|
-
}, _callee3, null, [[3, 14], [
|
|
312
|
+
}, _callee3, null, [[3, 14], [50, 65]]);
|
|
284
313
|
}));
|
|
285
314
|
return _processPackage.apply(this, arguments);
|
|
286
315
|
}
|
|
@@ -294,7 +323,7 @@ function publish(args) {
|
|
|
294
323
|
})) return false;
|
|
295
324
|
|
|
296
325
|
if (args.build && args.rebuild) {
|
|
297
|
-
color.error('Incompatible options: --build and');
|
|
326
|
+
color.error('Incompatible options: --build and --rebuild');
|
|
298
327
|
return false;
|
|
299
328
|
}
|
|
300
329
|
|
package/package.json
CHANGED