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.
@@ -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
  });
@@ -11,67 +10,64 @@ var _path = _interopRequireDefault(require("path"));
11
10
  var _entHelpers = require("../utils/ent-helpers");
12
11
  var utils = _interopRequireWildcard(require("../utils/utils"));
13
12
  var color = _interopRequireWildcard(require("../utils/color-utils"));
14
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
- 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; }
13
+ 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); }
14
+ 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; }
16
15
  function add(args) {
17
- var nOptions = Object.keys(args).length - 1;
18
- var nArgs = args['_'].length;
16
+ const nOptions = Object.keys(args).length - 1;
17
+ const nArgs = args['_'].length;
19
18
  if (nArgs < 2 || nArgs > 5 || nOptions > 0) return false;
20
- var entity = args['_'][1];
21
- var curDir = process.cwd();
22
- var curFolder = _path["default"].basename(curDir);
23
- var srcDir = _path["default"].join(curDir, 'src');
24
- var jsPath = _path["default"].join(srcDir, 'package.js');
25
- var tsPath = _path["default"].join(srcDir, 'package.ts');
26
- var detectorsPath = _path["default"].join(curDir, 'detectors.js');
27
- var webpackConfigPath = _path["default"].join(curDir, 'webpack.config.js');
28
- var scriptsDir = _path["default"].join(curDir, 'scripts');
29
- var queryDir = _path["default"].join(curDir, 'queries');
30
- var queryPath = _path["default"].join(queryDir, 'queries.sql');
31
- var connectDir = _path["default"].join(curDir, 'connections');
32
- var packagePath = _path["default"].join(curDir, 'package.json');
33
- var templateDir = _path["default"].join(_path["default"].dirname(_path["default"].dirname(__dirname)));
19
+ const entity = args['_'][1];
20
+ const curDir = process.cwd();
21
+ const curFolder = _path.default.basename(curDir);
22
+ const srcDir = _path.default.join(curDir, 'src');
23
+ const jsPath = _path.default.join(srcDir, 'package.js');
24
+ const tsPath = _path.default.join(srcDir, 'package.ts');
25
+ const detectorsPath = _path.default.join(curDir, 'detectors.js');
26
+ const webpackConfigPath = _path.default.join(curDir, 'webpack.config.js');
27
+ const scriptsDir = _path.default.join(curDir, 'scripts');
28
+ const queryDir = _path.default.join(curDir, 'queries');
29
+ const queryPath = _path.default.join(queryDir, 'queries.sql');
30
+ const connectDir = _path.default.join(curDir, 'connections');
31
+ const packagePath = _path.default.join(curDir, 'package.json');
32
+ const templateDir = _path.default.join(_path.default.dirname(_path.default.dirname(__dirname)));
34
33
 
35
34
  // Package directory check
36
- if (!_fs["default"].existsSync(packagePath)) return color.error('`package.json` not found');
35
+ if (!_fs.default.existsSync(packagePath)) return color.error('`package.json` not found');
37
36
  try {
38
- JSON.parse(_fs["default"].readFileSync(packagePath, {
37
+ JSON.parse(_fs.default.readFileSync(packagePath, {
39
38
  encoding: 'utf-8'
40
39
  }));
41
40
  } catch (error) {
42
- color.error("Error while reading ".concat(packagePath, ":"));
41
+ color.error(`Error while reading ${packagePath}:`);
43
42
  console.error(error);
44
43
  }
45
44
 
46
45
  // TypeScript package check
47
- var ts = _fs["default"].existsSync(_path["default"].join(curDir, 'tsconfig.json'));
48
- var packageEntry = ts ? tsPath : jsPath;
49
- var ext = ts ? '.ts' : '.js';
46
+ const ts = _fs.default.existsSync(_path.default.join(curDir, 'tsconfig.json'));
47
+ const packageEntry = ts ? tsPath : jsPath;
48
+ const ext = ts ? '.ts' : '.js';
50
49
  function validateName(name) {
51
50
  if (!/^([A-Za-z])+([A-Za-z\d])*$/.test(name)) return color.error('The name may only include letters and numbers. It cannot start with a digit');
52
51
  return true;
53
52
  }
54
53
  function insertName(name, data) {
55
- for (var _i = 0, _arr = ['NAME', 'NAME_TITLECASE', 'NAME_LOWERCASE']; _i < _arr.length; _i++) {
56
- var repl = _arr[_i];
57
- data = utils.replacers[repl](data, name);
58
- }
54
+ for (const repl of ['NAME', 'NAME_TITLECASE', 'NAME_LOWERCASE']) data = utils.replacers[repl](data, name);
59
55
  return data;
60
56
  }
61
57
  function createPackageEntryFile() {
62
- if (!_fs["default"].existsSync(srcDir)) _fs["default"].mkdirSync(srcDir);
63
- if (!_fs["default"].existsSync(packageEntry)) {
64
- var _contents = _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'src', 'package.js'), 'utf8');
65
- _fs["default"].writeFileSync(packageEntry, _contents, 'utf8');
58
+ if (!_fs.default.existsSync(srcDir)) _fs.default.mkdirSync(srcDir);
59
+ if (!_fs.default.existsSync(packageEntry)) {
60
+ const contents = _fs.default.readFileSync(_path.default.join(templateDir, 'package-template', 'src', 'package.js'), 'utf8');
61
+ _fs.default.writeFileSync(packageEntry, contents, 'utf8');
66
62
  }
67
63
  }
68
- var name;
69
- var tag;
70
- var contents;
64
+ let name;
65
+ let tag;
66
+ let contents;
71
67
  switch (entity) {
72
68
  case 'script':
73
69
  if (nArgs < 4 || nArgs > 5) return false;
74
- var lang = args['_'][2];
70
+ let lang = args['_'][2];
75
71
  name = args['_'][3];
76
72
  if (nArgs === 5) {
77
73
  tag = args['_'][2];
@@ -79,7 +75,7 @@ function add(args) {
79
75
  name = args['_'][4];
80
76
  }
81
77
  if (!Object.keys(utils.scriptLangExtMap).includes(lang)) {
82
- color.error("Unsupported language: ".concat(lang));
78
+ color.error(`Unsupported language: ${lang}`);
83
79
  console.log('You can add a script in one of the following languages:');
84
80
  console.log(Object.keys(utils.scriptLangExtMap).join(', '));
85
81
  return false;
@@ -90,19 +86,19 @@ function add(args) {
90
86
  if (tag && tag !== 'panel') return color.error('Currently, you can only add the `panel` tag');
91
87
 
92
88
  // Create the folder `scripts` if it doesn't exist yet
93
- if (!_fs["default"].existsSync(scriptsDir)) _fs["default"].mkdirSync(scriptsDir);
94
- var scriptPath = _path["default"].join(scriptsDir, name + '.' + utils.scriptLangExtMap[lang]);
95
- if (_fs["default"].existsSync(scriptPath)) return color.error("The file with the script already exists: ".concat(scriptPath));
89
+ if (!_fs.default.existsSync(scriptsDir)) _fs.default.mkdirSync(scriptsDir);
90
+ const scriptPath = _path.default.join(scriptsDir, name + '.' + utils.scriptLangExtMap[lang]);
91
+ if (_fs.default.existsSync(scriptPath)) return color.error(`The file with the script already exists: ${scriptPath}`);
96
92
 
97
93
  // Copy the script template
98
- var templatePath = _path["default"].join(templateDir, 'script-template');
99
- templatePath = _path["default"].join(templatePath, lang + '.' + utils.scriptLangExtMap[lang]);
100
- contents = _fs["default"].readFileSync(templatePath, 'utf8');
94
+ let templatePath = _path.default.join(templateDir, 'script-template');
95
+ templatePath = _path.default.join(templatePath, lang + '.' + utils.scriptLangExtMap[lang]);
96
+ contents = _fs.default.readFileSync(templatePath, 'utf8');
101
97
  if (tag) {
102
- var ind = contents.indexOf('tags: ') + 6;
98
+ const ind = contents.indexOf('tags: ') + 6;
103
99
  contents = contents.slice(0, ind) + 'panel, ' + contents.slice(ind);
104
100
  }
105
- _fs["default"].writeFileSync(scriptPath, insertName(name, contents), 'utf8');
101
+ _fs.default.writeFileSync(scriptPath, insertName(name, contents), 'utf8');
106
102
 
107
103
  // Provide a JS wrapper for the script
108
104
  console.log(_entHelpers.help.script(name, curFolder));
@@ -118,8 +114,8 @@ function add(args) {
118
114
  createPackageEntryFile();
119
115
 
120
116
  // Add an app template to package.js
121
- var app = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'app.js'), 'utf8');
122
- _fs["default"].appendFileSync(packageEntry, insertName(name, app));
117
+ const app = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'app.js'), 'utf8');
118
+ _fs.default.appendFileSync(packageEntry, insertName(name, app));
123
119
  console.log(_entHelpers.help.app(name));
124
120
  break;
125
121
  case 'function':
@@ -136,9 +132,9 @@ function add(args) {
136
132
  createPackageEntryFile();
137
133
 
138
134
  // Add a function to package.js
139
- var filename = tag === 'panel' ? 'panel' + ext : tag === 'init' ? 'init.js' : 'function' + ext;
140
- var func = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', filename), 'utf8');
141
- _fs["default"].appendFileSync(packageEntry, insertName(name, func));
135
+ const filename = tag === 'panel' ? 'panel' + ext : tag === 'init' ? 'init.js' : 'function' + ext;
136
+ const func = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', filename), 'utf8');
137
+ _fs.default.appendFileSync(packageEntry, insertName(name, func));
142
138
  console.log(_entHelpers.help.func(name, tag === 'panel'));
143
139
  break;
144
140
  case 'connection':
@@ -149,11 +145,11 @@ function add(args) {
149
145
  if (!validateName(name)) return false;
150
146
 
151
147
  // Create the `connections` folder if it doesn't exist yet
152
- if (!_fs["default"].existsSync(connectDir)) _fs["default"].mkdirSync(connectDir);
153
- var connectPath = _path["default"].join(connectDir, "".concat(name, ".json"));
154
- if (_fs["default"].existsSync(connectPath)) return color.error("The connection file already exists: ".concat(connectPath));
155
- var connectionTemplate = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'connection.json'), 'utf8');
156
- _fs["default"].writeFileSync(connectPath, insertName(name, connectionTemplate), 'utf8');
148
+ if (!_fs.default.existsSync(connectDir)) _fs.default.mkdirSync(connectDir);
149
+ const connectPath = _path.default.join(connectDir, `${name}.json`);
150
+ if (_fs.default.existsSync(connectPath)) return color.error(`The connection file already exists: ${connectPath}`);
151
+ const connectionTemplate = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'connection.json'), 'utf8');
152
+ _fs.default.writeFileSync(connectPath, insertName(name, connectionTemplate), 'utf8');
157
153
  console.log(_entHelpers.help.connection(name));
158
154
  break;
159
155
  case 'query':
@@ -164,27 +160,24 @@ function add(args) {
164
160
  if (!validateName(name)) return false;
165
161
 
166
162
  // Create the `queries` folder if it doesn't exist yet
167
- if (!_fs["default"].existsSync(queryDir)) _fs["default"].mkdirSync(queryDir);
163
+ if (!_fs.default.existsSync(queryDir)) _fs.default.mkdirSync(queryDir);
168
164
 
169
165
  // Add a query to queries.sql
170
- var query = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'queries.sql'), 'utf8');
166
+ const query = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'queries.sql'), 'utf8');
171
167
  contents = insertName(name, query);
