datagrok-tools 4.4.1 → 4.4.4
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 +15 -13
- package/bin/commands/api.js +13 -7
- package/bin/commands/config.js +13 -5
- package/bin/commands/create.js +45 -8
- package/bin/commands/publish.js +36 -31
- package/bin/utils/color-utils.js +28 -0
- package/package.json +1 -1
package/bin/commands/add.js
CHANGED
|
@@ -17,6 +17,8 @@ var _entHelpers = require("../utils/ent-helpers");
|
|
|
17
17
|
|
|
18
18
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
19
19
|
|
|
20
|
+
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
21
|
+
|
|
20
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); }
|
|
21
23
|
|
|
22
24
|
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; }
|
|
@@ -49,14 +51,14 @@ function add(args) {
|
|
|
49
51
|
var packagePath = _path["default"].join(curDir, 'package.json'); // Package directory check
|
|
50
52
|
|
|
51
53
|
|
|
52
|
-
if (!_fs["default"].existsSync(packagePath)) return
|
|
54
|
+
if (!_fs["default"].existsSync(packagePath)) return color.error('`package.json` not found');
|
|
53
55
|
|
|
54
56
|
try {
|
|
55
57
|
var _package = JSON.parse(_fs["default"].readFileSync(packagePath, {
|
|
56
58
|
encoding: 'utf-8'
|
|
57
59
|
}));
|
|
58
60
|
} catch (error) {
|
|
59
|
-
|
|
61
|
+
color.error("Error while reading ".concat(packagePath, ":"));
|
|
60
62
|
console.error(error);
|
|
61
63
|
} // TypeScript package check
|
|
62
64
|
|
|
@@ -68,7 +70,7 @@ function add(args) {
|
|
|
68
70
|
|
|
69
71
|
function validateName(name) {
|
|
70
72
|
if (!/^([A-Za-z])+([A-Za-z\d])*$/.test(name)) {
|
|
71
|
-
return
|
|
73
|
+
return color.error('The name may only include letters and numbers. It cannot start with a digit');
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
return true;
|
|
@@ -110,7 +112,7 @@ function add(args) {
|
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
if (!Object.keys(utils.scriptLangExtMap).includes(lang)) {
|
|
113
|
-
|
|
115
|
+
color.error("Unsupported language: ".concat(lang));
|
|
114
116
|
console.log('You can add a script in one of the following languages:');
|
|
115
117
|
console.log(Object.keys(utils.scriptLangExtMap).join(', '));
|
|
116
118
|
return false;
|
|
@@ -118,14 +120,14 @@ function add(args) {
|
|
|
118
120
|
|
|
119
121
|
|
|
120
122
|
if (!validateName(name)) return false;
|
|
121
|
-
if (tag && tag !== 'panel') return
|
|
123
|
+
if (tag && tag !== 'panel') return color.error('Currently, you can only add the `panel` tag'); // Create the folder `scripts` if it doesn't exist yet
|
|
122
124
|
|
|
123
125
|
if (!_fs["default"].existsSync(scriptsDir)) _fs["default"].mkdirSync(scriptsDir);
|
|
124
126
|
|
|
125
127
|
var scriptPath = _path["default"].join(scriptsDir, name + '.' + utils.scriptLangExtMap[lang]);
|
|
126
128
|
|
|
127
129
|
if (_fs["default"].existsSync(scriptPath)) {
|
|
128
|
-
return
|
|
130
|
+
return color.error("The file with the script already exists: ".concat(scriptPath));
|
|
129
131
|
} // Copy the script template
|
|
130
132
|
|
|
131
133
|
|
|
@@ -172,7 +174,7 @@ function add(args) {
|
|
|
172
174
|
if (!validateName(name)) return false;
|
|
173
175
|
|
|
174
176
|
if (tag && tag !== 'panel' && tag !== 'init') {
|
|
175
|
-
return
|
|
177
|
+
return color.error('Currently, you can only add the `panel` or `init` tag');
|
|
176
178
|
} // Create src/package.js if it doesn't exist yet
|
|
177
179
|
|
|
178
180
|
|
|
@@ -198,7 +200,7 @@ function add(args) {
|
|
|
198
200
|
var connectPath = _path["default"].join(connectDir, "".concat(name, ".json"));
|
|
199
201
|
|
|
200
202
|
if (_fs["default"].existsSync(connectPath)) {
|
|
201
|
-
return
|
|
203
|
+
return color.error("The connection file already exists: ".concat(connectPath));
|
|
202
204
|
}
|
|
203
205
|
|
|
204
206
|
var connectionTemplate = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'connection.json'), 'utf8');
|
|
@@ -252,7 +254,7 @@ function add(args) {
|
|
|
252
254
|
if (!validateName(name)) return false;
|
|
253
255
|
|
|
254
256
|
if (!name.endsWith('View')) {
|
|
255
|
-
|
|
257
|
+
color.warn("For consistency reasons, we recommend postfixing classes with 'View'");
|
|
256
258
|
} // Create src/package.js if it doesn't exist yet
|
|
257
259
|
|
|
258
260
|
|
|
@@ -261,7 +263,7 @@ function add(args) {
|
|
|
261
263
|
var viewPath = _path["default"].join(srcDir, utils.camelCaseToKebab(name) + ext);
|
|
262
264
|
|
|
263
265
|
if (_fs["default"].existsSync(viewPath)) {
|
|
264
|
-
return
|
|
266
|
+
return color.error("The view file already exists: ".concat(viewPath));
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
var viewClass = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'view-class' + ext), 'utf8');
|
|
@@ -287,7 +289,7 @@ function add(args) {
|
|
|
287
289
|
if (!validateName(name)) return false;
|
|
288
290
|
|
|
289
291
|
if (!name.endsWith('Viewer')) {
|
|
290
|
-
|
|
292
|
+
color.warn("For consistency reasons, we recommend postfixing classes with 'Viewer'");
|
|
291
293
|
} // Create src/package.js if it doesn't exist yet
|
|
292
294
|
|
|
293
295
|
|
|
@@ -296,7 +298,7 @@ function add(args) {
|
|
|
296
298
|
var viewerPath = _path["default"].join(srcDir, utils.camelCaseToKebab(name) + ext);
|
|
297
299
|
|
|
298
300
|
if (_fs["default"].existsSync(viewerPath)) {
|
|
299
|
-
return
|
|
301
|
+
return color.error("The viewer file already exists: ".concat(viewerPath));
|
|
300
302
|
}
|
|
301
303
|
|
|
302
304
|
var viewerClass = _fs["default"].readFileSync(_path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'entity-template', 'viewer-class' + ext), 'utf8');
|
|
@@ -331,7 +333,7 @@ function add(args) {
|
|
|
331
333
|
|
|
332
334
|
contents = _fs["default"].readFileSync(detectorsPath, 'utf8');
|
|
333
335
|
var idx = contents.search(/(?<=PackageDetectors extends DG.Package\s*{\s*(\r\n|\r|\n)).*/);
|
|
334
|
-
if (idx === -1) return
|
|
336
|
+
if (idx === -1) return color.error('Detectors class not found');
|
|
335
337
|
contents = contents.slice(0, idx) + detector + contents.slice(idx);
|
|
336
338
|
|
|
337
339
|
for (var _i2 = 0, _arr2 = ['NAME', 'NAME_PREFIX', 'PACKAGE_DETECTORS_NAME']; _i2 < _arr2.length; _i2++) {
|
package/bin/commands/api.js
CHANGED
|
@@ -17,6 +17,8 @@ var _ignoreWalk = _interopRequireDefault(require("ignore-walk"));
|
|
|
17
17
|
|
|
18
18
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
19
19
|
|
|
20
|
+
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
21
|
+
|
|
20
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); }
|
|
21
23
|
|
|
22
24
|
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; }
|
|
@@ -33,7 +35,8 @@ function generateQueryWrappers() {
|
|
|
33
35
|
var queriesDir = _path["default"].join(curDir, 'queries');
|
|
34
36
|
|
|
35
37
|
if (!_fs["default"].existsSync(queriesDir)) {
|
|
36
|
-
|
|
38
|
+
color.warn("Directory ".concat(queriesDir, " not found"));
|
|
39
|
+
console.log('Skipping API generation for queries...');
|
|
37
40
|
return;
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -103,14 +106,15 @@ function generateQueryWrappers() {
|
|
|
103
106
|
var queryFilePath = _path["default"].join(_fs["default"].existsSync(srcDir) ? srcDir : curDir, queryFileName);
|
|
104
107
|
|
|
105
108
|
if (_fs["default"].existsSync(queryFilePath)) {
|
|
106
|
-
|
|
109
|
+
color.warn("The file ".concat(queryFilePath, " already exists"));
|
|
110
|
+
console.log('Rewriting its contents...');
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
var sep = '\n';
|
|
110
114
|
|
|
111
115
|
_fs["default"].writeFileSync(queryFilePath, utils.dgImports + sep + wrappers.join(sep.repeat(2)) + sep, 'utf8');
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
color.success("Successfully generated file ".concat(queryFileName).concat(sep));
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
function generateScriptWrappers() {
|
|
@@ -119,7 +123,8 @@ function generateScriptWrappers() {
|
|
|
119
123
|
var scriptsDir = _path["default"].join(curDir, 'scripts');
|
|
120
124
|
|
|
121
125
|
if (!_fs["default"].existsSync(scriptsDir)) {
|
|
122
|
-
|
|
126
|
+
color.warn("Directory ".concat(scriptsDir, " not found"));
|
|
127
|
+
console.log('Skipping API generation for scripts...');
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -179,7 +184,8 @@ function generateScriptWrappers() {
|
|
|
179
184
|
var funcFilePath = _path["default"].join(_fs["default"].existsSync(srcDir) ? srcDir : curDir, funcFileName);
|
|
180
185
|
|
|
181
186
|
if (_fs["default"].existsSync(funcFilePath)) {
|
|
182
|
-
|
|
187
|
+
color.warn("The file ".concat(funcFilePath, " already exists"));
|
|
188
|
+
console.log('Rewriting its contents...');
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
var sep = '\n';
|
|
@@ -187,7 +193,7 @@ function generateScriptWrappers() {
|
|
|
187
193
|
|
|
188
194
|
_fs["default"].writeFileSync(funcFilePath, utils.dgImports + sep + scriptApi.build() + sep, 'utf8');
|
|
189
195
|
|
|
190
|
-
|
|
196
|
+
color.success("Successfully generated file ".concat(funcFileName).concat(sep));
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
function api(args) {
|
|
@@ -195,7 +201,7 @@ function api(args) {
|
|
|
195
201
|
if (args['_'].length !== 1 || nOptions > 0) return false;
|
|
196
202
|
|
|
197
203
|
if (!utils.isPackageDir(process.cwd())) {
|
|
198
|
-
|
|
204
|
+
color.error('File `package.json` not found. Run the command from the package directory');
|
|
199
205
|
return false;
|
|
200
206
|
}
|
|
201
207
|
|
package/bin/commands/config.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
6
8
|
value: true
|
|
7
9
|
});
|
|
@@ -23,6 +25,12 @@ var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
|
23
25
|
|
|
24
26
|
var _configValidator = require("../validators/config-validator");
|
|
25
27
|
|
|
28
|
+
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
29
|
+
|
|
30
|
+
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); }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
26
34
|
var confTemplateDir = _path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'config-template.yaml');
|
|
27
35
|
|
|
28
36
|
var confTemplate = _jsYaml["default"].load(_fs["default"].readFileSync(confTemplateDir, {
|
|
@@ -159,7 +167,7 @@ function config(args) {
|
|
|
159
167
|
try {
|
|
160
168
|
new URL(args.server);
|
|
161
169
|
} catch (error) {
|
|
162
|
-
|
|
170
|
+
color.error('URL parsing error. Please, provide a valid server URL.');
|
|
163
171
|
return false;
|
|
164
172
|
}
|
|
165
173
|
|
|
@@ -167,7 +175,7 @@ function config(args) {
|
|
|
167
175
|
url: args.server,
|
|
168
176
|
key: args.key
|
|
169
177
|
};
|
|
170
|
-
|
|
178
|
+
color.success('Successfully added the server.');
|
|
171
179
|
console.log("Use this command to deploy packages: grok publish ".concat(args.alias));
|
|
172
180
|
|
|
173
181
|
if (args["default"]) {
|
|
@@ -180,11 +188,11 @@ function config(args) {
|
|
|
180
188
|
var valRes = (0, _configValidator.validateConf)(config);
|
|
181
189
|
|
|
182
190
|
if (!config || !valRes.value) {
|
|
183
|
-
|
|
191
|
+
color.error(valRes.message);
|
|
184
192
|
return false;
|
|
185
193
|
}
|
|
186
194
|
|
|
187
|
-
if (valRes.warnings.length)
|
|
195
|
+
if (valRes.warnings.length) color.warn(valRes.warnings.join('\n'));
|
|
188
196
|
(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
189
197
|
var answers, server, url, question, devKey, defaultServer;
|
|
190
198
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
@@ -260,7 +268,7 @@ function config(args) {
|
|
|
260
268
|
case 25:
|
|
261
269
|
_context.prev = 25;
|
|
262
270
|
_context.t2 = _context["catch"](0);
|
|
263
|
-
|
|
271
|
+
color.error('The file is corrupted. Please run `grok config --reset` to restore the default template');
|
|
264
272
|
console.error(_context.t2);
|
|
265
273
|
return _context.abrupt("return", false);
|
|
266
274
|
|
package/bin/commands/create.js
CHANGED
|
@@ -25,6 +25,8 @@ var _entHelpers = require("../utils/ent-helpers");
|
|
|
25
25
|
|
|
26
26
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
27
27
|
|
|
28
|
+
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
29
|
+
|
|
28
30
|
var _configValidator = require("../validators/config-validator");
|
|
29
31
|
|
|
30
32
|
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); }
|
|
@@ -113,12 +115,12 @@ function createDirectoryContents(name, config, templateDir, packageDir) {
|
|
|
113
115
|
|
|
114
116
|
if (jest) {
|
|
115
117
|
Object.assign(_package.devDependencies, {
|
|
116
|
-
'jest': '
|
|
117
|
-
'jest
|
|
118
|
-
'@types/jest': '
|
|
119
|
-
'puppeteer': 'latest'
|
|
118
|
+
'jest-html-reporter': '^3.5.0',
|
|
119
|
+
'jest': '^27.0.0',
|
|
120
|
+
'@types/jest': '^27.0.0'
|
|
120
121
|
}, ts ? {
|
|
121
|
-
'ts-jest': '
|
|
122
|
+
'ts-jest': '^27.0.0',
|
|
123
|
+
'puppeteer': '^13.7.0'
|
|
122
124
|
} : {});
|
|
123
125
|
Object.assign(_package.scripts, {
|
|
124
126
|
'test': 'jest'
|
|
@@ -192,7 +194,7 @@ function create(args) {
|
|
|
192
194
|
var confTest = (0, _configValidator.validateConf)(config);
|
|
193
195
|
|
|
194
196
|
if (!confTest.value) {
|
|
195
|
-
|
|
197
|
+
color.error(confTest.message);
|
|
196
198
|
return false;
|
|
197
199
|
}
|
|
198
200
|
|
|
@@ -201,6 +203,7 @@ function create(args) {
|
|
|
201
203
|
|
|
202
204
|
if (validName) {
|
|
203
205
|
var packageDir = curDir;
|
|
206
|
+
var repositoryInfo = null;
|
|
204
207
|
|
|
205
208
|
if (curFolder !== name) {
|
|
206
209
|
packageDir = _path["default"].join(packageDir, name);
|
|
@@ -212,10 +215,44 @@ function create(args) {
|
|
|
212
215
|
|
|
213
216
|
if (!utils.isEmpty(packageDir)) {
|
|
214
217
|
console.log();
|
|
215
|
-
|
|
218
|
+
color.error('The package directory should be empty');
|
|
216
219
|
return false;
|
|
217
220
|
}
|
|
218
221
|
|
|
222
|
+
(0, _child_process.exec)('git rev-parse --is-inside-work-tree', {
|
|
223
|
+
cwd: packageDir
|
|
224
|
+
}, function (err) {
|
|
225
|
+
if (err) return;
|
|
226
|
+
var repository = {
|
|
227
|
+
type: 'git'
|
|
228
|
+
};
|
|
229
|
+
(0, _child_process.exec)('git config --get remote.origin.url', {
|
|
230
|
+
cwd: packageDir
|
|
231
|
+
}, function (err, stdout) {
|
|
232
|
+
if (err) return;
|
|
233
|
+
repository.url = stdout.trim();
|
|
234
|
+
(0, _child_process.exec)('git rev-parse --show-prefix', {
|
|
235
|
+
cwd: packageDir
|
|
236
|
+
}, function (err, stdout) {
|
|
237
|
+
if (err) return;
|
|
238
|
+
var prefix = stdout.trim();
|
|
239
|
+
repository.directory = prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
240
|
+
if (repository.type && repository.url && repository.directory) repositoryInfo = repository;
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
process.on('beforeExit', function () {
|
|
245
|
+
if (repositoryInfo) {
|
|
246
|
+
var packagePath = _path["default"].join(packageDir, 'package.json');
|
|
247
|
+
|
|
248
|
+
var p = JSON.parse(_fs["default"].readFileSync(packagePath, 'utf-8'));
|
|
249
|
+
p.repository = repositoryInfo;
|
|
250
|
+
|
|
251
|
+
_fs["default"].writeFileSync(packagePath, JSON.stringify(p, null, '\t'), 'utf-8');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
process.exit();
|
|
255
|
+
});
|
|
219
256
|
createDirectoryContents(name, config, templateDir, packageDir, args.ide, args.ts, args.eslint, args.jest);
|
|
220
257
|
console.log(_entHelpers.help["package"](name, args.ts));
|
|
221
258
|
console.log("\nThe package has the following dependencies:\n".concat(dependencies.join(' '), "\n"));
|
|
@@ -226,7 +263,7 @@ function create(args) {
|
|
|
226
263
|
if (err) throw err;else console.log(stderr, stdout);
|
|
227
264
|
});
|
|
228
265
|
} else {
|
|
229
|
-
|
|
266
|
+
color.error('Package name may only include letters, numbers, underscores, or hyphens');
|
|
230
267
|
}
|
|
231
268
|
|
|
232
269
|
return true;
|
package/bin/commands/publish.js
CHANGED
|
@@ -30,6 +30,8 @@ var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
|
30
30
|
|
|
31
31
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
32
32
|
|
|
33
|
+
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
34
|
+
|
|
33
35
|
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); }
|
|
34
36
|
|
|
35
37
|
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; }
|
|
@@ -86,7 +88,7 @@ function _processPackage() {
|
|
|
86
88
|
break;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
color.error(timestamps.message);
|
|
90
92
|
return _context3.abrupt("return", 1);
|
|
91
93
|
|
|
92
94
|
case 12:
|
|
@@ -118,7 +120,7 @@ function _processPackage() {
|
|
|
118
120
|
isWebpack = _fs["default"].existsSync('webpack.config.js');
|
|
119
121
|
|
|
120
122
|
if (!(!rebuild && isWebpack)) {
|
|
121
|
-
_context3.next =
|
|
123
|
+
_context3.next = 34;
|
|
122
124
|
break;
|
|
123
125
|
}
|
|
124
126
|
|
|
@@ -140,16 +142,14 @@ function _processPackage() {
|
|
|
140
142
|
distFiles.forEach(function (df) {
|
|
141
143
|
files.push("dist/".concat(df));
|
|
142
144
|
});
|
|
143
|
-
_context3.next =
|
|
145
|
+
_context3.next = 34;
|
|
144
146
|
break;
|
|
145
147
|
|
|
146
148
|
case 32:
|
|
147
|
-
|
|
148
|
-
console.log("Next time, please build your package locally with Webpack beforehand");
|
|
149
|
-
console.log("or run `grok publish` with the `--rebuild` option");
|
|
149
|
+
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');
|
|
150
150
|
rebuild = true;
|
|
151
151
|
|
|
152
|
-
case
|
|
152
|
+
case 34:
|
|
153
153
|
contentValidationLog = '';
|
|
154
154
|
files.forEach(function (file) {
|
|
155
155
|
var fullPath = file;
|
|
@@ -215,7 +215,7 @@ function _processPackage() {
|
|
|
215
215
|
case 7:
|
|
216
216
|
_context2.prev = 7;
|
|
217
217
|
_context2.t0 = _context2["catch"](0);
|
|
218
|
-
console.
|
|
218
|
+
console.error(response);
|
|
219
219
|
|
|
220
220
|
case 10:
|
|
221
221
|
case "end":
|
|
@@ -236,51 +236,51 @@ function _processPackage() {
|
|
|
236
236
|
})["catch"](function (error) {
|
|
237
237
|
console.error(error);
|
|
238
238
|
});
|
|
239
|
-
_context3.next =
|
|
239
|
+
_context3.next = 42;
|
|
240
240
|
return zip.finalize();
|
|
241
241
|
|
|
242
|
-
case
|
|
243
|
-
_context3.prev =
|
|
244
|
-
_context3.next =
|
|
242
|
+
case 42:
|
|
243
|
+
_context3.prev = 42;
|
|
244
|
+
_context3.next = 45;
|
|
245
245
|
return uploadPromise;
|
|
246
246
|
|
|
247
|
-
case
|
|
247
|
+
case 45:
|
|
248
248
|
log = _context3.sent;
|
|
249
249
|
|
|
250
250
|
_fs["default"].unlinkSync('zip');
|
|
251
251
|
|
|
252
252
|
if (!(log['#type'] === 'ApiError')) {
|
|
253
|
-
_context3.next =
|
|
253
|
+
_context3.next = 53;
|
|
254
254
|
break;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
console.
|
|
257
|
+
color.error(log['message']);
|
|
258
|
+
console.error(log['innerMessage']);
|
|
259
259
|
return _context3.abrupt("return", 1);
|
|
260
260
|
|
|
261
|
-
case
|
|
261
|
+
case 53:
|
|
262
262
|
console.log(log);
|
|
263
|
-
|
|
263
|
+
color.warn(contentValidationLog);
|
|
264
264
|
|
|
265
|
-
case
|
|
266
|
-
_context3.next =
|
|
265
|
+
case 55:
|
|
266
|
+
_context3.next = 61;
|
|
267
267
|
break;
|
|
268
268
|
|
|
269
|
-
case
|
|
270
|
-
_context3.prev =
|
|
271
|
-
_context3.t1 = _context3["catch"](
|
|
269
|
+
case 57:
|
|
270
|
+
_context3.prev = 57;
|
|
271
|
+
_context3.t1 = _context3["catch"](42);
|
|
272
272
|
console.error(_context3.t1);
|
|
273
273
|
return _context3.abrupt("return", 1);
|
|
274
274
|
|
|
275
|
-
case
|
|
275
|
+
case 61:
|
|
276
276
|
return _context3.abrupt("return", 0);
|
|
277
277
|
|
|
278
|
-
case
|
|
278
|
+
case 62:
|
|
279
279
|
case "end":
|
|
280
280
|
return _context3.stop();
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
}, _callee3, null, [[3, 14], [
|
|
283
|
+
}, _callee3, null, [[3, 14], [42, 57]]);
|
|
284
284
|
}));
|
|
285
285
|
return _processPackage.apply(this, arguments);
|
|
286
286
|
}
|
|
@@ -293,8 +293,13 @@ function publish(args) {
|
|
|
293
293
|
return ['build', 'rebuild', 'debug', 'release', 'k', 'key', 'suffix'].includes(option);
|
|
294
294
|
})) return false;
|
|
295
295
|
|
|
296
|
-
if (args.build && args.rebuild
|
|
297
|
-
|
|
296
|
+
if (args.build && args.rebuild) {
|
|
297
|
+
color.error('Incompatible options: --build and --rebuild');
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (args.debug && args.release) {
|
|
302
|
+
color.error('Incompatible options: --debug and --release');
|
|
298
303
|
return false;
|
|
299
304
|
} // Create `config.yaml` if it doesn't exist yet
|
|
300
305
|
|
|
@@ -317,16 +322,16 @@ function publish(args) {
|
|
|
317
322
|
if (url.endsWith('/')) url = url.slice(0, -1);
|
|
318
323
|
if (url in urls) key = config['servers'][urls[url]]['key'];
|
|
319
324
|
} catch (error) {
|
|
320
|
-
if (!(host in config.servers)) return
|
|
325
|
+
if (!(host in config.servers)) return color.error("Unknown server alias. Please add it to ".concat(confPath));
|
|
321
326
|
url = config['servers'][host]['url'];
|
|
322
327
|
key = config['servers'][host]['key'];
|
|
323
328
|
} // Update the developer key
|
|
324
329
|
|
|
325
330
|
|
|
326
331
|
if (args.key) key = args.key;
|
|
327
|
-
if (key === '') return
|
|
332
|
+
if (key === '') return color.warn('Please provide the key with `--key` option or add it by running `grok config`'); // Get the package name
|
|
328
333
|
|
|
329
|
-
if (!_fs["default"].existsSync(packDir)) return
|
|
334
|
+
if (!_fs["default"].existsSync(packDir)) return color.error('`package.json` doesn\'t exist');
|
|
330
335
|
|
|
331
336
|
var _package = JSON.parse(_fs["default"].readFileSync(packDir, {
|
|
332
337
|
encoding: 'utf-8'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.warn = exports.success = exports.info = exports.fail = exports.error = void 0;
|
|
7
|
+
|
|
8
|
+
var error = function error(s) {
|
|
9
|
+
return console.log('\x1b[31m%s\x1b[0m', s);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.error = error;
|
|
13
|
+
|
|
14
|
+
var info = function info(s) {
|
|
15
|
+
return console.log('\x1b[32m%s\x1b[0m', s);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.info = info;
|
|
19
|
+
|
|
20
|
+
var warn = function warn(s) {
|
|
21
|
+
return console.log('\x1b[33m%s\x1b[0m', s);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.warn = warn;
|
|
25
|
+
var success = info;
|
|
26
|
+
exports.success = success;
|
|
27
|
+
var fail = error;
|
|
28
|
+
exports.fail = fail;
|
package/package.json
CHANGED