datagrok-tools 4.7.2-beta.2 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +100 -100
  2. package/bin/_deprecated/migrate.js +83 -83
  3. package/bin/_deprecated/upload.js +161 -161
  4. package/bin/commands/link.js +4 -4
  5. package/bin/grok.js +29 -29
  6. package/bin/utils/test-utils.js +4 -3
  7. package/config-template.yaml +11 -11
  8. package/entity-template/app.js +6 -6
  9. package/entity-template/connection.json +17 -17
  10. package/entity-template/function.js +9 -9
  11. package/entity-template/function.ts +9 -9
  12. package/entity-template/init.js +4 -4
  13. package/entity-template/panel.js +11 -11
  14. package/entity-template/panel.ts +11 -11
  15. package/entity-template/queries.sql +7 -7
  16. package/entity-template/sem-type-detector.js +11 -11
  17. package/entity-template/test.ts +16 -16
  18. package/entity-template/view-class.js +60 -60
  19. package/entity-template/view-class.ts +64 -64
  20. package/entity-template/view.js +10 -10
  21. package/entity-template/viewer-class.js +23 -23
  22. package/entity-template/viewer-class.ts +23 -23
  23. package/entity-template/viewer.js +8 -8
  24. package/package-template/.eslintrc.json +38 -38
  25. package/package-template/.vscode/launch.json +15 -15
  26. package/package-template/.vscode/tasks.json +9 -9
  27. package/package-template/README.md +2 -2
  28. package/package-template/detectors.js +9 -9
  29. package/package-template/gitignore +29 -29
  30. package/package-template/npmignore +26 -26
  31. package/package-template/package.json +29 -29
  32. package/package-template/src/package-test.js +11 -11
  33. package/package-template/src/package-test.ts +12 -12
  34. package/package-template/src/package.js +11 -11
  35. package/package-template/ts.webpack.config.js +37 -37
  36. package/package-template/tsconfig.json +71 -71
  37. package/package-template/webpack.config.js +29 -29
  38. package/package.json +52 -52
  39. package/script-template/javascript.js +6 -6
  40. package/script-template/julia.jl +8 -8
  41. package/script-template/node.js +8 -8
  42. package/script-template/octave.m +8 -8
  43. package/script-template/python.py +8 -8
  44. package/script-template/r.R +8 -8
  45. package/tsconfig.json +71 -71