172
- var connection;
173
- if (_fs["default"].existsSync(connectDir) && _fs["default"].readdirSync(connectDir).length !== 0) {
174
- var _fs$readdirSync$find;
168
+ let connection;
169
+ if (_fs.default.existsSync(connectDir) && _fs.default.readdirSync(connectDir).length !== 0) {
175
170
  // Use the name of the first found connection
176
- connection = (_fs$readdirSync$find = _fs["default"].readdirSync(connectDir).find(function (c) {
177
- return /.+\.json$/.test(c);
178
- })) === null || _fs$readdirSync$find === void 0 ? void 0 : _fs$readdirSync$find.slice(0, -5);
171
+ connection = _fs.default.readdirSync(connectDir).find(c => /.+\.json$/.test(c))?.slice(0, -5);
179
172
  } else {
180
173
  // Create the default connection file
181
- if (!_fs["default"].existsSync(connectDir)) _fs["default"].mkdirSync(connectDir);
182
- connection = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'connection.json'), 'utf8');
183
- _fs["default"].writeFileSync(_path["default"].join(connectDir, 'connection.json'), insertName('connection', connection), 'utf8');
174
+ if (!_fs.default.existsSync(connectDir)) _fs.default.mkdirSync(connectDir);
175
+ connection = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'connection.json'), 'utf8');
176
+ _fs.default.writeFileSync(_path.default.join(connectDir, 'connection.json'), insertName('connection', connection), 'utf8');
184
177
  connection = 'connection';
