datagrok-tools 4.13.74 → 4.13.76
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 +96 -106
- package/bin/commands/api.js +65 -107
- package/bin/commands/check.js +264 -396
- package/bin/commands/config.js +82 -158
- package/bin/commands/create.js +65 -80
- package/bin/commands/help.js +194 -12
- package/bin/commands/init.js +73 -95
- package/bin/commands/link.js +70 -176
- package/bin/commands/publish.js +283 -484
- package/bin/commands/test-all.js +77 -291
- package/bin/commands/test.js +169 -391
- package/bin/utils/color-utils.js +8 -11
- package/bin/utils/ent-helpers.js +52 -42
- package/bin/utils/func-generation.js +25 -57
- package/bin/utils/interfaces.js +5 -1
- package/bin/utils/order-functions.js +47 -118
- package/bin/utils/test-utils.js +322 -750
- package/bin/utils/utils.js +123 -235
- package/bin/validators/config-validator.js +12 -14
- package/package.json +13 -4
package/bin/commands/help.js
CHANGED
|
@@ -4,17 +4,199 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.help = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const HELP = `
|
|
8
|
+
Usage: grok <command>
|
|
9
|
+
|
|
10
|
+
Datagrok's package management tool
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
add Add an object template
|
|
14
|
+
api Create wrapper functions
|
|
15
|
+
check Check package content (function signatures, etc.)
|
|
16
|
+
config Create and manage config files
|
|
17
|
+
create Create a package
|
|
18
|
+
init Modify a package template
|
|
19
|
+
link Link \`datagrok-api\` and libraries for local development
|
|
20
|
+
publish Upload a package
|
|
21
|
+
test Run package tests
|
|
22
|
+
testall Run packages tests
|
|
23
|
+
|
|
24
|
+
To get help on a particular command, use:
|
|
25
|
+
grok <command> --help
|
|
26
|
+
|
|
27
|
+
Read more about the package development workflow:
|
|
28
|
+
https://datagrok.ai/help/develop/develop
|
|
29
|
+
`;
|
|
30
|
+
const HELP_ADD = `
|
|
31
|
+
Usage: grok add <entity> <name>
|
|
32
|
+
|
|
33
|
+
Add an object template to your package:
|
|
34
|
+
|
|
35
|
+
grok add app <name>
|
|
36
|
+
grok add connection <name>
|
|
37
|
+
grok add detector <semantic-type-name>
|
|
38
|
+
grok add function [tag] <name>
|
|
39
|
+
grok add query <name>
|
|
40
|
+
grok add script [tag] <language> <name>
|
|
41
|
+
grok add view <name>
|
|
42
|
+
grok add viewer <name>
|
|
43
|
+
grok add tests
|
|
44
|
+
|
|
45
|
+
Please note that entity names may only include letters and numbers
|
|
46
|
+
|
|
47
|
+
Supported languages for scripts:
|
|
48
|
+
javascript, julia, node, octave, python, r
|
|
49
|
+
|
|
50
|
+
Available tags:
|
|
51
|
+
panel, init
|
|
52
|
+
`;
|
|
53
|
+
const HELP_INIT = `
|
|
54
|
+
Usage: grok init
|
|
55
|
+
|
|
56
|
+
Modify a package template by adding config files for linters, IDE, etc.
|
|
57
|
+
|
|
58
|
+
Options:
|
|
59
|
+
[--eslint] [--ide] [--test] [--ts] [--git]
|
|
60
|
+
|
|
61
|
+
--eslint Add a configuration for eslint
|
|
62
|
+
--ide Add an IDE-specific configuration for debugging (vscode)
|
|
63
|
+
--test Add tests support (TypeScript packages only)
|
|
64
|
+
--ts Convert a JavaScript package to TypeScript
|
|
65
|
+
--git Configure GIT and install commit linting tools.
|
|
66
|
+
Read more: https://datagrok.ai/help/develop/advanced/git-policy
|
|
67
|
+
`;
|
|
68
|
+
const HELP_API = `
|
|
69
|
+
Usage: grok api
|
|
70
|
+
|
|
71
|
+
Create wrapper functions for package scripts and queries
|
|
72
|
+
`;
|
|
73
|
+
const HELP_CONFIG = `
|
|
74
|
+
Usage: grok config
|
|
75
|
+
|
|
76
|
+
Create or update a configuration file
|
|
77
|
+
|
|
78
|
+
Options:
|
|
79
|
+
[--reset] [--server] [--alias] [-k | --key]
|
|
80
|
+
|
|
81
|
+
--reset Restore the default config file template
|
|
82
|
+
--server Use to add a server to the config (\`grok config add --alias alias --server url --key key\`)
|
|
83
|
+
--alias Use in conjunction with the \`server\` option to set the server name
|
|
84
|
+
--key Use in conjunction with the \`server\` option to set the developer key
|
|
85
|
+
--default Use in conjunction with the \`server\` option to set the added server as default
|
|
86
|
+
`;
|
|
87
|
+
const HELP_CREATE = `
|
|
88
|
+
Usage: grok create [name]
|
|
89
|
+
|
|
90
|
+
Create a package:
|
|
91
|
+
|
|
92
|
+
grok create Create a package in the current working directory
|
|
93
|
+
grok create <name> Create a package in a folder with the specified name
|
|
94
|
+
|
|
95
|
+
Please note that the package name may only include letters, numbers, underscores, or hyphens
|
|
96
|
+
|
|
97
|
+
Options:
|
|
98
|
+
[--eslint] [--ide] [--js | --ts] [--test]
|
|
99
|
+
|
|
100
|
+
--eslint Add a configuration for eslint
|
|
101
|
+
--ide Add an IDE-specific configuration for debugging (vscode)
|
|
102
|
+
--js Create a JavaScript package
|
|
103
|
+
--ts Create a TypeScript package (default)
|
|
104
|
+
--test Add tests support (TypeScript packages only)
|
|
105
|
+
`;
|
|
106
|
+
const HELP_PUBLISH = `
|
|
107
|
+
Usage: grok publish [host]
|
|
108
|
+
|
|
109
|
+
Upload a package
|
|
110
|
+
|
|
111
|
+
Options:
|
|
112
|
+
[--build|--rebuild] [--debug|--release] [-k | --key] [--suffix] [--all] [--refresh] [--link]
|
|
113
|
+
|
|
114
|
+
--all Publish all available packages
|
|
115
|
+
--refresh Publish all available already loaded packages
|
|
116
|
+
--link Link the package to local utils
|
|
117
|
+
|
|
118
|
+
Running \`grok publish\` is the same as running \`grok publish defaultHost --build --debug\`
|
|
119
|
+
`;
|
|
120
|
+
const HELP_CHECK = `
|
|
121
|
+
Usage: grok check
|
|
122
|
+
|
|
123
|
+
Options:
|
|
124
|
+
[-r | --recursive]
|
|
125
|
+
|
|
126
|
+
--recursive Check all packages in the current directory
|
|
127
|
+
|
|
128
|
+
Check package content (function signatures, import statements of external modules, etc.)
|
|
129
|
+
`;
|
|
130
|
+
const HELP_TEST = `
|
|
131
|
+
Usage: grok test
|
|
132
|
+
|
|
133
|
+
Options:
|
|
134
|
+
[--package] [--category] [--test] [--host] [--csv] [--gui] [--skip-build] [--skip-publish] [--link] [--catchUnhandled] [--report] [--record] [--verbose] [--platform] [--benchmark] [--stress-test] --[debug]
|
|
135
|
+
|
|
136
|
+
--package Specify a package name to run tests for
|
|
137
|
+
--category Specify a category name to run tests for
|
|
138
|
+
--test Specify a test name to run
|
|
139
|
+
--host Host alias as in the config file
|
|
140
|
+
--csv Save the test report in a CSV file
|
|
141
|
+
--gui Launch graphical interface (non-headless mode)
|
|
142
|
+
--debug Enables debug point on tests run (useless without gui mode)
|
|
143
|
+
--catchUnhandled Catch unhandled exceptions during test execution (default=true)
|
|
144
|
+
--report Report failed tests to audit, notifies package author (default=false)
|
|
145
|
+
--skip-build Skip the package build step
|
|
146
|
+
--skip-publish Skip the package publication step
|
|
147
|
+
--link Link the package to local utils
|
|
148
|
+
--record Records the test execution process in mp4 format
|
|
149
|
+
--verbose Prints detailed information about passed and skipped tests in the console
|
|
150
|
+
--platform Runs only platform tests (applicable for ApiTests package only)
|
|
151
|
+
--core Runs package & auto tests & core tests (core tests run only from DevTools package)
|
|
152
|
+
--benchmark Runs tests in benchmark mode
|
|
153
|
+
--stress-test Runs shuffled stress-test only
|
|
154
|
+
|
|
155
|
+
Run package tests
|
|
156
|
+
|
|
157
|
+
See instructions:
|
|
158
|
+
https://datagrok.ai/help/develop/how-to/test-packages#local-testing
|
|
159
|
+
`;
|
|
160
|
+
const HELP_TESTALL = `
|
|
161
|
+
Usage: grok testall
|
|
162
|
+
|
|
163
|
+
Options:
|
|
164
|
+
[--packages] [--host] [--csv] [--gui] [--skip-build] [--skip-publish] [--link-package] [--catchUnhandled] [--report] [--record] [--verbose] [--benchmark] [--stress-test] [--order] [--tags] [--testRepeat] [--browsers-count] [--debug]
|
|
165
|
+
|
|
166
|
+
--packages Specify a packages names to run tests for
|
|
167
|
+
--host Host alias as in the config file
|
|
168
|
+
--csv Save the test report in a CSV file
|
|
169
|
+
--gui Launch graphical interface (non-headless mode)
|
|
170
|
+
--debug Enables debug point on tests run (useless without gui mode)
|
|
171
|
+
--catchUnhandled Catch unhandled exceptions during test execution (default=true)
|
|
172
|
+
--report Report failed tests to audit, notifies packages author (default=false)
|
|
173
|
+
--skip-build Skip the packages build step
|
|
174
|
+
--skip-publish Skip the packages publication step
|
|
175
|
+
--link-package Link the packages to local utils
|
|
176
|
+
--record Records the test execution process in mp4 format
|
|
177
|
+
--verbose Prints detailed information about passed and skipped tests in the console
|
|
178
|
+
--core Runs packages & core tests (applicable for DevTools packages only)
|
|
179
|
+
--benchmark Runs tests in benchmark mode
|
|
180
|
+
--stress-test Runs shuffled stress-test only
|
|
181
|
+
--order Specify order for tests invocation
|
|
182
|
+
--tags Filter tests by tag name for run
|
|
183
|
+
--testRepeat Set amount of tests repeats
|
|
184
|
+
--browsers-count Set amount of browsers for tests run
|
|
185
|
+
|
|
186
|
+
Run tests of all or specified packages
|
|
187
|
+
|
|
188
|
+
See instructions:
|
|
189
|
+
https://datagrok.ai/help/develop/how-to/test-packages#local-testing
|
|
190
|
+
`;
|
|
191
|
+
const HELP_LINK = `
|
|
192
|
+
Usage: grok link
|
|
193
|
+
|
|
194
|
+
Link \`datagrok-api\` and libraries for local development
|
|
195
|
+
|
|
196
|
+
Options:
|
|
197
|
+
--dev Links also dev dependencies
|
|
198
|
+
--verbose Prints detailed information about linked packages
|
|
199
|
+
`;
|
|
18
200
|
|
|
19
201
|
// const HELP_MIGRATE = `
|
|
20
202
|
// Usage: grok migrate
|
|
@@ -23,7 +205,7 @@ var HELP_LINK = "\nUsage: grok link\n\nLink `datagrok-api` and libraries for loc
|
|
|
23
205
|
// file and converting your scripts in the \`package.json\` file
|
|
24
206
|
// `;
|
|
25
207
|
|
|
26
|
-
|
|
208
|
+
const help = exports.help = {
|
|
27
209
|
add: HELP_ADD,
|
|
28
210
|
api: HELP_API,
|
|
29
211
|
check: HELP_CHECK,
|
package/bin/commands/init.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -14,49 +13,37 @@ var _child_process = require("child_process");
|
|
|
14
13
|
var utils = _interopRequireWildcard(require("../utils/utils"));
|
|
15
14
|
var color = _interopRequireWildcard(require("../utils/color-utils"));
|
|
16
15
|
var _configValidator = require("../validators/config-validator");
|
|
17
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
18
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var webpackConfigPath = _path["default"].join(curDir, 'webpack.config.js');
|
|
29
|
-
var templateDir = _path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)), 'package-template');
|
|
30
|
-
var options = ['ide', 'eslint', 'test', 'ts', 'git'];
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
const curDir = process.cwd();
|
|
19
|
+
const platform = _os.default.platform();
|
|
20
|
+
const grokDir = _path.default.join(_os.default.homedir(), '.grok');
|
|
21
|
+
const confPath = _path.default.join(grokDir, 'config.yaml');
|
|
22
|
+
const packageJsonPath = _path.default.join(curDir, 'package.json');
|
|
23
|
+
const tsConfigPath = _path.default.join(curDir, 'tsconfig.json');
|
|
24
|
+
const webpackConfigPath = _path.default.join(curDir, 'webpack.config.js');
|
|
25
|
+
const templateDir = _path.default.join(_path.default.dirname(_path.default.dirname(__dirname)), 'package-template');
|
|
26
|
+
const options = ['ide', 'eslint', 'test', 'ts', 'git'];
|
|
31
27
|
function init(args) {
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const nOptions = Object.keys(args).length - 1;
|
|
29
|
+
const nArgs = args['_'].length;
|
|
34
30
|
if (nArgs > 1 || nOptions > options.length) {
|
|
35
31
|
color.error('Incorrect number of arguments and options.');
|
|
36
32
|
return false;
|
|
37
33
|
}
|
|
38
|
-
|
|
34
|
+
const passedOptions = Object.keys(args).slice(1);
|
|
39
35
|
if (nOptions) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var op = _step.value;
|
|
46
|
-
if (!options.includes(op)) {
|
|
47
|
-
if (op !== 'h' && op !== 'help') color.error("Unknown option: ".concat(op));
|
|
48
|
-
hasUnknownOpt = true;
|
|
49
|
-
}
|
|
36
|
+
let hasUnknownOpt = false;
|
|
37
|
+
for (const op of passedOptions) {
|
|
38
|
+
if (!options.includes(op)) {
|
|
39
|
+
if (op !== 'h' && op !== 'help') color.error(`Unknown option: ${op}`);
|
|
40
|
+
hasUnknownOpt = true;
|
|
50
41
|
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
_iterator.e(err);
|
|
53
|
-
} finally {
|
|
54
|
-
_iterator.f();
|
|
55
42
|
}
|
|
56
43
|
if (hasUnknownOpt) return false;
|
|
57
44
|
}
|
|
58
45
|
if (args.git) {
|
|
59
|
-
(0, _child_process.exec)('git config --global pull.rebase false && ' + 'git config --global branch.master.rebase true && ' + 'git config --global branch.main.rebase true && ' + 'git config --global rebase.autostash true',
|
|
46
|
+
(0, _child_process.exec)('git config --global pull.rebase false && ' + 'git config --global branch.master.rebase true && ' + 'git config --global branch.main.rebase true && ' + 'git config --global rebase.autostash true', (err, stdout, stderr) => {
|
|
60
47
|
color.info('Configuring rebase pull strategy...');
|
|
61
48
|
console.log('Read more: https://datagrok.ai/help/develop/advanced/git-policy');
|
|
62
49
|
if (err) throw err;else {
|
|
@@ -64,14 +51,14 @@ function init(args) {
|
|
|
64
51
|
color.success('GIT successfully configured\n');
|
|
65
52
|
}
|
|
66
53
|
});
|
|
67
|
-
(0, _child_process.exec)('npm install --location=global @commitlint/config-conventional @commitlint/cli',
|
|
54
|
+
(0, _child_process.exec)('npm install --location=global @commitlint/config-conventional @commitlint/cli', (err, stdout, stderr) => {
|
|
68
55
|
color.info('Installing @commitlint/config-conventional and @commitlint/cli...');
|
|
69
56
|
if (err) throw err;else console.log(stderr, stdout);
|
|
70
57
|
});
|
|
71
|
-
(0, _child_process.exec)('pip install pre-commit',
|
|
58
|
+
(0, _child_process.exec)('pip install pre-commit', (err, stdout, stderr) => {
|
|
72
59
|
color.info('Installing pre-commit...');
|
|
73
60
|
if (err) throw err;else console.log(stderr, stdout);
|
|
74
|
-
(0, _child_process.exec)('pre-commit install --install-hooks --hook-type pre-commit --hook-type commit-msg',
|
|
61
|
+
(0, _child_process.exec)('pre-commit install --install-hooks --hook-type pre-commit --hook-type commit-msg', (err, stdout, stderr) => {
|
|
75
62
|
color.info('Installing commit hooks...');
|
|
76
63
|
if (err) throw err;else console.log(stderr, stdout);
|
|
77
64
|
});
|
|
@@ -82,11 +69,11 @@ function init(args) {
|
|
|
82
69
|
return false;
|
|
83
70
|
}
|
|
84
71
|
if (args.ts) {
|
|
85
|
-
_fs
|
|
86
|
-
_fs
|
|
87
|
-
|
|
88
|
-
_fs
|
|
89
|
-
|
|
72
|
+
_fs.default.writeFileSync(webpackConfigPath, _fs.default.readFileSync(_path.default.join(templateDir, 'ts.webpack.config.js')));
|
|
73
|
+
_fs.default.writeFileSync(tsConfigPath, _fs.default.readFileSync(_path.default.join(templateDir, 'tsconfig.json')));
|
|
74
|
+
const packageJsPath = _path.default.join(curDir, 'src', 'package.js');
|
|
75
|
+
_fs.default.writeFileSync(_path.default.join(curDir, 'src', 'package.ts'), _fs.default.existsSync(packageJsPath) ? _fs.default.readFileSync(packageJsPath) : _fs.default.readFileSync(_path.default.join(templateDir, 'src', 'package.ts')));
|
|
76
|
+
const packageData = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
90
77
|
Object.assign(packageData.devDependencies, {
|
|
91
78
|
'ts-loader': 'latest',
|
|
92
79
|
'typescript': 'latest'
|
|
@@ -97,97 +84,88 @@ function init(args) {
|
|
|
97
84
|
'@typescript-eslint/parser': 'latest'
|
|
98
85
|
});
|
|
99
86
|
}
|
|
100
|
-
_fs
|
|
87
|
+
_fs.default.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 2), 'utf-8');
|
|
101
88
|
color.success('TypeScript support has been added.');
|
|
102
89
|
}
|
|
103
90
|
if (args.ide) {
|
|
104
|
-
|
|
91
|
+
const config = _jsYaml.default.load(_fs.default.readFileSync(confPath, {
|
|
105
92
|
encoding: 'utf-8'
|
|
106
93
|
}));
|
|
107
|
-
|
|
94
|
+
const confTest = (0, _configValidator.validateConf)(config);
|
|
108
95
|
if (!confTest.value) {
|
|
109
96
|
color.warn('Invalid configuration. Skipping `ide`...');
|
|
110
97
|
color.error(confTest.message);
|
|
111
98
|
}
|
|
112
99
|
if (args.ide === 'vscode') {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (!_fs
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (file === 'tasks.json' && platform !== 'win32') contents = contents.replace(/(?<="command": ").*(?=")/, 'webpack && grok publish #{GROK_HOST_ALIAS}');
|
|
124
|
-
contents = contents.replace(/#{GROK_HOST_ALIAS}/g, config["default"]);
|
|
125
|
-
contents = contents.replace(/#{GROK_HOST}/g, /localhost|127\.0\.0\.1/.test(config['servers'][config["default"]]['url']) ? 'http://localhost:63343/login.html' : new URL(config['servers'][config["default"]]['url']).origin);
|
|
126
|
-
_fs["default"].writeFileSync(_path["default"].join(ideConfPath, file), contents, 'utf-8');
|
|
127
|
-
}
|
|
128
|
-
} catch (err) {
|
|
129
|
-
_iterator2.e(err);
|
|
130
|
-
} finally {
|
|
131
|
-
_iterator2.f();
|
|
100
|
+
const ideConfPath = _path.default.join(curDir, '.vscode');
|
|
101
|
+
const templateConfPath = _path.default.join(templateDir, '.vscode');
|
|
102
|
+
if (!_fs.default.existsSync(ideConfPath)) _fs.default.mkdirSync(ideConfPath);
|
|
103
|
+
const files = _fs.default.readdirSync(templateConfPath);
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
let contents = _fs.default.readFileSync(_path.default.join(templateConfPath, file), 'utf-8');
|
|
106
|
+
if (file === 'tasks.json' && platform !== 'win32') contents = contents.replace(/(?<="command": ").*(?=")/, 'webpack && grok publish #{GROK_HOST_ALIAS}');
|
|
107
|
+
contents = contents.replace(/#{GROK_HOST_ALIAS}/g, config.default);
|
|
108
|
+
contents = contents.replace(/#{GROK_HOST}/g, /localhost|127\.0\.0\.1/.test(config['servers'][config.default]['url']) ? 'http://localhost:63343/login.html' : new URL(config['servers'][config.default]['url']).origin);
|
|
109
|
+
_fs.default.writeFileSync(_path.default.join(ideConfPath, file), contents, 'utf-8');
|
|
132
110
|
}
|
|
133
111
|
color.success('IDE configuration has been added.');
|
|
134
112
|
}
|
|
135
113
|
}
|
|
136
114
|
if (args.eslint) {
|
|
137
|
-
|
|
138
|
-
Object.assign(
|
|
115
|
+
const packageData = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
116
|
+
Object.assign(packageData.devDependencies, {
|
|
139
117
|
'eslint': 'latest',
|
|
140
118
|
'eslint-config-google': 'latest'
|
|
141
119
|
});
|
|
142
|
-
|
|
120
|
+
const ts = _fs.default.existsSync(tsConfigPath);
|
|
143
121
|
if (ts) {
|
|
144
|
-
Object.assign(
|
|
122
|
+
Object.assign(packageData.devDependencies, {
|
|
145
123
|
'@typescript-eslint/eslint-plugin': 'latest',
|
|
146
124
|
'@typescript-eslint/parser': 'latest'
|
|
147
125
|
});
|
|
148
126
|
}
|
|
149
|
-
Object.assign(
|
|
150
|
-
'lint':
|
|
151
|
-
'lint-fix':
|
|
127
|
+
Object.assign(packageData.scripts, {
|
|
128
|
+
'lint': `eslint src${ts ? ' --ext .ts' : ''}`,
|
|
129
|
+
'lint-fix': `eslint src${ts ? ' --ext .ts' : ''} --fix`
|
|
152
130
|
});
|
|
153
|
-
_fs
|
|
154
|
-
|
|
155
|
-
|
|
131
|
+
_fs.default.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 2), 'utf-8');
|
|
132
|
+
const eslintConfigPath = _path.default.join(curDir, '.eslintrc.json');
|
|
133
|
+
const eslintTemplatePath = _path.default.join(templateDir, '.eslintrc.json');
|
|
156
134
|
if (ts) {
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
let contents = _fs.default.readFileSync(eslintTemplatePath, 'utf-8');
|
|
136
|
+
const eslintConf = JSON.parse(contents);
|
|
159
137
|
eslintConf.parser = '@typescript-eslint/parser';
|
|
160
138
|
eslintConf.plugins = ['@typescript-eslint'];
|
|
161
|
-
|
|
162
|
-
_fs
|
|
163
|
-
} else _fs
|
|
139
|
+
contents = JSON.stringify(eslintConf, null, 2);
|
|
140
|
+
_fs.default.writeFileSync(eslintConfigPath, contents, 'utf-8');
|
|
141
|
+
} else _fs.default.writeFileSync(eslintConfigPath, eslintTemplatePath);
|
|
164
142
|
color.success('Linter configuration has been added.');
|
|
165
143
|
}
|
|
166
144
|
if (args.test) {
|
|
167
|
-
|
|
168
|
-
if (!_fs
|
|
169
|
-
|
|
170
|
-
if (!/(?<=entry:\s*{\s*(\r\n|\r|\n))[^}]*test:/.test(
|
|
171
|
-
|
|
145
|
+
const tsPath = _path.default.join(curDir, 'src', 'package.ts');
|
|
146
|
+
if (!_fs.default.existsSync(tsPath)) color.warn('Tests can only be added to TypeScript packages. Skipping `test`...');else if (!_fs.default.existsSync(webpackConfigPath)) color.warn('Webpack configuration not found. Skipping `test`...');else {
|
|
147
|
+
const config = _fs.default.readFileSync(webpackConfigPath, 'utf-8');
|
|
148
|
+
if (!/(?<=entry:\s*{\s*(\r\n|\r|\n))[^}]*test:/.test(config)) {
|
|
149
|
+
const entryIdx = config.search(/(?<=entry:\s*{\s*(\r\n|\r|\n)).*/);
|
|
172
150
|
if (entryIdx === -1) color.error('Entry point not found during webpack config parsing');else {
|
|
173
|
-
|
|
174
|
-
_fs
|
|
151
|
+
const testEntry = ' test: {filename: \'package-test.js\', library: ' + '{type: \'var\', name:`${packageName}_test`}, import: \'./src/package-test.ts\'},';
|
|
152
|
+
_fs.default.writeFileSync(webpackConfigPath, config.slice(0, entryIdx) + testEntry + config.slice(entryIdx), 'utf-8');
|
|
175
153
|
}
|
|
176
154
|
}
|
|
177
|
-
|
|
178
|
-
Object.assign(
|
|
155
|
+
const packageData = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
156
|
+
Object.assign(packageData.dependencies, {
|
|
179
157
|
'@datagrok-libraries/utils': 'latest'
|
|
180
158
|
});
|
|
181
|
-
Object.assign(
|
|
159
|
+
Object.assign(packageData.scripts, {
|
|
182
160
|
'test': 'grok test'
|
|
183
161
|
});
|
|
184
|
-
_fs
|
|
185
|
-
|
|
186
|
-
if (!_fs
|
|
187
|
-
|
|
188
|
-
if (!_fs
|
|
189
|
-
_fs
|
|
190
|
-
_fs
|
|
162
|
+
_fs.default.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 2), 'utf-8');
|
|
163
|
+
const packageTestPath = _path.default.join(curDir, 'src', 'package-test.ts');
|
|
164
|
+
if (!_fs.default.existsSync(packageTestPath)) _fs.default.writeFileSync(packageTestPath, _fs.default.readFileSync(_path.default.join(templateDir, 'src', 'package-test.ts')));
|
|
165
|
+
const testsDir = _path.default.join(curDir, 'src', 'tests');
|
|
166
|
+
if (!_fs.default.existsSync(testsDir)) _fs.default.mkdirSync(testsDir);
|
|
167
|
+
_fs.default.writeFileSync(_path.default.join(testsDir, 'test-examples.ts'), _fs.default.readFileSync(_path.default.join(_path.default.dirname(templateDir), 'entity-template', 'test.ts')));
|
|
168
|
+
_fs.default.writeFileSync(packageTestPath, `import './tests/test-examples';\n` + _fs.default.readFileSync(packageTestPath, 'utf-8'), 'utf-8');
|
|
191
169
|
color.success('Tests support has been added.');
|
|
192
170
|
}
|
|
193
171
|
}
|