datagrok-tools 4.8.4 → 4.10.0
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/README.md +1 -1
- package/bin/commands/add.js +48 -140
- package/bin/commands/api.js +5 -61
- package/bin/commands/check.js +43 -154
- package/bin/commands/config.js +0 -60
- package/bin/commands/create.js +11 -71
- package/bin/commands/help.js +2 -4
- package/bin/commands/init.js +2 -81
- package/bin/commands/link.js +127 -172
- package/bin/commands/publish.js +14 -87
- package/bin/commands/test.js +2 -57
- package/bin/grok.js +0 -1
- package/bin/utils/color-utils.js +0 -6
- package/bin/utils/ent-helpers.js +2 -13
- package/bin/utils/func-generation.js +189 -0
- package/bin/utils/test-utils.js +7 -61
- package/bin/utils/utils.js +1 -48
- package/bin/validators/config-validator.js +2 -15
- package/package-template/.eslintrc.json +1 -1
- package/package-template/ts.webpack.config.js +4 -0
- package/package-template/tsconfig.json +3 -3
- package/package.json +6 -3
- package/plugins/func-gen-plugin.js +144 -0
- package/tsconfig.json +2 -2
- package/bin/validators/interfaces.js +0 -1
package/bin/commands/publish.js
CHANGED
|
@@ -1,65 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.processPackage = processPackage;
|
|
11
9
|
exports.publish = publish;
|
|
12
|
-
|
|
13
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
|
-
|
|
15
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
|
-
|
|
17
12
|
var _archiverPromise = _interopRequireDefault(require("archiver-promise"));
|
|
18
|
-
|
|
19
13
|
var _fs = _interopRequireDefault(require("fs"));
|
|
20
|
-
|
|
21
14
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
22
|
-
|
|
23
15
|
var _os = _interopRequireDefault(require("os"));
|
|
24
|
-
|
|
25
16
|
var _path = _interopRequireDefault(require("path"));
|
|
26
|
-
|
|
27
17
|
var _ignoreWalk = _interopRequireDefault(require("ignore-walk"));
|
|
28
|
-
|
|
29
18
|
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
30
|
-
|
|
31
19
|
var _check = require("./check");
|
|
32
|
-
|
|
33
20
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
34
|
-
|
|
35
21
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
36
|
-
|
|
37
22
|
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); }
|
|
38
|
-
|
|
39
23
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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; }
|
|
40
|
-
|
|
41
24
|
// @ts-ignore
|
|
25
|
+
|
|
42
26
|
// @ts-ignore
|
|
43
|
-
var grokDir = _path["default"].join(_os["default"].homedir(), '.grok');
|
|
44
27
|
|
|
28
|
+
var grokDir = _path["default"].join(_os["default"].homedir(), '.grok');
|
|
45
29
|
var confPath = _path["default"].join(grokDir, 'config.yaml');
|
|
46
|
-
|
|
47
30
|
var confTemplateDir = _path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'config-template.yaml');
|
|
48
|
-
|
|
49
31
|
var confTemplate = _jsYaml["default"].load(_fs["default"].readFileSync(confTemplateDir, {
|
|
50
32
|
encoding: 'utf-8'
|
|
51
33
|
}));
|
|
52
|
-
|
|
53
34
|
var curDir = process.cwd();
|
|
54
|
-
|
|
55
35
|
var packDir = _path["default"].join(curDir, 'package.json');
|
|
56
|
-
|
|
57
36
|
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
|
-
|
|
59
37
|
function processPackage(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
60
38
|
return _processPackage.apply(this, arguments);
|
|
61
39
|
}
|
|
62
|
-
|
|
63
40
|
function _processPackage() {
|
|
64
41
|
_processPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(debug, rebuild, host, devKey, packageName, suffix) {
|
|
65
42
|
var timestamps, url, zip, localTimestamps, files, isWebpack, distFiles, contentValidationLog, checkStart, jsTsFiles, webpackConfigPath, content, externals, importWarnings, funcFiles, funcWarnings, packageWarnings, uploadPromise, log;
|
|
@@ -70,46 +47,36 @@ function _processPackage() {
|
|
|
70
47
|
// Get the server timestamps
|
|
71
48
|
timestamps = {};
|
|
72
49
|
url = "".concat(host, "/packages/dev/").concat(devKey, "/").concat(packageName);
|
|
73
|
-
|
|
74
50
|
if (!debug) {
|
|
75
51
|
_context3.next = 18;
|
|
76
52
|
break;
|
|
77
53
|
}
|
|
78
|
-
|
|
79
54
|
_context3.prev = 3;
|
|
80
55
|
_context3.next = 6;
|
|
81
56
|
return (0, _nodeFetch["default"])(url + '/timestamps');
|
|
82
|
-
|
|
83
57
|
case 6:
|
|
84
58
|
_context3.next = 8;
|
|
85
59
|
return _context3.sent.json();
|
|
86
|
-
|
|
87
60
|
case 8:
|
|
88
61
|
timestamps = _context3.sent;
|
|
89
|
-
|
|
90
62
|
if (!(timestamps['#type'] === 'ApiError')) {
|
|
91
63
|
_context3.next = 12;
|
|
92
64
|
break;
|
|
93
65
|
}
|
|
94
|
-
|
|
95
66
|
color.error(timestamps.message);
|
|
96
67
|
return _context3.abrupt("return", 1);
|
|
97
|
-
|
|
98
68
|
case 12:
|
|
99
69
|
_context3.next = 18;
|
|
100
70
|
break;
|
|
101
|
-
|
|
102
71
|
case 14:
|
|
103
72
|
_context3.prev = 14;
|
|
104
73
|
_context3.t0 = _context3["catch"](3);
|
|
105
74
|
console.error(_context3.t0);
|
|
106
75
|
return _context3.abrupt("return", 1);
|
|
107
|
-
|
|
108
76
|
case 18:
|
|
109
77
|
zip = (0, _archiverPromise["default"])('zip', {
|
|
110
78
|
store: false
|
|
111
79
|
}); // Gather the files
|
|
112
|
-
|
|
113
80
|
localTimestamps = {};
|
|
114
81
|
_context3.next = 22;
|
|
115
82
|
return (0, _ignoreWalk["default"])({
|
|
@@ -118,21 +85,17 @@ function _processPackage() {
|
|
|
118
85
|
includeEmpty: false,
|
|
119
86
|
follow: true
|
|
120
87
|
});
|
|
121
|
-
|
|
122
88
|
case 22:
|
|
123
89
|
files = _context3.sent;
|
|
124
90
|
isWebpack = _fs["default"].existsSync('webpack.config.js');
|
|
125
|
-
|
|
126
91
|
if (!(!rebuild && isWebpack)) {
|
|
127
92
|
_context3.next = 34;
|
|
128
93
|
break;
|
|
129
94
|
}
|
|
130
|
-
|
|
131
95
|
if (!_fs["default"].existsSync('dist/package.js')) {
|
|
132
96
|
_context3.next = 32;
|
|
133
97
|
break;
|
|
134
98
|
}
|
|
135
|
-
|
|
136
99
|
_context3.next = 28;
|
|
137
100
|
return (0, _ignoreWalk["default"])({
|
|
138
101
|
path: './dist',
|
|
@@ -140,7 +103,6 @@ function _processPackage() {
|
|
|
140
103
|
includeEmpty: false,
|
|
141
104
|
follow: true
|
|
142
105
|
});
|
|
143
|
-
|
|
144
106
|
case 28:
|
|
145
107
|
distFiles = _context3.sent;
|
|
146
108
|
distFiles.forEach(function (df) {
|
|
@@ -148,11 +110,9 @@ function _processPackage() {
|
|
|
148
110
|
});
|
|
149
111
|
_context3.next = 34;
|
|
150
112
|
break;
|
|
151
|
-
|
|
152
113
|
case 32:
|
|
153
114
|
color.warn('File `dist/package.js` not found. Building the package on the server side...\n' + 'Next time, please build your package locally with Webpack beforehand\n' + 'or run `grok publish` with the `--rebuild` option');
|
|
154
115
|
rebuild = true;
|
|
155
|
-
|
|
156
116
|
case 34:
|
|
157
117
|
contentValidationLog = '';
|
|
158
118
|
console.log('Starting package checks...');
|
|
@@ -160,20 +120,17 @@ function _processPackage() {
|
|
|
160
120
|
jsTsFiles = files.filter(function (f) {
|
|
161
121
|
return !f.startsWith('dist/') && (f.endsWith('.js') || f.endsWith('.ts'));
|
|
162
122
|
});
|
|
163
|
-
|
|
164
123
|
if (isWebpack) {
|
|
165
124
|
webpackConfigPath = _path["default"].join(curDir, 'webpack.config.js');
|
|
166
125
|
content = _fs["default"].readFileSync(webpackConfigPath, {
|
|
167
126
|
encoding: 'utf-8'
|
|
168
127
|
});
|
|
169
128
|
externals = (0, _check.extractExternals)(content);
|
|
170
|
-
|
|
171
129
|
if (externals) {
|
|
172
130
|
importWarnings = (0, _check.checkImportStatements)(curDir, jsTsFiles, externals);
|
|
173
131
|
contentValidationLog += importWarnings.join('\n') + (importWarnings.length ? '\n' : '');
|
|
174
132
|
}
|
|
175
133
|
}
|
|
176
|
-
|
|
177
134
|
funcFiles = jsTsFiles.filter(function (f) {
|
|
178
135
|
return packageFiles.includes(f);
|
|
179
136
|
});
|
|
@@ -184,35 +141,26 @@ function _processPackage() {
|
|
|
184
141
|
console.log("Checks finished in ".concat(Date.now() - checkStart, " ms"));
|
|
185
142
|
files.forEach(function (file) {
|
|
186
143
|
var fullPath = file;
|
|
187
|
-
|
|
188
144
|
var relativePath = _path["default"].relative(curDir, fullPath);
|
|
189
|
-
|
|
190
145
|
var canonicalRelativePath = relativePath.replace(/\\/g, '/');
|
|
191
146
|
if (canonicalRelativePath.includes('/.')) return;
|
|
192
147
|
if (canonicalRelativePath.startsWith('.')) return;
|
|
193
148
|
if (relativePath.startsWith('node_modules')) return;
|
|
194
149
|
if (relativePath.startsWith('dist') && rebuild) return;
|
|
195
|
-
|
|
196
150
|
if (relativePath.startsWith('src') && !rebuild && isWebpack) {
|
|
197
151
|
if (!relativePath.startsWith('src/package') && !relativePath.startsWith('src\\package')) return;
|
|
198
152
|
}
|
|
199
|
-
|
|
200
153
|
if (relativePath.startsWith('upload.keys.json')) return;
|
|
201
154
|
if (relativePath === 'zip') return;
|
|
202
|
-
|
|
203
155
|
if (!utils.checkScriptLocation(canonicalRelativePath)) {
|
|
204
156
|
contentValidationLog += "Warning: file `".concat(canonicalRelativePath, "`") + " should be in directory `".concat(_path["default"].basename(curDir), "/scripts/`\n");
|
|
205
157
|
}
|
|
206
|
-
|
|
207
158
|
var t = _fs["default"].statSync(fullPath).mtime.toUTCString();
|
|
208
|
-
|
|
209
159
|
localTimestamps[canonicalRelativePath] = t;
|
|
210
|
-
|
|
211
160
|
if (debug && timestamps[canonicalRelativePath] === t) {
|
|
212
161
|
console.log("Skipping ".concat(canonicalRelativePath));
|
|
213
162
|
return;
|
|
214
163
|
}
|
|
215
|
-
|
|
216
164
|
zip.append(_fs["default"].createReadStream(fullPath), {
|
|
217
165
|
name: relativePath
|
|
218
166
|
});
|
|
@@ -220,8 +168,9 @@ function _processPackage() {
|
|
|
220
168
|
});
|
|
221
169
|
zip.append(JSON.stringify(localTimestamps), {
|
|
222
170
|
name: 'timestamps.json'
|
|
223
|
-
});
|
|
171
|
+
});
|
|
224
172
|
|
|
173
|
+
// Upload
|
|
225
174
|
url += "?debug=".concat(debug.toString(), "&rebuild=").concat(rebuild.toString());
|
|
226
175
|
if (suffix) url += "&suffix=".concat(suffix.toString());
|
|
227
176
|
uploadPromise = new Promise(function (resolve, reject) {
|
|
@@ -238,16 +187,13 @@ function _processPackage() {
|
|
|
238
187
|
_context2.prev = 0;
|
|
239
188
|
_context2.next = 3;
|
|
240
189
|
return body.text();
|
|
241
|
-
|
|
242
190
|
case 3:
|
|
243
191
|
response = _context2.sent;
|
|
244
192
|
return _context2.abrupt("return", JSON.parse(response));
|
|
245
|
-
|
|
246
193
|
case 7:
|
|
247
194
|
_context2.prev = 7;
|
|
248
195
|
_context2.t0 = _context2["catch"](0);
|
|
249
196
|
console.error(response);
|
|
250
|
-
|
|
251
197
|
case 10:
|
|
252
198
|
case "end":
|
|
253
199
|
return _context2.stop();
|
|
@@ -255,7 +201,6 @@ function _processPackage() {
|
|
|
255
201
|
}
|
|
256
202
|
}, _callee2, null, [[0, 7]]);
|
|
257
203
|
}));
|
|
258
|
-
|
|
259
204
|
return function (_x7) {
|
|
260
205
|
return _ref2.apply(this, arguments);
|
|
261
206
|
};
|
|
@@ -269,43 +214,33 @@ function _processPackage() {
|
|
|
269
214
|
});
|
|
270
215
|
_context3.next = 52;
|
|
271
216
|
return zip.finalize();
|
|
272
|
-
|
|
273
217
|
case 52:
|
|
274
218
|
_context3.prev = 52;
|
|
275
219
|
_context3.next = 55;
|
|
276
220
|
return uploadPromise;
|
|
277
|
-
|
|
278
221
|
case 55:
|
|
279
222
|
log = _context3.sent;
|
|
280
|
-
|
|
281
223
|
_fs["default"].unlinkSync('zip');
|
|
282
|
-
|
|
283
224
|
if (!(log['#type'] === 'ApiError')) {
|
|
284
225
|
_context3.next = 63;
|
|
285
226
|
break;
|
|
286
227
|
}
|
|
287
|
-
|
|
288
228
|
color.error(log['message']);
|
|
289
229
|
console.error(log['innerMessage']);
|
|
290
230
|
return _context3.abrupt("return", 1);
|
|
291
|
-
|
|
292
231
|
case 63:
|
|
293
232
|
console.log(log);
|
|
294
233
|
color.warn(contentValidationLog);
|
|
295
|
-
|
|
296
234
|
case 65:
|
|
297
235
|
_context3.next = 71;
|
|
298
236
|
break;
|
|
299
|
-
|
|
300
237
|
case 67:
|
|
301
238
|
_context3.prev = 67;
|
|
302
239
|
_context3.t1 = _context3["catch"](52);
|
|
303
240
|
console.error(_context3.t1);
|
|
304
241
|
return _context3.abrupt("return", 1);
|
|
305
|
-
|
|
306
242
|
case 71:
|
|
307
243
|
return _context3.abrupt("return", 0);
|
|
308
|
-
|
|
309
244
|
case 72:
|
|
310
245
|
case "end":
|
|
311
246
|
return _context3.stop();
|
|
@@ -315,7 +250,6 @@ function _processPackage() {
|
|
|
315
250
|
}));
|
|
316
251
|
return _processPackage.apply(this, arguments);
|
|
317
252
|
}
|
|
318
|
-
|
|
319
253
|
function publish(args) {
|
|
320
254
|
var nOptions = Object.keys(args).length - 1;
|
|
321
255
|
var nArgs = args['_'].length;
|
|
@@ -323,31 +257,28 @@ function publish(args) {
|
|
|
323
257
|
if (!Object.keys(args).slice(1).every(function (option) {
|
|
324
258
|
return ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option);
|
|
325
259
|
})) return false;
|
|
326
|
-
|
|
327
260
|
if (args.build && args.rebuild) {
|
|
328
261
|
color.error('Incompatible options: --build and --rebuild');
|
|
329
262
|
return false;
|
|
330
263
|
}
|
|
331
|
-
|
|
332
264
|
if (args.debug && args.release) {
|
|
333
265
|
color.error('Incompatible options: --debug and --release');
|
|
334
266
|
return false;
|
|
335
|
-
}
|
|
336
|
-
|
|
267
|
+
}
|
|
337
268
|
|
|
269
|
+
// Create `config.yaml` if it doesn't exist yet
|
|
338
270
|
if (!_fs["default"].existsSync(grokDir)) _fs["default"].mkdirSync(grokDir);
|
|
339
271
|
if (!_fs["default"].existsSync(confPath)) _fs["default"].writeFileSync(confPath, _jsYaml["default"].dump(confTemplate));
|
|
340
|
-
|
|
341
272
|
var config = _jsYaml["default"].load(_fs["default"].readFileSync(confPath, {
|
|
342
273
|
encoding: 'utf-8'
|
|
343
274
|
}));
|
|
344
|
-
|
|
345
275
|
var host = config["default"];
|
|
346
276
|
var urls = utils.mapURL(config);
|
|
347
277
|
if (nArgs === 2) host = args['_'][1];
|
|
348
278
|
var key = '';
|
|
349
|
-
var url = '';
|
|
279
|
+
var url = '';
|
|
350
280
|
|
|
281
|
+
// The host can be passed either as a URL or an alias
|
|
351
282
|
try {
|
|
352
283
|
url = new URL(host).href;
|
|
353
284
|
if (url.endsWith('/')) url = url.slice(0, -1);
|
|
@@ -356,20 +287,20 @@ function publish(args) {
|
|
|
356
287
|
if (!(host in config.servers)) return color.error("Unknown server alias. Please add it to ".concat(confPath));
|
|
357
288
|
url = config['servers'][host]['url'];
|
|
358
289
|
key = config['servers'][host]['key'];
|
|
359
|
-
}
|
|
360
|
-
|
|
290
|
+
}
|
|
361
291
|
|
|
292
|
+
// Update the developer key
|
|
362
293
|
if (args.key) key = args.key;
|
|
363
|
-
if (key === '') return color.warn('Please provide the key with `--key` option or add it by running `grok config`');
|
|
294
|
+
if (key === '') return color.warn('Please provide the key with `--key` option or add it by running `grok config`');
|
|
364
295
|
|
|
296
|
+
// Get the package name
|
|
365
297
|
if (!_fs["default"].existsSync(packDir)) return color.error('`package.json` doesn\'t exist');
|
|
366
|
-
|
|
367
298
|
var _package = JSON.parse(_fs["default"].readFileSync(packDir, {
|
|
368
299
|
encoding: 'utf-8'
|
|
369
300
|
}));
|
|
301
|
+
var packageName = _package.name;
|
|
370
302
|
|
|
371
|
-
|
|
372
|
-
|
|
303
|
+
// Upload the package
|
|
373
304
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
374
305
|
process.on('beforeExit', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
375
306
|
var code;
|
|
@@ -381,22 +312,18 @@ function publish(args) {
|
|
|
381
312
|
_context.prev = 1;
|
|
382
313
|
_context.next = 4;
|
|
383
314
|
return processPackage(!args.release, Boolean(args.rebuild), url, key, packageName, args.suffix);
|
|
384
|
-
|
|
385
315
|
case 4:
|
|
386
316
|
code = _context.sent;
|
|
387
317
|
_context.next = 11;
|
|
388
318
|
break;
|
|
389
|
-
|
|
390
319
|
case 7:
|
|
391
320
|
_context.prev = 7;
|
|
392
321
|
_context.t0 = _context["catch"](1);
|
|
393
322
|
console.error(_context.t0);
|
|
394
323
|
code = 1;
|
|
395
|
-
|
|
396
324
|
case 11:
|
|
397
325
|
console.log("Exiting with code ".concat(code));
|
|
398
326
|
process.exit(code);
|
|
399
|
-
|
|
400
327
|
case 13:
|
|
401
328
|
case "end":
|
|
402
329
|
return _context.stop();
|
package/bin/commands/test.js
CHANGED
|
@@ -1,68 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.test = test;
|
|
11
|
-
|
|
12
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
-
|
|
14
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
11
|
var _child_process = require("child_process");
|
|
17
|
-
|
|
18
12
|
var _fs = _interopRequireDefault(require("fs"));
|
|
19
|
-
|
|
20
13
|
var _os = _interopRequireDefault(require("os"));
|
|
21
|
-
|
|
22
14
|
var _path = _interopRequireDefault(require("path"));
|
|
23
|
-
|
|
24
15
|
var _puppeteer = _interopRequireDefault(require("puppeteer"));
|
|
25
|
-
|
|
26
16
|
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
27
|
-
|
|
28
17
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
29
|
-
|
|
30
18
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
31
|
-
|
|
32
19
|
var testUtils = _interopRequireWildcard(require("../utils/test-utils"));
|
|
33
|
-
|
|
34
20
|
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); }
|
|
35
|
-
|
|
36
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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; }
|
|
37
|
-
|
|
38
22
|
function test(args) {
|
|
39
23
|
var options = Object.keys(args).slice(1);
|
|
40
24
|
var commandOptions = ['host', 'csv', 'gui', 'skip-build', 'skip-publish'];
|
|
41
25
|
var nArgs = args['_'].length;
|
|
42
26
|
var curDir = process.cwd();
|
|
43
|
-
|
|
44
27
|
var grokDir = _path["default"].join(_os["default"].homedir(), '.grok');
|
|
45
|
-
|
|
46
28
|
var confPath = _path["default"].join(grokDir, 'config.yaml');
|
|
47
|
-
|
|
48
29
|
if (nArgs > 1 || options.length > commandOptions.length || options.length > 0 && !options.every(function (op) {
|
|
49
30
|
return commandOptions.includes(op);
|
|
50
31
|
})) return false;
|
|
51
|
-
|
|
52
32
|
if (!utils.isPackageDir(curDir)) {
|
|
53
33
|
color.error('File `package.json` not found. Run the command from the package directory');
|
|
54
34
|
return false;
|
|
55
35
|
}
|
|
56
|
-
|
|
57
36
|
if (!_fs["default"].existsSync(confPath)) {
|
|
58
37
|
color.error("File `".concat(confPath, "` not found. Run `grok config` to set up the config file"));
|
|
59
38
|
return false;
|
|
60
39
|
}
|
|
61
|
-
|
|
62
40
|
var config = _jsYaml["default"].load(_fs["default"].readFileSync(confPath, {
|
|
63
41
|
encoding: 'utf-8'
|
|
64
42
|
}));
|
|
65
|
-
|
|
66
43
|
if (args.host) {
|
|
67
44
|
if (args.host in config.servers) {
|
|
68
45
|
process.env.HOST = args.host;
|
|
@@ -75,11 +52,9 @@ function test(args) {
|
|
|
75
52
|
process.env.HOST = config["default"];
|
|
76
53
|
console.log('Environment variable `HOST` is set to', config["default"]);
|
|
77
54
|
}
|
|
78
|
-
|
|
79
55
|
var packageData = JSON.parse(_fs["default"].readFileSync(_path["default"].join(curDir, 'package.json'), {
|
|
80
56
|
encoding: 'utf-8'
|
|
81
57
|
}));
|
|
82
|
-
|
|
83
58
|
if (packageData.name) {
|
|
84
59
|
process.env.TARGET_PACKAGE = utils.kebabToCamelCase(utils.removeScope(packageData.name));
|
|
85
60
|
console.log('Environment variable `TARGET_PACKAGE` is set to', process.env.TARGET_PACKAGE);
|
|
@@ -87,7 +62,6 @@ function test(args) {
|
|
|
87
62
|
color.error('Invalid package name. Set the `name` field in `package.json`');
|
|
88
63
|
return false;
|
|
89
64
|
}
|
|
90
|
-
|
|
91
65
|
if (args['skip-build']) {
|
|
92
66
|
if (args['skip-publish']) test();else publish(test);
|
|
93
67
|
} else {
|
|
@@ -95,11 +69,9 @@ function test(args) {
|
|
|
95
69
|
return publish(test);
|
|
96
70
|
});
|
|
97
71
|
}
|
|
98
|
-
|
|
99
72
|
function build(callback) {
|
|
100
73
|
(0, _child_process.exec)('npm run build', function (err, stdout, stderr) {
|
|
101
74
|
color.info("Building package...");
|
|
102
|
-
|
|
103
75
|
if (err) {
|
|
104
76
|
console.log(stdout);
|
|
105
77
|
throw err;
|
|
@@ -107,11 +79,9 @@ function test(args) {
|
|
|
107
79
|
console.log(stdout);
|
|
108
80
|
color.warn(stderr);
|
|
109
81
|
}
|
|
110
|
-
|
|
111
82
|
callback();
|
|
112
83
|
});
|
|
113
84
|
}
|
|
114
|
-
|
|
115
85
|
function publish(callback) {
|
|
116
86
|
(0, _child_process.exec)("grok publish ".concat(process.platform === 'win32' ? '%HOST%' : '${HOST}'), function (err, stdout, stderr) {
|
|
117
87
|
color.info("Publishing package \"".concat(process.env.TARGET_PACKAGE, "\" to ").concat(process.env.HOST, "..."));
|
|
@@ -122,13 +92,11 @@ function test(args) {
|
|
|
122
92
|
callback();
|
|
123
93
|
});
|
|
124
94
|
}
|
|
125
|
-
|
|
126
95
|
function test() {
|
|
127
96
|
color.info('Starting tests...');
|
|
128
97
|
var P_START_TIMEOUT = 3600000;
|
|
129
98
|
var browser;
|
|
130
99
|
var page;
|
|
131
|
-
|
|
132
100
|
function init(timeout) {
|
|
133
101
|
var params = Object.assign({}, testUtils.defaultLaunchParameters);
|
|
134
102
|
if (args.gui) params['headless'] = false;
|
|
@@ -141,19 +109,16 @@ function test(args) {
|
|
|
141
109
|
_context.prev = 0;
|
|
142
110
|
_context.next = 3;
|
|
143
111
|
return testUtils.getBrowserPage(_puppeteer["default"], params);
|
|
144
|
-
|
|
145
112
|
case 3:
|
|
146
113
|
out = _context.sent;
|
|
147
114
|
browser = out.browser;
|
|
148
115
|
page = out.page;
|
|
149
116
|
_context.next = 11;
|
|
150
117
|
break;
|
|
151
|
-
|
|
152
118
|
case 8:
|
|
153
119
|
_context.prev = 8;
|
|
154
120
|
_context.t0 = _context["catch"](0);
|
|
155
121
|
throw _context.t0;
|
|
156
|
-
|
|
157
122
|
case 11:
|
|
158
123
|
case "end":
|
|
159
124
|
return _context.stop();
|
|
@@ -162,11 +127,9 @@ function test(args) {
|
|
|
162
127
|
}, _callee, null, [[0, 8]]);
|
|
163
128
|
})));
|
|
164
129
|
}
|
|
165
|
-
|
|
166
130
|
function runTest(timeout) {
|
|
167
131
|
return testUtils.runWithTimeout(timeout, /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
168
132
|
var _process$env$TARGET_P;
|
|
169
|
-
|
|
170
133
|
var targetPackage, r;
|
|
171
134
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
172
135
|
while (1) {
|
|
@@ -182,7 +145,6 @@ function test(args) {
|
|
|
182
145
|
var skipReport = '';
|
|
183
146
|
var passReport = '';
|
|
184
147
|
var failReport = '';
|
|
185
|
-
|
|
186
148
|
if (df == null) {
|
|
187
149
|
failed = true;
|
|
188
150
|
failReport = 'Fail reason: No package tests found';
|
|
@@ -193,14 +155,12 @@ function test(args) {
|
|
|
193
155
|
failed: failed
|
|
194
156
|
});
|
|
195
157
|
}
|
|
196
|
-
|
|
197
158
|
var cStatus = df.columns.byName('success');
|
|
198
159
|
var cSkipped = df.columns.byName('skipped');
|
|
199
160
|
var cMessage = df.columns.byName('result');
|
|
200
161
|
var cCat = df.columns.byName('category');
|
|
201
162
|
var cName = df.columns.byName('name');
|
|
202
163
|
var cTime = df.columns.byName('ms');
|
|
203
|
-
|
|
204
164
|
for (var i = 0; i < df.rowCount; i++) {
|
|
205
165
|
if (cStatus.get(i)) {
|
|
206
166
|
if (cSkipped.get(i)) {
|
|
@@ -213,7 +173,6 @@ function test(args) {
|
|
|
213
173
|
failReport += "Test result : Failed : ".concat(cTime.get(i), " : ").concat(targetPackage, ".").concat(cCat.get(i), ".").concat(cName.get(i), " : ").concat(cMessage.get(i), "\n");
|
|
214
174
|
}
|
|
215
175
|
}
|
|
216
|
-
|
|
217
176
|
var csv = df.toCsv();
|
|
218
177
|
resolve({
|
|
219
178
|
failReport: failReport,
|
|
@@ -227,11 +186,9 @@ function test(args) {
|
|
|
227
186
|
});
|
|
228
187
|
});
|
|
229
188
|
}, targetPackage);
|
|
230
|
-
|
|
231
189
|
case 4:
|
|
232
190
|
r = _context2.sent;
|
|
233
191
|
return _context2.abrupt("return", r);
|
|
234
|
-
|
|
235
192
|
case 6:
|
|
236
193
|
case "end":
|
|
237
194
|
return _context2.stop();
|
|
@@ -240,7 +197,6 @@ function test(args) {
|
|
|
240
197
|
}, _callee2);
|
|
241
198
|
})));
|
|
242
199
|
}
|
|
243
|
-
|
|
244
200
|
(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
245
201
|
var r;
|
|
246
202
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
@@ -250,34 +206,26 @@ function test(args) {
|
|
|
250
206
|
_context3.prev = 0;
|
|
251
207
|
_context3.next = 3;
|
|
252
208
|
return init(P_START_TIMEOUT);
|
|
253
|
-
|
|
254
209
|
case 3:
|
|
255
210
|
color.success('Initialization completed.');
|
|
256
211
|
_context3.next = 10;
|
|
257
212
|
break;
|
|
258
|
-
|
|
259
213
|
case 6:
|
|
260
214
|
_context3.prev = 6;
|
|
261
215
|
_context3.t0 = _context3["catch"](0);
|
|
262
216
|
color.error('Initialization failed.');
|
|
263
217
|
throw _context3.t0;
|
|
264
|
-
|
|
265
218
|
case 10:
|
|
266
219
|
_context3.next = 12;
|
|
267
220
|
return runTest(7200000);
|
|
268
|
-
|
|
269
221
|
case 12:
|
|
270
222
|
r = _context3.sent;
|
|
271
|
-
|
|
272
223
|
if (r.csv && args.csv) {
|
|
273
224
|
_fs["default"].writeFileSync(_path["default"].join(curDir, 'test-report.csv'), r.csv, 'utf8');
|
|
274
|
-
|
|
275
225
|
color.info('Saved `test-report.csv`\n');
|
|
276
226
|
}
|
|
277
|
-
|
|
278
227
|
if (r.passReport) console.log(r.passReport);
|
|
279
228
|
if (r.skipReport) console.log(r.skipReport);
|
|
280
|
-
|
|
281
229
|
if (r.failed) {
|
|
282
230
|
console.log(r.failReport);
|
|
283
231
|
color.fail('Tests failed.');
|
|
@@ -285,17 +233,15 @@ function test(args) {
|
|
|
285
233
|
} else {
|
|
286
234
|
color.success('Tests passed.');
|
|
287
235
|
testUtils.exitWithCode(0);
|
|
288
|
-
}
|
|
289
|
-
|
|
236
|
+
}
|
|
290
237
|
|
|
238
|
+
//@ts-ignore
|
|
291
239
|
if (!(browser != null)) {
|
|
292
240
|
_context3.next = 20;
|
|
293
241
|
break;
|
|
294
242
|
}
|
|
295
|
-
|
|
296
243
|
_context3.next = 20;
|
|
297
244
|
return browser.close();
|
|
298
|
-
|
|
299
245
|
case 20:
|
|
300
246
|
case "end":
|
|
301
247
|
return _context3.stop();
|
|
@@ -304,6 +250,5 @@ function test(args) {
|
|
|
304
250
|
}, _callee3, null, [[0, 6]]);
|
|
305
251
|
}))();
|
|
306
252
|
}
|
|
307
|
-
|
|
308
253
|
return true;
|
|
309
254
|
}
|
package/bin/grok.js
CHANGED
|
@@ -12,7 +12,6 @@ const commands = {
|
|
|
12
12
|
create: require('./commands/create').create,
|
|
13
13
|
init: require('./commands/init').init,
|
|
14
14
|
link: require('./commands/link').link,
|
|
15
|
-
unlink: require('./commands/link').unlink,
|
|
16
15
|
publish: require('./commands/publish').publish,
|
|
17
16
|
test: require('./commands/test').test,
|
|
18
17
|
};
|
package/bin/utils/color-utils.js
CHANGED
|
@@ -4,23 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.warn = exports.success = exports.info = exports.fail = exports.error = void 0;
|
|
7
|
-
|
|
8
7
|
var error = function error(s) {
|
|
9
8
|
return console.log('\x1b[31m%s\x1b[0m', s);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
10
|
exports.error = error;
|
|
13
|
-
|
|
14
11
|
var info = function info(s) {
|
|
15
12
|
return console.log('\x1b[32m%s\x1b[0m', s);
|
|
16
13
|
};
|
|
17
|
-
|
|
18
14
|
exports.info = info;
|
|
19
|
-
|
|
20
15
|
var warn = function warn(s) {
|
|
21
16
|
return console.log('\x1b[33m%s\x1b[0m', s);
|
|
22
17
|
};
|
|
23
|
-
|
|
24
18
|
exports.warn = warn;
|
|
25
19
|
var success = info;
|
|
26
20
|
exports.success = success;
|