185
178
  }
186
179
  contents = contents.replace('#{CONNECTION}', connection);
187
- _fs["default"].appendFileSync(queryPath, contents);
180
+ _fs.default.appendFileSync(queryPath, contents);
188
181
  console.log(_entHelpers.help.query(name));
189
182
  break;
190
183
  case 'view':
@@ -199,17 +192,17 @@ function add(args) {
199
192
  createPackageEntryFile();
200
193
 
201
194
  // Add a new JS file with a view class
202
- var viewPath = _path["default"].join(srcDir, utils.camelCaseToKebab(name) + ext);
203
- if (_fs["default"].existsSync(viewPath)) return color.error("The view file already exists: ".concat(viewPath));
204
- var viewClass = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'view-class' + ext), 'utf8');
205
- _fs["default"].writeFileSync(viewPath, insertName(name, viewClass), 'utf8');
195
+ const viewPath = _path.default.join(srcDir, utils.camelCaseToKebab(name) + ext);
196
+ if (_fs.default.existsSync(viewPath)) return color.error(`The view file already exists: ${viewPath}`);
197
+ const viewClass = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'view-class' + ext), 'utf8');
198
+ _fs.default.writeFileSync(viewPath, insertName(name, viewClass), 'utf8');
206
199
 
207
200
  // Add a view function to package.js