package/README.md CHANGED
@@ -1,100 +1,100 @@
1
- # Datagrok-tools
2
-
3
- Utility to upload and publish [packages](https://datagrok.ai/help/develop/develop#packages) to Datagrok.
4
-
5
- ## Installation
6
-
7
- ```shell
8
- npm install datagrok-tools -g
9
- ```
10
-
11
- ## Usage
12
-
13
- 1. Configure your environment with the following command:
14
-
15
- ```shell
16
- grok config
17
- ```
18
-
19
- Enter developer keys and set the default server. The developer key can be retrieved from your user profile (for
20
- example, see https://public.datagrok.ai/u).
21
- 2. Create a new package by running this command:
22
-
23
- ```shell
24
- grok create <package-name>
25
- ```
26
-
27
- A new folder `<package-name>` will be created automatically as well as its contents.
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.
31
- 5. Once you have completed the work on your package, upload it by running:
32
-
33
- ```shell
34
- grok publish
35
- ```
36
-
37
- Run `grok` for instructions and `grok <command> --help` to get help on a particular command.
38
-
39
- Read more about package development in [Datagrok's documentation](https://datagrok.ai/help/develop/develop).
40
-
41
- ## Commands
42
-
43
- - `config` creates or updates a configuration file. The command shows the location of the config file with the developer
44
- keys and offers to interactively change them. It is also possible to reset the current configuration.
45
- - `create` adds a package template to the current working directory when used without the `name` argument. The directory
46
- must be empty:
47
-
48
- ```shell
49
- grok create
50
- ```
51
-
52
- When called with an argument, the command creates a package in a folder with the specified name:
53
-
54
- ```shell
55
- grok create <package-name>
56
- ```
57
-
58
- Package name may only include letters, numbers, underscores, or hyphens. Read more about naming
59
- conventions [here](https://datagrok.ai/help/develop/develop#naming-conventions). Options:
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`
65
- - `add` puts an object template to your package:
66
-
67
- ```shell
68
- cd <package-name>
69
- grok add app <name>
70
- grok add connection <name>
71
- grok add detector <semantic-type-name>
72
- grok add function [tag] <name>
73
- grok add query <name>
74
- grok add script [tag] <language> <name>
75
- grok add view <name>
76
- grok add viewer <name>
77
- grok add tests
78
- ```
79
-
80
- In general, entity names follow naming rules for functions. Views and viewers should have class names, we recommend
81
- that you postfix them with 'View' and 'Viewer' respectively. Supported languages for scripts are `javascript`, `julia`
82
- , `node`, `octave`, `python`, `r`. Available function tags: `panel`, `init`.
83
- - `api` creates wrapper functions for package scripts and queries. The output is stored in files `/src/scripts-api.ts`
84
- and `/src/queries-api.ts` respectively.
85
- - `publish` uploads a package to the specified server (pass either a URL or a server alias from the `config.yaml` file).
86
-
87
- ```shell
88
- cd <package-name>
89
- grok publish [host]
90
- ```
91
-
92
- Options:
93
- - `--build` or `--rebuild`: boolean flags that indicate whether a local webpack bundle should be used or it should
94
- be generated on the server side
95
- - `--debug` or `--release`: boolean flags that determine whether to publish a debug version of the package visible
96
- only to the developer or a release version accessible by all eligible users and user groups
97
- - `--key`: a string containing a developer key that is not listed in the config file, e.g., the key for a new server
98
- - `--suffix`: a string containing package version hash
99
-
100
- Running `grok publish` is the same as running `grok publish defaultHost --build --debug`.
1
+ # Datagrok-tools
2
+
3
+ Utility to upload and publish [packages](https://datagrok.ai/help/develop/develop#packages) to Datagrok.
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ npm install datagrok-tools -g
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ 1. Configure your environment with the following command:
14
+
15
+ ```shell
16
+ grok config
17
+ ```
18
+
19
+ Enter developer keys and set the default server. The developer key can be retrieved from your user profile (for
20
+ example, see https://public.datagrok.ai/u).
21
+ 2. Create a new package by running this command:
22
+
23
+ ```shell
24
+ grok create <package-name>
25
+ ```
26
+
27
+ A new folder `<package-name>` will be created automatically as well as its contents.
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.
31
+ 5. Once you have completed the work on your package, upload it by running:
32
+
33
+ ```shell
34
+ grok publish
35
+ ```
36
+
37
+ Run `grok` for instructions and `grok <command> --help` to get help on a particular command.
38
+
39
+ Read more about package development in [Datagrok's documentation](https://datagrok.ai/help/develop/develop).
40
+
41
+ ## Commands
42
+
43
+ - `config` creates or updates a configuration file. The command shows the location of the config file with the developer
44
+ keys and offers to interactively change them. It is also possible to reset the current configuration.
45
+ - `create` adds a package template to the current working directory when used without the `name` argument. The directory
46
+ must be empty:
47
+
48
+ ```shell
49
+ grok create
50
+ ```
51
+
52
+ When called with an argument, the command creates a package in a folder with the specified name:
53
+
54
+ ```shell
55
+ grok create <package-name>
56
+ ```
57
+
58
+ Package name may only include letters, numbers, underscores, or hyphens. Read more about naming
59
+ conventions [here](https://datagrok.ai/help/develop/develop#naming-conventions). Options:
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`
65
+ - `add` puts an object template to your package:
66
+
67
+ ```shell
68
+ cd <package-name>
69
+ grok add app <name>
70
+ grok add connection <name>
71
+ grok add detector <semantic-type-name>
72
+ grok add function [tag] <name>
73
+ grok add query <name>
74
+ grok add script [tag] <language> <name>
75
+ grok add view <name>
76
+ grok add viewer <name>
77
+ grok add tests
78
+ ```
79
+
80
+ In general, entity names follow naming rules for functions. Views and viewers should have class names, we recommend
81
+ that you postfix them with 'View' and 'Viewer' respectively. Supported languages for scripts are `javascript`, `julia`
82
+ , `node`, `octave`, `python`, `r`. Available function tags: `panel`, `init`.
83
+ - `api` creates wrapper functions for package scripts and queries. The output is stored in files `/src/scripts-api.ts`
84
+ and `/src/queries-api.ts` respectively.
85
+ - `publish` uploads a package to the specified server (pass either a URL or a server alias from the `config.yaml` file).
86
+
87
+ ```shell
88
+ cd <package-name>
89
+ grok publish [host]
90
+ ```
91
+
92
+ Options:
93
+ - `--build` or `--rebuild`: boolean flags that indicate whether a local webpack bundle should be used or it should
94
+ be generated on the server side
95
+ - `--debug` or `--release`: boolean flags that determine whether to publish a debug version of the package visible
96
+ only to the developer or a release version accessible by all eligible users and user groups
97
+ - `--key`: a string containing a developer key that is not listed in the config file, e.g., the key for a new server
98
+ - `--suffix`: a string containing package version hash
99
+
100
+ Running `grok publish` is the same as running `grok publish defaultHost --build --debug`.
@@ -1,83 +1,83 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const os = require('os');
4
- const yaml = require('js-yaml');
5
- const utils = require('../utils/utils.js');
6
-
7
- module.exports = {
8
- migrate: migrate
9
- };
10
-
11
- const curDir = process.cwd();
12
- const keysDir = path.join(curDir, 'upload.keys.json');
13
- const packDir = path.join(curDir, 'package.json');
14
- const grokDir = path.join(os.homedir(), '.grok');
15
- const confPath = path.join(grokDir, 'config.yaml');
16
- const confTemplateDir = path.join(path.dirname(path.dirname(__dirname)), 'config-template.yaml');
17
- const confTemplate = yaml.load(fs.readFileSync(confTemplateDir));
18
-
19
- const grokMap = {
20
- 'datagrok-upload': 'grok publish',
21
- 'debug': '',
22
- 'deploy': '--release',
23
- 'build': '',
24
- 'rebuild': '--rebuild'
25
- };
26
-
27
- const replRegExp = new RegExp(Object.keys(grokMap).join("|"), "g");
28
-
29
- function migrate(args) {
30
- const nOptions = Object.keys(args).length - 1;
31
- const nArgs = args['_'].length;
32
-
33
- if (nArgs > 1 || nOptions > 0) return false;
34
-
35
- // Create `config.yaml` if it doesn't exist yet
36
- if (!fs.existsSync(grokDir)) fs.mkdirSync(grokDir);
37
- if (!fs.existsSync(confPath)) fs.writeFileSync(confPath, yaml.dump(confTemplate));
38
-
39
- let config = yaml.load(fs.readFileSync(confPath));
40
-
41
- // Copy keys to the `config.yaml` file
42
- if (fs.existsSync(keysDir)) {
43
- try {
44
- const keys = JSON.parse(fs.readFileSync(keysDir));
45
- let urls = utils.mapURL(config);
46
- for (const url in keys) {
47
- try {
48
- let hostname = (new URL(url)).hostname;
49
- if (url in urls) hostname = urls[url];
50
- config['servers'][hostname] = {};
51
- config['servers'][hostname]['url'] = url;
52
- config['servers'][hostname]['key'] = keys[url];
53
- } catch (error) {
54
- console.log(`Skipping an invalid URL in \`upload.keys.json\`: ${url}`);
55
- }
56
- }
57
- fs.writeFileSync(confPath, yaml.dump(config));
58
- console.log(`Migrated data from local \`upload.keys.json\` to ${confPath}`);
59
- fs.unlinkSync(keysDir);
60
- console.log('Successfully deleted the file');
61
- } catch (error) {
62
- console.error(error);
63
- }
64
- } else {
65
- console.log('Unable to locate `upload.keys.json`');
66
- }
67
-
68
- // Rewrite scripts in `package.json`
69
- if (!fs.existsSync(packDir)) return console.log('`package.json` doesn\'t exist');
70
- try {
71
- let _package = JSON.parse(fs.readFileSync(packDir));
72
- for (let script in _package.scripts) {
73
- if (!_package['scripts'][script].includes('datagrok-upload')) continue;
74
- _package['scripts'][script] = _package['scripts'][script].replace(replRegExp, (match) => grokMap[match]);
75
- }
76
- fs.writeFileSync(packDir, JSON.stringify(_package, null, '\t'));
77
- console.log('Converting scripts in `package.json`... Done!');
78
- } catch (error) {
79
- console.error(error);
80
- }
81
-
82
- return true;
83
- }
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+ const yaml = require('js-yaml');
5
+ const utils = require('../utils/utils.js');
6
+
7
+ module.exports = {
8
+ migrate: migrate
9
+ };
10
+
11
+ const curDir = process.cwd();
12
+ const keysDir = path.join(curDir, 'upload.keys.json');
13
+ const packDir = path.join(curDir, 'package.json');
14
+ const grokDir = path.join(os.homedir(), '.grok');
15
+ const confPath = path.join(grokDir, 'config.yaml');
16
+ const confTemplateDir = path.join(path.dirname(path.dirname(__dirname)), 'config-template.yaml');
17
+ const confTemplate = yaml.load(fs.readFileSync(confTemplateDir));
18
+
19
+ const grokMap = {
20
+ 'datagrok-upload': 'grok publish',
21
+ 'debug': '',
22
+ 'deploy': '--release',
23
+ 'build': '',
24
+ 'rebuild': '--rebuild'
25
+ };
26
+
27
+ const replRegExp = new RegExp(Object.keys(grokMap).join("|"), "g");
28
+
29
+ function migrate(args) {
30
+ const nOptions = Object.keys(args).length - 1;
31
+ const nArgs = args['_'].length;
32
+
33
+ if (nArgs > 1 || nOptions > 0) return false;
34
+
35
+ // Create `config.yaml` if it doesn't exist yet
36
+ if (!fs.existsSync(grokDir)) fs.mkdirSync(grokDir);
37
+ if (!fs.existsSync(confPath)) fs.writeFileSync(confPath, yaml.dump(confTemplate));
38
+
39
+ let config = yaml.load(fs.readFileSync(confPath));
40
+
41
+ // Copy keys to the `config.yaml` file
42
+ if (fs.existsSync(keysDir)) {
43
+ try {
44
+ const keys = JSON.parse(fs.readFileSync(keysDir));
45
+ let urls = utils.mapURL(config);
46
+ for (const url in keys) {
47
+ try {
48
+ let hostname = (new URL(url)).hostname;
49
+ if (url in urls) hostname = urls[url];
50
+ config['servers'][hostname] = {};
51
+ config['servers'][hostname]['url'] = url;
52
+ config['servers'][hostname]['key'] = keys[url];
53
+ } catch (error) {
54
+ console.log(`Skipping an invalid URL in \`upload.keys.json\`: ${url}`);
55
+ }
56
+ }
57
+ fs.writeFileSync(confPath, yaml.dump(config));
58
+ console.log(`Migrated data from local \`upload.keys.json\` to ${confPath}`);
59
+ fs.unlinkSync(keysDir);
60
+ console.log('Successfully deleted the file');
61
+ } catch (error) {
62
+ console.error(error);
63
+ }
64
+ } else {
65
+ console.log('Unable to locate `upload.keys.json`');
66
+ }
67
+
68
+ // Rewrite scripts in `package.json`
69
+ if (!fs.existsSync(packDir)) return console.log('`package.json` doesn\'t exist');
70
+ try {
71
+ let _package = JSON.parse(fs.readFileSync(packDir));
72
+ for (let script in _package.scripts) {
73
+ if (!_package['scripts'][script].includes('datagrok-upload')) continue;
74
+ _package['scripts'][script] = _package['scripts'][script].replace(replRegExp, (match) => grokMap[match]);
75
+ }
76
+ fs.writeFileSync(packDir, JSON.stringify(_package, null, '\t'));
77
+ console.log('Converting scripts in `package.json`... Done!');
78
+ } catch (error) {
79
+ console.error(error);
80
+ }
81
+
82
+ return true;
83
+ }