datagrok-tools 4.4.2 → 4.5.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 +35 -20
- 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 +52 -12
- package/bin/commands/help.js +1 -1
- package/bin/commands/publish.js +36 -31
- package/bin/utils/color-utils.js +28 -0
- package/bin/utils/ent-helpers.js +2 -3
- package/package-template/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,27 +4,33 @@ Utility to upload and publish [packages](https://datagrok.ai/help/develop/develo
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```shell
|
|
8
8
|
npm install datagrok-tools -g
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
1. Configure your environment with the following command:
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
```shell
|
|
15
16
|
grok config
|
|
16
17
|
```
|
|
18
|
+
|
|
17
19
|
Enter developer keys and set the default server. The developer key can be retrieved from your user profile (for
|
|
18
20
|
example, see https://public.datagrok.ai/u).
|
|
19
21
|
2. Create a new package by running this command:
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
```shell
|
|
21
24
|
grok create <package-name>
|
|
22
25
|
```
|
|
26
|
+
|
|
23
27
|
A new folder `<package-name>` will be created automatically as well as its contents.
|
|
24
|
-
3. Run `npm install` in your package directory to get the required dependencies
|
|
25
|
-
|
|
28
|
+
3. Run `npm install` in your package directory to get the required dependencies (the command is called
|
|
29
|
+
automatically after package creation, if it ran successfully, skip this step).
|
|
30
|
+
4. Start working on the functionality of your package. Use `grok add` to create function templates.
|
|
26
31
|
5. Once you have completed the work on your package, upload it by running:
|
|
27
|
-
|
|
32
|
+
|
|
33
|
+
```shell
|
|
28
34
|
grok publish
|
|
29
35
|
```
|
|
30
36
|
|
|
@@ -38,21 +44,27 @@ Read more about package development in [Datagrok's documentation](https://datagr
|
|
|
38
44
|
keys and offers to interactively change them. It is also possible to reset the current configuration.
|
|
39
45
|
- `create` adds a package template to the current working directory when used without the `name` argument. The directory
|
|
40
46
|
must be empty:
|
|
41
|
-
|
|
47
|
+
|
|
48
|
+
```shell
|
|
42
49
|
grok create
|
|
43
50
|
```
|
|
51
|
+
|
|
44
52
|
When called with an argument, the command creates a package in a folder with the specified name:
|
|
45
|
-
|
|
53
|
+
|
|
54
|
+
```shell
|
|
46
55
|
grok create <package-name>
|
|
47
56
|
```
|
|
57
|
+
|
|
48
58
|
Package name may only include letters, numbers, underscores, or hyphens. Read more about naming
|
|
49
59
|
conventions [here](https://datagrok.ai/help/develop/develop#naming-conventions). Options:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
- `--eslint` adds a basic configuration for `eslint`
|
|
61
|
+
- `--ide` adds an IDE-specific configuration for debugging (vscode)
|
|
62
|
+
- `--js` creates a JavaScript package template
|
|
63
|
+
- `--ts` creates a TypeScript package template (default)
|
|
64
|
+
- `--jest` adds a basic configuration for `jest`
|
|
54
65
|
- `add` puts an object template to your package:
|
|
55
|
-
|
|
66
|
+
|
|
67
|
+
```shell
|
|
56
68
|
cd <package-name>
|
|
57
69
|
grok add app <name>
|
|
58
70
|
grok add connection <name>
|
|
@@ -63,22 +75,25 @@ Read more about package development in [Datagrok's documentation](https://datagr
|
|
|
63
75
|
grok add view <name>
|
|
64
76
|
grok add viewer <name>
|
|
65
77
|
```
|
|
78
|
+
|
|
66
79
|
In general, entity names follow naming rules for functions. Views and viewers should have class names, we recommend
|
|
67
80
|
that you postfix them with 'View' and 'Viewer' respectively. Supported languages for scripts are `javascript`, `julia`
|
|
68
81
|
, `node`, `octave`, `python`, `r`. Available function tags: `panel`, `init`.
|
|
69
82
|
- `api` creates wrapper functions for package scripts and queries. The output is stored in files `/src/scripts-api.ts`
|
|
70
83
|
and `/src/queries-api.ts` respectively.
|
|
71
84
|
- `publish` uploads a package to the specified server (pass either a URL or a server alias from the `config.yaml` file).
|
|
72
|
-
|
|
85
|
+
|
|
86
|
+
```shell
|
|
73
87
|
cd <package-name>
|
|
74
88
|
grok publish [host]
|
|
75
89
|
```
|
|
90
|
+
|
|
76
91
|
Options:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
- `--build` or `--rebuild`: boolean flags that indicate whether a local webpack bundle should be used or it should
|
|
93
|
+
be generated on the server side
|
|
94
|
+
- `--debug` or `--release`: boolean flags that determine whether to publish a debug version of the package visible
|
|
95
|
+
only to the developer or a release version accessible by all eligible users and user groups
|
|
96
|
+
- `--key`: a string containing a developer key that is not listed in the config file, e.g., the key for a new server
|
|
97
|
+
- `--suffix`: a string containing package version hash
|
|
83
98
|
|
|
84
99
|
Running `grok publish` is the same as running `grok publish defaultHost --build --debug`.
|
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); }
|
|
@@ -53,7 +55,7 @@ var dependencies = [];
|
|
|
53
55
|
|
|
54
56
|
function createDirectoryContents(name, config, templateDir, packageDir) {
|
|
55
57
|
var ide = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
|
|
56
|
-
var ts = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] :
|
|
58
|
+
var ts = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
|
|
57
59
|
var eslint = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
58
60
|
var jest = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
59
61
|
|
|
@@ -88,8 +90,8 @@ function createDirectoryContents(name, config, templateDir, packageDir) {
|
|
|
88
90
|
|
|
89
91
|
for (var server in config.servers) {
|
|
90
92
|
if (server === config["default"]) continue;
|
|
91
|
-
_package['scripts']["debug-".concat(name.toLowerCase(), "-").concat(server)] = "grok publish ".concat(server
|
|
92
|
-
_package['scripts']["release-".concat(name.toLowerCase(), "-").concat(server)] = "grok publish ".concat(server, " --
|
|
93
|
+
_package['scripts']["debug-".concat(name.toLowerCase(), "-").concat(server)] = "webpack && grok publish ".concat(server);
|
|
94
|
+
_package['scripts']["release-".concat(name.toLowerCase(), "-").concat(server)] = "webpack && grok publish ".concat(server, " --release");
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
if (ts) Object.assign(_package.devDependencies, {
|
|
@@ -118,7 +120,7 @@ function createDirectoryContents(name, config, templateDir, packageDir) {
|
|
|
118
120
|
'@types/jest': '^27.0.0'
|
|
119
121
|
}, ts ? {
|
|
120
122
|
'ts-jest': '^27.0.0',
|
|
121
|
-
'puppeteer': '
|
|
123
|
+
'puppeteer': '^13.7.0'
|
|
122
124
|
} : {});
|
|
123
125
|
Object.assign(_package.scripts, {
|
|
124
126
|
'test': 'jest'
|
|
@@ -175,12 +177,14 @@ function createDirectoryContents(name, config, templateDir, packageDir) {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
function create(args) {
|
|
180
|
+
var options = ['ide', 'js', 'ts', 'eslint', 'jest'];
|
|
178
181
|
var nOptions = Object.keys(args).length - 1;
|
|
179
182
|
var nArgs = args['_'].length;
|
|
180
|
-
if (nArgs > 2 || nOptions >
|
|
183
|
+
if (nArgs > 2 || nOptions > 4) return false;
|
|
181
184
|
if (nOptions && !Object.keys(args).slice(1).every(function (op) {
|
|
182
|
-
return
|
|
183
|
-
})) return false;
|
|
185
|
+
return options.includes(op);
|
|
186
|
+
})) return false;
|
|
187
|
+
if (args.js && args.ts) return color.error('Incompatible options: --js and --ts'); // Create `config.yaml` if it doesn't exist yet
|
|
184
188
|
|
|
185
189
|
if (!_fs["default"].existsSync(grokDir)) _fs["default"].mkdirSync(grokDir);
|
|
186
190
|
if (!_fs["default"].existsSync(confPath)) _fs["default"].writeFileSync(confPath, _jsYaml["default"].dump(confTemplate));
|
|
@@ -192,7 +196,7 @@ function create(args) {
|
|
|
192
196
|
var confTest = (0, _configValidator.validateConf)(config);
|
|
193
197
|
|
|
194
198
|
if (!confTest.value) {
|
|
195
|
-
|
|
199
|
+
color.error(confTest.message);
|
|
196
200
|
return false;
|
|
197
201
|
}
|
|
198
202
|
|
|
@@ -201,6 +205,7 @@ function create(args) {
|
|
|
201
205
|
|
|
202
206
|
if (validName) {
|
|
203
207
|
var packageDir = curDir;
|
|
208
|
+
var repositoryInfo = null;
|
|
204
209
|
|
|
205
210
|
if (curFolder !== name) {
|
|
206
211
|
packageDir = _path["default"].join(packageDir, name);
|
|
@@ -212,12 +217,47 @@ function create(args) {
|
|
|
212
217
|
|
|
213
218
|
if (!utils.isEmpty(packageDir)) {
|
|
214
219
|
console.log();
|
|
215
|
-
|
|
220
|
+
color.error('The package directory should be empty');
|
|
216
221
|
return false;
|
|
217
222
|
}
|
|
218
223
|
|
|
219
|
-
|
|
220
|
-
|
|
224
|
+
(0, _child_process.exec)('git rev-parse --is-inside-work-tree', {
|
|
225
|
+
cwd: packageDir
|
|
226
|
+
}, function (err) {
|
|
227
|
+
if (err) return;
|
|
228
|
+
var repository = {
|
|
229
|
+
type: 'git'
|
|
230
|
+
};
|
|
231
|
+
(0, _child_process.exec)('git config --get remote.origin.url', {
|
|
232
|
+
cwd: packageDir
|
|
233
|
+
}, function (err, stdout) {
|
|
234
|
+
if (err) return;
|
|
235
|
+
repository.url = stdout.trim();
|
|
236
|
+
(0, _child_process.exec)('git rev-parse --show-prefix', {
|
|
237
|
+
cwd: packageDir
|
|
238
|
+
}, function (err, stdout) {
|
|
239
|
+
if (err) return;
|
|
240
|
+
var prefix = stdout.trim();
|
|
241
|
+
repository.directory = prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
242
|
+
if (repository.type && repository.url && repository.directory) repositoryInfo = repository;
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
process.on('beforeExit', function () {
|
|
247
|
+
if (repositoryInfo) {
|
|
248
|
+
var packagePath = _path["default"].join(packageDir, 'package.json');
|
|
249
|
+
|
|
250
|
+
var p = JSON.parse(_fs["default"].readFileSync(packagePath, 'utf-8'));
|
|
251
|
+
p.repository = repositoryInfo;
|
|
252
|
+
|
|
253
|
+
_fs["default"].writeFileSync(packagePath, JSON.stringify(p, null, '\t'), 'utf-8');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
process.exit();
|
|
257
|
+
});
|
|
258
|
+
createDirectoryContents(name, config, templateDir, packageDir, args.ide, !!args.ts, !!args.eslint, !!args.jest);
|
|
259
|
+
color.success('Successfully created package ' + name);
|
|
260
|
+
console.log(_entHelpers.help["package"](!!args.ts));
|
|
221
261
|
console.log("\nThe package has the following dependencies:\n".concat(dependencies.join(' '), "\n"));
|
|
222
262
|
console.log('Running `npm install` to get the required dependencies...\n');
|
|
223
263
|
(0, _child_process.exec)('npm install', {
|
|
@@ -226,7 +266,7 @@ function create(args) {
|
|
|
226
266
|
if (err) throw err;else console.log(stderr, stdout);
|
|
227
267
|
});
|
|
228
268
|
} else {
|
|
229
|
-
|
|
269
|
+
color.error('Package name may only include letters, numbers, underscores, or hyphens');
|
|
230
270
|
}
|
|
231
271
|
|
|
232
272
|
return true;
|
package/bin/commands/help.js
CHANGED
|
@@ -8,7 +8,7 @@ var HELP = "\nUsage: grok <command>\n\nDatagrok's package management tool\n\nCom
|
|
|
8
8
|
var HELP_ADD = "\nUsage: grok add <entity> <name>\n\nAdd an object template to your package:\n\ngrok add app <name>\ngrok add connection <name>\ngrok add detector <semantic-type-name>\ngrok add function [tag] <name>\ngrok add query <name>\ngrok add script [tag] <language> <name>\ngrok add view <name>\ngrok add viewer <name>\n\nPlease note that entity names may only include letters and numbers\n\nSupported languages for scripts:\njavascript, julia, node, octave, python, r\n\nAvailable tags:\npanel, init\n";
|
|
9
9
|
var HELP_API = "\nUsage: grok api\n\nCreate wrapper functions for package scripts and queries\n";
|
|
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
|
-
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] [--ts] [--jest]\n\n--eslint Add a configuration for eslint\n--ide Add an IDE-specific configuration for debugging (vscode)\n--ts Create a TypeScript package\n--jest Add a configuration for jest\n";
|
|
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
13
|
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";
|
|
14
14
|
var help = {
|
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/bin/utils/ent-helpers.js
CHANGED
|
@@ -38,9 +38,8 @@ var viewer = function viewer(viewerName) {
|
|
|
38
38
|
return "\nThe viewer ".concat(viewerName, " has been added successfully\nRead more at https://datagrok.ai/help/develop/how-to/develop-custom-viewer\nSee examples at https://github.com/datagrok-ai/public/tree/master/packages/Viewers,\nhttps://public.datagrok.ai/js/samples/functions/custom-viewers/viewers");
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
var _package = function _package(
|
|
42
|
-
|
|
43
|
-
return "\nSuccessfully created package `".concat(name, "`").concat(ts ? '' : '\nConsider TypeScript as a language for package development, to start over, run `grok create` with the `--ts` flag', "\nLikely next steps: `grok add` to add functionality, `grok publish` to upload the package");
|
|
41
|
+
var _package = function _package(ts) {
|
|
42
|
+
return ts ? '' : 'Consider TypeScript as a language for package development, to start over, run `grok create` with the `--ts` flag\n' + 'Likely next steps: `grok add` to add functionality, `grok publish` to upload the package';
|
|
44
43
|
};
|
|
45
44
|
|
|
46
45
|
var help = {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"link-all": "",
|
|
19
|
-
"debug-#{PACKAGE_NAME_LOWERCASE}": "webpack && grok publish
|
|
19
|
+
"debug-#{PACKAGE_NAME_LOWERCASE}": "webpack && grok publish",
|
|
20
20
|
"release-#{PACKAGE_NAME_LOWERCASE}": "webpack && grok publish --release",
|
|
21
21
|
"build-#{PACKAGE_NAME_LOWERCASE}": "webpack",
|
|
22
22
|
"build": "webpack"
|
package/package.json
CHANGED