208
- var view = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'view.js'), 'utf8');
209
- contents = insertName(name, "import {#{NAME}} from './".concat(utils.camelCaseToKebab(name), "';\n"));
210
- contents += _fs["default"].readFileSync(packageEntry, 'utf8');
201
+ const view = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'view.js'), 'utf8');
202
+ contents = insertName(name, `import {#{NAME}} from './${utils.camelCaseToKebab(name)}';\n`);
203
+ contents += _fs.default.readFileSync(packageEntry, 'utf8');
211
204
  contents += insertName(name, view);
212
- _fs["default"].writeFileSync(packageEntry, contents, 'utf8');
205
+ _fs.default.writeFileSync(packageEntry, contents, 'utf8');
213
206
  console.log(_entHelpers.help.view(name));
214
207
  break;
215
208
  case 'viewer':
@@ -224,65 +217,62 @@ function add(args) {
224
217
  createPackageEntryFile();
225
218
 
226
219
  // Add a new JS file with a viewer class
227
- var viewerPath = _path["default"].join(srcDir, utils.camelCaseToKebab(name) + ext);
228
- if (_fs["default"].existsSync(viewerPath)) return color.error("The viewer file already exists: ".concat(viewerPath));
229
- var viewerClass = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'viewer-class' + ext), 'utf8');
230
- _fs["default"].writeFileSync(viewerPath, insertName(name, viewerClass), 'utf8');
220
+ const viewerPath = _path.default.join(srcDir, utils.camelCaseToKebab(name) + ext);
221
+ if (_fs.default.existsSync(viewerPath)) return color.error(`The viewer file already exists: ${viewerPath}`);
222
+ const viewerClass = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'viewer-class' + ext), 'utf8');
223
+ _fs.default.writeFileSync(viewerPath, insertName(name, viewerClass), 'utf8');
231
224
  console.log(_entHelpers.help.viewer(name));
232
225
  break;
233
226
  case 'detector':
234
227
  if (nArgs !== 3) return false;
235
228
  name = args['_'][2];
236
- if (!_fs["default"].existsSync(detectorsPath)) {
237
- var temp = _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'detectors.js'), 'utf8');
229
+ if (!_fs.default.existsSync(detectorsPath)) {
230
+ let temp = _fs.default.readFileSync(_path.default.join(templateDir, 'package-template', 'detectors.js'), 'utf8');
238
231
  // eslint-disable-next-line new-cap
239
232
  temp = utils.replacers['PACKAGE_DETECTORS_NAME'](temp, curFolder);
240
- _fs["default"].writeFileSync(detectorsPath, temp, 'utf8');
233
+ _fs.default.writeFileSync(detectorsPath, temp, 'utf8');
241
234
  }
242
- var detector = _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'sem-type-detector.js'), 'utf8');
243
- contents = _fs["default"].readFileSync(detectorsPath, 'utf8');
244
- var idx = contents.search(/(?<=PackageDetectors extends DG.Package\s*{\s*(\r\n|\r|\n)).*/);
235
+ const detector = _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'sem-type-detector.js'), 'utf8');
236
+ contents = _fs.default.readFileSync(detectorsPath, 'utf8');
237
+ const idx = contents.search(/(?<=PackageDetectors extends DG.Package\s*{\s*(\r\n|\r|\n)).*/);
245
238
  if (idx === -1) return color.error('Detectors class not found');
246
239
  contents = contents.slice(0, idx) + detector + contents.slice(idx);
247
- for (var _i2 = 0, _arr2 = ['NAME', 'NAME_PREFIX', 'PACKAGE_DETECTORS_NAME']; _i2 < _arr2.length; _i2++) {
248
- var repl = _arr2[_i2];
249
- contents = utils.replacers[repl](contents, name);
250
- }
251
- _fs["default"].writeFileSync(detectorsPath, contents, 'utf8');
240
+ for (const repl of ['NAME', 'NAME_PREFIX', 'PACKAGE_DETECTORS_NAME']) contents = utils.replacers[repl](contents, name);
241
+ _fs.default.writeFileSync(detectorsPath, contents, 'utf8');
252
242
  console.log(_entHelpers.help.detector(name));
253
243
  break;
254
244
  case 'tests':
255
- if (!_fs["default"].existsSync(tsPath)) {
245
+ if (!_fs.default.existsSync(tsPath)) {
256
246
  color.error('Only TypeScript packages are supported');
257
247
  return false;
258
248
  }
259
- if (!_fs["default"].existsSync(webpackConfigPath)) {
249
+ if (!_fs.default.existsSync(webpackConfigPath)) {
260
250
  color.error('Webpack configuration not found');
261
251
  return false;
262
252
  }
263
- var config = _fs["default"].readFileSync(webpackConfigPath, 'utf8');
253
+ const config = _fs.default.readFileSync(webpackConfigPath, 'utf8');
264
254
  if (!/(?<=entry:\s*{\s*(\r\n|\r|\n))[^}]*test:/.test(config)) {
265
- var entryIdx = config.search(/(?<=entry:\s*{\s*(\r\n|\r|\n)).*/);
255
+ const entryIdx = config.search(/(?<=entry:\s*{\s*(\r\n|\r|\n)).*/);
266
256
  if (entryIdx === -1) return color.error('Entry point not found during config parsing');
267
- var testEntry = ' test: {filename: \'package-test.js\', library: ' + '{type: \'var\', name:`${packageName}_test`}, import: \'./src/package-test.ts\'},';
268
- _fs["default"].writeFileSync(webpackConfigPath, config.slice(0, entryIdx) + testEntry + config.slice(entryIdx), 'utf8');
257
+ const testEntry = ' test: {filename: \'package-test.js\', library: ' + '{type: \'var\', name:`${packageName}_test`}, import: \'./src/package-test.ts\'},';
258
+ _fs.default.writeFileSync(webpackConfigPath, config.slice(0, entryIdx) + testEntry + config.slice(entryIdx), 'utf8');
269
259
  }
270
- var packageObj = JSON.parse(_fs["default"].readFileSync(packagePath, 'utf8'));
260
+ const packageObj = JSON.parse(_fs.default.readFileSync(packagePath, 'utf8'));
271
261
  Object.assign(packageObj.dependencies, {
272
262
  '@datagrok-libraries/utils': 'latest'
273
263
  });
274
264
  Object.assign(packageObj.scripts, {
275
265
  'test': 'grok test'
276
266
  });
277
- _fs["default"].writeFileSync(packagePath, JSON.stringify(packageObj, null, 2), 'utf8');
278
- var packageTestPath = _path["default"].join(srcDir, 'package-test.ts');
279
- if (!_fs["default"].existsSync(packageTestPath)) {
280
- _fs["default"].writeFileSync(packageTestPath, _fs["default"].readFileSync(_path["default"].join(templateDir, 'package-template', 'src', 'package-test.ts')));
267
+ _fs.default.writeFileSync(packagePath, JSON.stringify(packageObj, null, 2), 'utf8');
268
+ const packageTestPath = _path.default.join(srcDir, 'package-test.ts');
269
+ if (!_fs.default.existsSync(packageTestPath)) {
270
+ _fs.default.writeFileSync(packageTestPath, _fs.default.readFileSync(_path.default.join(templateDir, 'package-template', 'src', 'package-test.ts')));
281
271
  }
282
- var testsDir = _path["default"].join(srcDir, 'tests');
283
- if (!_fs["default"].existsSync(testsDir)) _fs["default"].mkdirSync(testsDir);
284
- _fs["default"].writeFileSync(_path["default"].join(testsDir, 'test-examples.ts'), _fs["default"].readFileSync(_path["default"].join(templateDir, 'entity-template', 'test.ts')));
285
- _fs["default"].writeFileSync(packageTestPath, "import './tests/test-examples';\n" + _fs["default"].readFileSync(packageTestPath));
272
+ const testsDir = _path.default.join(srcDir, 'tests');
273
+ if (!_fs.default.existsSync(testsDir)) _fs.default.mkdirSync(testsDir);
274
+ _fs.default.writeFileSync(_path.default.join(testsDir, 'test-examples.ts'), _fs.default.readFileSync(_path.default.join(templateDir, 'entity-template', 'test.ts')));
275
+ _fs.default.writeFileSync(packageTestPath, `import './tests/test-examples';\n` + _fs.default.readFileSync(packageTestPath));
286
276
  console.log(_entHelpers.help.test(testsDir));
287
277
  break;
288
278
  default:
@@ -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
  });
@@ -11,140 +10,99 @@ var _path = _interopRequireDefault(require("path"));
11
10
  var _ignoreWalk = _interopRequireDefault(require("ignore-walk"));
12
11
  var utils = _interopRequireWildcard(require("../utils/utils"));
13
12
  var color = _interopRequireWildcard(require("../utils/color-utils"));
14
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
- 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; }
16
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
17
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ 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); }
14
+ 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; }
19
15
  function generateQueryWrappers() {
20
- var curDir = process.cwd();
21
- var queriesDir = _path["default"].join(curDir, 'queries');
22
- if (!_fs["default"].existsSync(queriesDir)) {
23
- color.warn("Directory ".concat(queriesDir, " not found"));
16
+ const curDir = process.cwd();
17
+ const queriesDir = _path.default.join(curDir, 'queries');
18
+ if (!_fs.default.existsSync(queriesDir)) {
19
+ color.warn(`Directory ${queriesDir} not found`);
24
20
  console.log('Skipping API generation for queries...');
25
21
  return;
26
22
  }
27
- var packagePath = _path["default"].join(curDir, 'package.json');
28
- var _package = JSON.parse(_fs["default"].readFileSync(packagePath, {
23
+ const packagePath = _path.default.join(curDir, 'package.json');
24
+ const _package = JSON.parse(_fs.default.readFileSync(packagePath, {
29
25
  encoding: 'utf-8'
30
26
  }));
31
- var files = _ignoreWalk["default"].sync({
27
+ const files = _ignoreWalk.default.sync({
32
28
  path: './queries',
33
29
  ignoreFiles: ['.npmignore', '.gitignore']
34
30
  });
35
- var wrappers = [];
36
- var _iterator = _createForOfIteratorHelper(files),
37
- _step;
38
- try {
39
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
40
- var file = _step.value;
41
- if (!file.endsWith(utils.queryExtension)) continue;
42
- var filepath = _path["default"].join(queriesDir, file);
43
- var script = _fs["default"].readFileSync(filepath, 'utf8');
44
- if (!script) continue;
45
- var queries = script.split('--end').map(function (q) {
46
- return q.trim();
47
- }).filter(function (q) {
48
- return q.length > 0;
49
- });
50
- var _iterator2 = _createForOfIteratorHelper(queries),
51
- _step2;
52
- try {
53
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
54
- var q = _step2.value;
55
- var name = utils.getScriptName(q, utils.commentMap[utils.queryExtension]);
56
- if (!name) continue;
57
- var tb = new utils.TemplateBuilder(utils.queryWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
58
- var inputs = utils.getScriptInputs(q, utils.commentMap[utils.queryExtension]);
59
- var outputType = utils.getScriptOutputType(q, utils.commentMap[utils.queryExtension]);
60
- tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs)
61
- // The query output, if omitted, is a dataframe
62
- .replace('OUTPUT_TYPE', outputType === 'void' ? utils.dgToTsTypeMap['dataframe'] : outputType);
63
- wrappers.push(tb.build());
64
- }
65
- } catch (err) {
66
- _iterator2.e(err);
67
- } finally {
68
- _iterator2.f();
69
- }
31
+ const wrappers = [];
32
+ for (const file of files) {
33
+ if (!file.endsWith(utils.queryExtension)) continue;
34
+ const filepath = _path.default.join(queriesDir, file);
35
+ const script = _fs.default.readFileSync(filepath, 'utf8');
36
+ if (!script) continue;
37
+ const queries = script.split('--end').map(q => q.trim()).filter(q => q.length > 0);
38
+ for (const q of queries) {
39
+ const name = utils.getScriptName(q, utils.commentMap[utils.queryExtension]);
40
+ if (!name) continue;
41
+ const tb = new utils.TemplateBuilder(utils.queryWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
42
+ const inputs = utils.getScriptInputs(q, utils.commentMap[utils.queryExtension]);
43
+ const outputType = utils.getScriptOutputType(q, utils.commentMap[utils.queryExtension]);
44
+ tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs)
45
+ // The query output, if omitted, is a dataframe
46
+ .replace('OUTPUT_TYPE', outputType === 'void' ? utils.dgToTsTypeMap['dataframe'] : outputType);
47
+ wrappers.push(tb.build());
70
48
  }
71
- } catch (err) {
72
- _iterator.e(err);
73
- } finally {
74
- _iterator.f();
75
49
  }
76
- var srcDir = _path["default"].join(curDir, 'src');
77
- var queryFileName = 'queries-api.ts';
78
- var queryFilePath = _path["default"].join(_fs["default"].existsSync(srcDir) ? srcDir : curDir, queryFileName);
79
- if (_fs["default"].existsSync(queryFilePath)) {
80
- color.warn("The file ".concat(queryFilePath, " already exists"));
50
+ const srcDir = _path.default.join(curDir, 'src');
51
+ const queryFileName = 'queries-api.ts';
52
+ const queryFilePath = _path.default.join(_fs.default.existsSync(srcDir) ? srcDir : curDir, queryFileName);
53
+ if (_fs.default.existsSync(queryFilePath)) {
54
+ color.warn(`The file ${queryFilePath} already exists`);
81
55
  console.log('Rewriting its contents...');
82
56
  }
83
- var sep = '\n';
84
- _fs["default"].writeFileSync(queryFilePath, utils.dgImports + sep + wrappers.join(sep.repeat(2)) + sep, 'utf8');
85
- color.success("Successfully generated file ".concat(queryFileName).concat(sep));
57
+ const sep = '\n';
58
+ _fs.default.writeFileSync(queryFilePath, utils.dgImports + sep + wrappers.join(sep.repeat(2)) + sep, 'utf8');
59
+ color.success(`Successfully generated file ${queryFileName}${sep}`);
86
60
  }
87
61
  function generateScriptWrappers() {
88
- var curDir = process.cwd();
89
- var scriptsDir = _path["default"].join(curDir, 'scripts');
90
- if (!_fs["default"].existsSync(scriptsDir)) {
91
- color.warn("Directory ".concat(scriptsDir, " not found"));
62
+ const curDir = process.cwd();
63
+ const scriptsDir = _path.default.join(curDir, 'scripts');
64
+ if (!_fs.default.existsSync(scriptsDir)) {
65
+ color.warn(`Directory ${scriptsDir} not found`);
92
66
  console.log('Skipping API generation for scripts...');
93
67
  return;
94
68
  }
95
- var packagePath = _path["default"].join(curDir, 'package.json');
96
- var _package = JSON.parse(_fs["default"].readFileSync(packagePath, {
69
+ const packagePath = _path.default.join(curDir, 'package.json');
70
+ const _package = JSON.parse(_fs.default.readFileSync(packagePath, {
97
71
  encoding: 'utf-8'
98
72
  }));
99
- var files = _ignoreWalk["default"].sync({
73
+ const files = _ignoreWalk.default.sync({
100
74
  path: './scripts',
101
75
  ignoreFiles: ['.npmignore', '.gitignore']
102
76
  });
103
- var wrappers = [];
104
- var _iterator3 = _createForOfIteratorHelper(files),
105
- _step3;
106
- try {
107
- var _loop = function _loop() {
108
- var file = _step3.value;
109
- var extension;
110
- if (!utils.scriptExtensions.some(function (ext) {
111
- return extension = ext, file.endsWith(ext);
112
- })) return 0; // continue
113
- var filepath = _path["default"].join(scriptsDir, file);
114
- var script = _fs["default"].readFileSync(filepath, 'utf8');
115
- if (!script) return 0; // continue
116
- var name = utils.getScriptName(script, utils.commentMap[extension]);
117
- if (!name) return 0; // continue
118
- var tb = new utils.TemplateBuilder(utils.scriptWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
119
- var inputs = utils.getScriptInputs(script);
120
- var outputType = utils.getScriptOutputType(script);
121
- tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs).replace('OUTPUT_TYPE', outputType);
122
- wrappers.push(tb.build(1));
123
- },
124
- _ret;
125
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
126
- _ret = _loop();
127
- if (_ret === 0) continue;
128
- }
129
- } catch (err) {
130
- _iterator3.e(err);
131
- } finally {
132
- _iterator3.f();
77
+ const wrappers = [];
78
+ for (const file of files) {
79
+ let extension;
80
+ if (!utils.scriptExtensions.some(ext => (extension = ext, file.endsWith(ext)))) continue;
81
+ const filepath = _path.default.join(scriptsDir, file);
82
+ const script = _fs.default.readFileSync(filepath, 'utf8');
83
+ if (!script) continue;
84
+ const name = utils.getScriptName(script, utils.commentMap[extension]);
85
+ if (!name) continue;
86
+ const tb = new utils.TemplateBuilder(utils.scriptWrapperTemplate).replace('FUNC_NAME', name).replace('FUNC_NAME_LOWERCASE', name).replace('PACKAGE_NAMESPACE', _package.name);
87
+ const inputs = utils.getScriptInputs(script);
88
+ const outputType = utils.getScriptOutputType(script);
89
+ tb.replace('PARAMS_OBJECT', inputs).replace('TYPED_PARAMS', inputs).replace('OUTPUT_TYPE', outputType);
90
+ wrappers.push(tb.build(1));
133
91
  }
134
- var srcDir = _path["default"].join(curDir, 'src');
135
- var funcFileName = 'scripts-api.ts';
136
- var funcFilePath = _path["default"].join(_fs["default"].existsSync(srcDir) ? srcDir : curDir, funcFileName);
137
- if (_fs["default"].existsSync(funcFilePath)) {
138
- color.warn("The file ".concat(funcFilePath, " already exists"));
92
+ const srcDir = _path.default.join(curDir, 'src');
93
+ const funcFileName = 'scripts-api.ts';
94
+ const funcFilePath = _path.default.join(_fs.default.existsSync(srcDir) ? srcDir : curDir, funcFileName);
95
+ if (_fs.default.existsSync(funcFilePath)) {
96
+ color.warn(`The file ${funcFilePath} already exists`);
139
97
  console.log('Rewriting its contents...');
140
98
  }
141
- var sep = '\n';
142
- var scriptApi = new utils.TemplateBuilder(utils.namespaceTemplate).replace('PACKAGE_NAMESPACE', _package.name).replace('NAME', wrappers.join(sep.repeat(2)));
143
- _fs["default"].writeFileSync(funcFilePath, utils.dgImports + sep + scriptApi.build() + sep, 'utf8');
144
- color.success("Successfully generated file ".concat(funcFileName).concat(sep));
99
+ const sep = '\n';
100
+ const scriptApi = new utils.TemplateBuilder(utils.namespaceTemplate).replace('PACKAGE_NAMESPACE', _package.name).replace('NAME', wrappers.join(sep.repeat(2)));
101
+ _fs.default.writeFileSync(funcFilePath, utils.dgImports + sep + scriptApi.build() + sep, 'utf8');
102
+ color.success(`Successfully generated file ${funcFileName}${sep}`);
145
103
  }
146
104
  function api(args) {
147
- var nOptions = Object.keys(args).length - 1;
105
+ const nOptions = Object.keys(args).length - 1;
148
106
  if (args['_'].length !== 1 || nOptions > 0) return false;
149
107
  if (!utils.isPackageDir(process.cwd())) {
150
108
  color.error('File `package.json` not found. Run the command from the package directory');