datagrok-tools 4.14.30 → 4.14.31

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/grok.js CHANGED
@@ -26,12 +26,10 @@ if (command in commands) {
26
26
  if (argv['help']) {
27
27
  console.log(help[command]);
28
28
  exitWithCode(1);
29
- }
30
- else if (argv.all && onPackageCommandNames.includes(command)) {
29
+ } else if (argv.all && onPackageCommandNames.includes(command)) {
31
30
  runAllCommand(process.cwd(),
32
31
  `grok ${process.argv.slice(2).join(' ')}`.replace('--all', ''), {});
33
- }
34
- else if (!commands[command](argv)) {
32
+ } else if (!commands[command](argv)) {
35
33
  console.log(help[command]);
36
34
  exitWithCode(1);
37
35
  }
@@ -20,7 +20,7 @@ let pseudoParams = exports.pseudoParams = /*#__PURE__*/function (pseudoParams) {
20
20
  pseudoParams["INPUT_TYPE"] = "inputType";
21
21
  return pseudoParams;
22
22
  }({});
23
- const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl'];
23
+ const nonMetaData = ['sidebar', 'editor', 'friendlyName', 'helpUrl', 'condition', 'top-menu', 'cache', 'cache.invalidateOn'];
24
24
  const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
25
25
  const dgAnnotationTypes = exports.dgAnnotationTypes = {
26
26
  INT: 'int',
@@ -145,17 +145,23 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
145
145
  } else type = 'dynamic';
146
146
  const options = input?.options?.options ? buildStringOfOptions(input.options.options ?? {}) : '';
147
147
  const functionName = (input.options?.name ? input?.options?.name : ` ${input.name?.replaceAll('.', '')}`)?.trim();
148
+
149
+ // eslint-disable-next-line max-len
148
150
  s += comment + 'input: ' + type + ' ' + functionName + (input.defaultValue !== undefined ? `= ${input.defaultValue}` : '') + ' ' + options.replaceAll('"', '\'') + sep;
149
151
  }
150
152
  if (data.outputs) {
151
153
  for (const output of data.outputs) {
152
- if (output.type !== 'void') s += comment + 'output: ' + output.type + (output.name ? ` ${output.name}${output.options ? ` ${buildStringOfOptions(output.options)}` : ''}` : '') + sep;
154
+ if (output.type !== 'void') {
155
+ // eslint-disable-next-line max-len
156
+ s += comment + 'output: ' + output.type + (output.name ? ` ${output.name}${output.options ? ` ${buildStringOfOptions(output.options)}` : ''}` : '') + sep;
157
+ }
153
158
  }
154
159
  }
155
160
  if (data.meta) {
156
161
  for (const entry of Object.entries(data.meta)) s += `${comment}meta.${entry[0]}: ${entry[1]}${sep}`;
157
162
  }
158
163
  for (const parameter in data) {
164
+ // eslint-disable-next-line max-len
159
165
  if (parameter === pseudoParams.EXTENSION || parameter === pseudoParams.INPUT_TYPE || parameter === 'meta' || parameter === 'isAsync' || parameter === 'test') continue;else if (parameter === pseudoParams.EXTENSIONS) {
160
166
  if (isFileViewer) continue;
161
167
  s += `${comment}meta.ext: ${data[parameter]}${sep}`;
@@ -431,8 +437,11 @@ const primitives = new Set(['string', 'string[]', 'number', 'number[]', 'boolean
431
437
 
432
438
  /** Generates a DG function. */
433
439
  function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
440
+ // eslint-disable-next-line max-len
434
441
  const funcSigNature = inputs.map(e => `${e.name}: ${primitives.has(e.type ?? '') && !typesToAny.includes(e.type ?? '') ? e.type : typesToAnnotation[e.type?.replace('[]', '') ?? ''] && !typesToAny.includes(e.type ?? '') ? e.type : 'any'}`).join(', ');
435
442
  const funcArguments = inputs.map(e => e.name).join(', ');
443
+
444
+ // eslint-disable-next-line max-len
436
445
  return sep + annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep}`;
437
446
  }
438
447
  function generateImport(className, path, sep = '\n') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.14.30",
3
+ "version": "4.14.31",
4
4
  "description": "Utility to upload and publish packages to Datagrok",
5
5
  "homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
6
6
  "dependencies": {
@@ -1,8 +1,8 @@
1
- const fs = require("fs");
2
- const path = require("path");
1
+ const fs = require('fs');
2
+ const path = require('path');
3
3
 
4
- const tsParser = require("@typescript-eslint/typescript-estree");
5
- const generate = require("@babel/generator").default;
4
+ const tsParser = require('@typescript-eslint/typescript-estree');
5
+ const generate = require('@babel/generator').default;
6
6
 
7
7
  const {
8
8
  reservedDecorators,
@@ -11,48 +11,49 @@ const {
11
11
  generateExport,
12
12
  typesToAnnotation,
13
13
  dgAnnotationTypes,
14
- } = require("../bin/utils/func-generation");
14
+ } = require('../bin/utils/func-generation');
15
15
 
16
- const baseImport = "import * as DG from 'datagrok-api/dg';\n";
16
+ const baseImport = 'import * as DG from \'datagrok-api/dg\';\n';
17
+ // eslint-disable-next-line max-len
17
18
  const annotationForGeneratedFile = `/**\nThis file is auto-generated by the webpack command.\nIf you notice any changes, please push them to the repository.\nDo not edit this file manually.\n*/\n`;
18
19
 
19
20
  class FuncGeneratorPlugin {
20
- constructor(options = { outputPath: "./src/package.g.ts" }) {
21
+ constructor(options = {outputPath: './src/package.g.ts'}) {
21
22
  this.options = options;
22
23
  }
23
24
 
24
25
  apply(compiler) {
25
- const srcDirPath = path.join(compiler.context, "src");
26
- let packageFilePath = path.join(srcDirPath, "package.ts");
26
+ const srcDirPath = path.join(compiler.context, 'src');
27
+ let packageFilePath = path.join(srcDirPath, 'package.ts');
27
28
  if (!fs.existsSync(packageFilePath))
28
- packageFilePath = path.join(srcDirPath, "package.js");
29
+ packageFilePath = path.join(srcDirPath, 'package.js');
29
30
  const tsFiles = this._getTsFiles(srcDirPath);
30
31
  const genImports = [];
31
32
  const genExports = [];
32
33
 
33
- compiler.hooks.compilation.tap("FuncGeneratorPlugin", (_compilation) => {
34
+ compiler.hooks.compilation.tap('FuncGeneratorPlugin', (_compilation) => {
34
35
  this._clearGeneratedFile();
35
36
 
36
37
  for (const file of tsFiles) {
37
- const content = fs.readFileSync(file, "utf-8");
38
- if (!content.includes("@grok.decorators.")) continue;
38
+ const content = fs.readFileSync(file, 'utf-8');
39
+ if (!content.includes('@grok.decorators.')) continue;
39
40
 
40
41
  if (!content) continue;
41
42
  const ast = tsParser.parse(content, {
42
- sourceType: "module",
43
+ sourceType: 'module',
43
44
  plugins: [
44
- ["decorators", { decoratorsBeforeExport: true }],
45
- "classProperties",
46
- "typescript",
45
+ ['decorators', {decoratorsBeforeExport: true}],
46
+ 'classProperties',
47
+ 'typescript',
47
48
  ],
48
49
  });
49
50
  const functions = [];
50
- let imports = new Set();
51
+ const imports = new Set();
51
52
  this._walk(ast, (node, parentClass) => {
52
53
  const decorators = node.decorators;
53
54
  if (!decorators || decorators.length === 0) return;
54
55
 
55
- if (node?.type === "ClassDeclaration")
56
+ if (node?.type === 'ClassDeclaration') {
56
57
  this._addNodeData(
57
58
  node,
58
59
  file,
@@ -60,10 +61,11 @@ class FuncGeneratorPlugin {
60
61
  functions,
61
62
  imports,
62
63
  genImports,
63
- genExports
64
+ genExports,
64
65
  );
66
+ }
65
67
 
66
- if (node?.type === "MethodDefinition")
68
+ if (node?.type === 'MethodDefinition') {
67
69
  this._addNodeData(
68
70
  node,
69
71
  file,
@@ -72,11 +74,12 @@ class FuncGeneratorPlugin {
72
74
  imports,
73
75
  genImports,
74
76
  genExports,
75
- parentClass
77
+ parentClass,
76
78
  );
79
+ }
77
80
  });
78
81
  this._insertImports([...imports]);
79
- fs.appendFileSync(this.options.outputPath, functions.join(""), "utf-8");
82
+ fs.appendFileSync(this.options.outputPath, functions.join(''), 'utf-8');
80
83
  }
81
84
  this._checkPackageFileForDecoratorsExport(packageFilePath);
82
85
  // Uncommment to add obvious import/export
@@ -92,7 +95,7 @@ class FuncGeneratorPlugin {
92
95
  imports,
93
96
  genImports,
94
97
  genExports,
95
- parent = undefined
98
+ parent = undefined,
96
99
  ) {
97
100
  if (
98
101
  !node.decorators ||
@@ -105,7 +108,7 @@ class FuncGeneratorPlugin {
105
108
  const relativePath = path.relative(dirPath, filePath);
106
109
  return `./${relativePath
107
110
  .slice(0, relativePath.length - 3)
108
- .replace(/\\/g, "/")}`;
111
+ .replace(/\\/g, '/')}`;
109
112
  }
110
113
 
111
114
  const decorator = node.decorators[0];
@@ -117,57 +120,57 @@ class FuncGeneratorPlugin {
117
120
  if (!name) return;
118
121
 
119
122
  const decoratorOptions = this._readDecoratorOptions(
120
- exp.arguments[0].properties
123
+ exp.arguments[0].properties,
121
124
  );
122
125
 
123
- decoratorOptions.set("tags", [
124
- ...(reservedDecorators[name]["metadata"]["tags"] ?? []),
125
- ...(decoratorOptions.get("tags") ?? []),
126
+ decoratorOptions.set('tags', [
127
+ ...(reservedDecorators[name]['metadata']['tags'] ?? []),
128
+ ...(decoratorOptions.get('tags') ?? []),
126
129
  ]);
127
130
  const functionParams =
128
- node?.type === "MethodDefinition" ? this._readMethodParamas(node) : [];
129
- const annotationByReturnObj = node?.type === "MethodDefinition" ? this._readOutputsFromReturnType(node) : undefined;
131
+ node?.type === 'MethodDefinition' ? this._readMethodParamas(node) : [];
132
+ const annotationByReturnObj = node?.type === 'MethodDefinition' ? this._readOutputsFromReturnType(node) : undefined;
130
133
  const isMethodAsync = this._isMethodAsync(node);
131
- let importString = generateImport(
132
- node?.type === "MethodDefinition" ? className : identifierName,
133
- modifyImportPath(path.dirname(this.options.outputPath), file)
134
+ const importString = generateImport(
135
+ node?.type === 'MethodDefinition' ? className : identifierName,
136
+ modifyImportPath(path.dirname(this.options.outputPath), file),
134
137
  );
135
138
  imports.add(importString);
136
139
  const funcName = `${
137
- node?.type === "MethodDefinition" ? "" : "_"
140
+ node?.type === 'MethodDefinition' ? '' : '_'
138
141
  }${identifierName}`;
139
142
  const funcAnnotaionOptions = {
140
- ...reservedDecorators[name]["metadata"],
141
- ...(annotationByReturnObj
142
- ? { outputs: annotationByReturnObj ?? [] }
143
- : {}),
143
+ ...reservedDecorators[name]['metadata'],
144
+ ...(annotationByReturnObj ?
145
+ {outputs: annotationByReturnObj ?? []} :
146
+ {}),
144
147
  ...Object.fromEntries(decoratorOptions),
145
- ...{ inputs: functionParams },
146
- ...{ isAsync: isMethodAsync },
148
+ ...{inputs: functionParams},
149
+ ...{isAsync: isMethodAsync},
147
150
  };
148
151
  if (!funcAnnotaionOptions.name) funcAnnotaionOptions.name = identifierName;
149
152
  functions.push(
150
- reservedDecorators[name]["genFunc"](
153
+ reservedDecorators[name]['genFunc'](
151
154
  getFuncAnnotation(funcAnnotaionOptions),
152
155
  identifierName,
153
- "\n",
154
- className ?? "",
156
+ '\n',
157
+ className ?? '',
155
158
  functionParams,
156
- funcAnnotaionOptions.isAsync ?? false
157
- )
159
+ funcAnnotaionOptions.isAsync ?? false,
160
+ ),
158
161
  );
159
162
  genImports.push(
160
163
  generateImport(
161
164
  funcName,
162
- modifyImportPath(srcDirPath, this.options.outputPath)
163
- )
165
+ modifyImportPath(srcDirPath, this.options.outputPath),
166
+ ),
164
167
  );
165
168
  genExports.push(generateExport(funcName));
166
169
  }
167
170
 
168
171
  _isMethodAsync(node) {
169
172
  let result = false;
170
- if (node.type === "MethodDefinition") result = node.value.async;
173
+ if (node.type === 'MethodDefinition') result = node.value.async;
171
174
  return result;
172
175
  }
173
176
 
@@ -176,86 +179,88 @@ class FuncGeneratorPlugin {
176
179
  const results = [];
177
180
 
178
181
  let match;
179
- while ((match = importRegex.exec(content)) !== null) {
182
+ while ((match = importRegex.exec(content)) !== null)
180
183
  results.push(`${match[1]}\n`);
181
- }
184
+
182
185
  return results;
183
186
  }
184
187
 
185
188
  _readDecoratorOptions(properties) {
186
189
  const resultMap = new Map();
190
+ console.log(properties);
187
191
 
188
- for (let prop of properties)
189
- resultMap.set(prop.key.name, this._evalLiteral(prop.value));
192
+ for (const prop of properties)
193
+ resultMap.set(prop.key.name ?? prop.key.value, this._evalLiteral(prop.value));
190
194
  return resultMap;
191
195
  }
192
196
 
193
197
  _evalLiteral(node) {
194
198
  if (!node) return null;
195
199
  switch (node.type) {
196
- case "Literal":
197
- return node.value;
200
+ case 'Literal':
201
+ return node.value;
198
202
 
199
- case "ArrayExpression":
200
- return node.elements.map((el) => this._evalLiteral(el));
203
+ case 'ArrayExpression':
204
+ return node.elements.map((el) => this._evalLiteral(el));
201
205
 
202
- case "MemberExpression":
203
- return dgAnnotationTypes[node?.property?.name ?? ""] ?? "dynamic";
206
+ case 'MemberExpression':
207
+ return dgAnnotationTypes[node?.property?.name ?? ''] ?? 'dynamic';
204
208
 
205
- case "ObjectExpression":
206
- return Object.fromEntries(
207
- node.properties.map((p) => {
208
- return [p.key.name || p.key.value, this._evalLiteral(p.value)];
209
- })
210
- );
209
+ case 'ObjectExpression':
210
+ return Object.fromEntries(
211
+ node.properties.map((p) => {
212
+ return [p.key.name || p.key.value, this._evalLiteral(p.value)];
213
+ }),
214
+ );
211
215
 
212
- default:
213
- return "";
216
+ default:
217
+ return '';
214
218
  }
215
219
  }
216
220
 
217
221
  _readMethodParamas(node) {
218
222
  const params = node?.value?.params?.map((param) => {
219
223
  let baseParam =
220
- param.type === "TSNonNullExpression" ? param.expression : param;
224
+ param.type === 'TSNonNullExpression' ? param.expression : param;
221
225
  const options =
222
- param.decorators?.length > 0
223
- ? Object.fromEntries(
224
- this._readDecoratorOptions(
225
- param.decorators[0]?.expression?.arguments[0].properties
226
- )
227
- )
228
- : undefined;
226
+ param.decorators?.length > 0 ?
227
+ Object.fromEntries(
228
+ this._readDecoratorOptions(
229
+ param.decorators[0]?.expression?.arguments[0].properties,
230
+ ),
231
+ ) :
232
+ undefined;
229
233
 
230
234
  // Commented code finds value by default of function's variable
231
235
  // let defaultValue = undefined;
232
- if (baseParam.type === "AssignmentPattern") {
236
+ if (baseParam.type === 'AssignmentPattern') {
233
237
  // if (baseParam?.right?.type === 'Literal')
234
238
  // defaultValue = baseParam?.right?.raw;
235
239
  baseParam = baseParam?.left;
236
240
  }
237
241
 
238
- if (baseParam.type === "RestElement" || baseParam.type === "Identifier") {
242
+ if (baseParam.type === 'RestElement' || baseParam.type === 'Identifier') {
239
243
  let name =
240
- baseParam.type === "RestElement"
241
- ? `...${baseParam.argument.name}`
242
- : baseParam.name;
243
- if (baseParam?.argument?.typeAnnotation)
244
+ baseParam.type === 'RestElement' ?
245
+ `...${baseParam.argument.name}` :
246
+ baseParam.name;
247
+ if (baseParam?.argument?.typeAnnotation) {
244
248
  name +=
245
- ": " +
249
+ ': ' +
246
250
  generate(baseParam.argument.typeAnnotation.typeAnnotation).code;
251
+ }
247
252
 
248
- let type = "";
253
+ let type = '';
249
254
  if (baseParam?.typeAnnotation?.typeAnnotation)
250
255
  type = generate(baseParam.typeAnnotation.typeAnnotation).code;
251
- else type = "any";
256
+ else type = 'any';
252
257
 
253
- let params =
258
+ const params =
254
259
  baseParam.typeAnnotation.typeAnnotation.typeArguments?.params;
255
- if (type !== "any" && params && params.length > 0)
256
- type += `<${params.map((e) => e.typeName?.name ?? 'any').join(",")}>`;
260
+ if (type !== 'any' && params && params.length > 0)
261
+ type += `<${params.map((e) => e.typeName?.name ?? 'any').join(',')}>`;
257
262
 
258
- return { name: name, type: type, options: options };
263
+ return {name: name, type: type, options: options};
259
264
  }
260
265
  // Commented code belove sets more strong types for ObjectPatterns and ArrayPatterns
261
266
  // else if (baseParam.type === 'ObjectPattern' || baseParam.type === 'ArrayPattern') {
@@ -290,7 +295,7 @@ class FuncGeneratorPlugin {
290
295
 
291
296
  // return { name: name, type: type, options: options };
292
297
  // }
293
- return { name: "value", type: "any", options: undefined };
298
+ return {name: 'value', type: 'any', options: undefined};
294
299
  });
295
300
  return params;
296
301
  }
@@ -298,7 +303,7 @@ class FuncGeneratorPlugin {
298
303
  _getTsFiles(root) {
299
304
  const tsFiles = [];
300
305
  const extPattern = /\.tsx?$/;
301
- const excludedFiles = ["package-test.ts", "package.g.ts"];
306
+ const excludedFiles = ['package-test.ts', 'package.g.ts'];
302
307
 
303
308
  function findFiles(dir) {
304
309
  const files = fs.readdirSync(dir);
@@ -315,7 +320,7 @@ class FuncGeneratorPlugin {
315
320
  }
316
321
 
317
322
  _walk(node, visitor, parent = null) {
318
- if (!node || typeof node !== "object") return;
323
+ if (!node || typeof node !== 'object') return;
319
324
 
320
325
  visitor(node, parent);
321
326
 
@@ -323,40 +328,39 @@ class FuncGeneratorPlugin {
323
328
  const value = node[key];
324
329
  if (Array.isArray(value)) {
325
330
  value.forEach((child) => {
326
- if (child && typeof child.type === "string") {
331
+ if (child && typeof child.type === 'string') {
327
332
  this._walk(
328
333
  child,
329
334
  visitor,
330
- node.type === "ClassDeclaration" ? node : parent
335
+ node.type === 'ClassDeclaration' ? node : parent,
331
336
  );
332
337
  }
333
338
  });
334
- } else if (value && typeof value.type === "string") {
339
+ } else if (value && typeof value.type === 'string') {
335
340
  this._walk(
336
341
  value,
337
342
  visitor,
338
- node.type === "ClassDeclaration" ? node : parent
343
+ node.type === 'ClassDeclaration' ? node : parent,
339
344
  );
340
345
  }
341
346
  }
342
347
  }
343
348
 
344
349
  _readReturnType(annotation) {
345
- let resultType = "dynamic";
350
+ let resultType = 'dynamic';
346
351
  let isArray = false;
347
352
  if (
348
353
  annotation &&
349
- annotation.type !== "TSUnionType" &&
350
- annotation.type !== "TSIntersectionType"
354
+ annotation.type !== 'TSUnionType' &&
355
+ annotation.type !== 'TSIntersectionType'
351
356
  ) {
352
357
 
353
- if (annotation.typeName || annotation.type === "TSTypeReference")
358
+ if (annotation.typeName || annotation.type === 'TSTypeReference') {
354
359
  resultType =
355
360
  annotation.typeName?.right?.name ?? annotation.typeName?.name;
356
- else if (annotation.type !== "TSArrayType"){
361
+ } else if (annotation.type !== 'TSArrayType')
357
362
  resultType = this._getTypeNameFromNode(annotation);
358
- }
359
- else if (annotation.elementType.type !== "TSTypeReference") {
363
+ else if (annotation.elementType.type !== 'TSTypeReference') {
360
364
  isArray = true;
361
365
  resultType = this._getTypeNameFromNode(annotation?.elementType);
362
366
  } else {
@@ -378,18 +382,17 @@ class FuncGeneratorPlugin {
378
382
  if (node?.type === 'ClassDeclaration')
379
383
  return [];
380
384
 
381
- if (annotation?.typeName?.name === "Promise") {
385
+ if (annotation?.typeName?.name === 'Promise') {
382
386
  const argumnets = annotation.typeArguments?.params;
383
- if (argumnets && argumnets.length === 1) {
387
+ if (argumnets && argumnets.length === 1)
384
388
  annotation = argumnets[0];
385
- } else annotation = {};
389
+ else annotation = {};
386
390
  }
387
391
 
388
- if (annotation?.type === "TSTypeLiteral"){
392
+ if (annotation?.type === 'TSTypeLiteral')
389
393
  results = this._readOutputsFromReturnTypeObject(annotation);
390
- }
391
- else{
392
- let resultType = this._readReturnType(annotation);
394
+ else {
395
+ const resultType = this._readReturnType(annotation);
393
396
  results.push({name: 'result', type: resultType});
394
397
  if (resultType === 'void')
395
398
  results = [];
@@ -399,8 +402,8 @@ class FuncGeneratorPlugin {
399
402
 
400
403
  _readOutputsFromReturnTypeObject(node) {
401
404
  let i = 0;
402
- let results = [];
403
- for (let member of node.members) {
405
+ const results = [];
406
+ for (const member of node.members) {
404
407
  results.push({
405
408
  name: member?.key?.name ?? `result${i}`,
406
409
  type: this._readReturnType(member.typeAnnotation.typeAnnotation),
@@ -411,19 +414,19 @@ class FuncGeneratorPlugin {
411
414
  }
412
415
 
413
416
  _getTypeNameFromNode(typeNode) {
414
- if (typeNode.type === "TSTypeReference") {
417
+ if (typeNode.type === 'TSTypeReference')
415
418
  return typeNode.typeName.name;
416
- } else if (typeNode.type === "TSVoidKeyword") {
417
- return "void";
418
- } else if (typeNode.type === "TSNumberKeyword") {
419
- return "number";
420
- } else if (typeNode.type === "TSStringKeyword") {
421
- return "string";
422
- } else if (typeNode.type === "TSBooleanKeyword") {
423
- return "boolean";
424
- } else {
419
+ else if (typeNode.type === 'TSVoidKeyword')
420
+ return 'void';
421
+ else if (typeNode.type === 'TSNumberKeyword')
422
+ return 'number';
423
+ else if (typeNode.type === 'TSStringKeyword')
424
+ return 'string';
425
+ else if (typeNode.type === 'TSBooleanKeyword')
426
+ return 'boolean';
427
+ else
425
428
  return typeNode.type;
426
- }
429
+
427
430
  }
428
431
 
429
432
  _clearGeneratedFile() {
@@ -431,38 +434,41 @@ class FuncGeneratorPlugin {
431
434
  }
432
435
 
433
436
  _checkPackageFileForDecoratorsExport(packagePath) {
434
- const content = fs.readFileSync(packagePath, "utf-8");
437
+ const content = fs.readFileSync(packagePath, 'utf-8');
435
438
  const decoratorsExportRegex = /export\s*\*\s*from\s*'\.\/package\.g';/;
436
- if (!decoratorsExportRegex.test(content))
439
+ if (!decoratorsExportRegex.test(content)) {
437
440
  console.warn(
438
- `\nWARNING: Your package doesn't export package.g.ts file to package.ts \n please add 'export * from './package.g';' to the package.ts file.\n`
441
+ // eslint-disable-next-line max-len
442
+ `\nWARNING: Your package doesn't export package.g.ts file to package.ts \n please add 'export * from './package.g';' to the package.ts file.\n`,
439
443
  );
444
+ }
440
445
  }
441
446
 
442
447
  _writeToPackageFile(filePath, imports, exp) {
443
448
  if (imports.length !== exp.length) return;
444
- let content = fs.readFileSync(filePath, "utf-8");
449
+ let content = fs.readFileSync(filePath, 'utf-8');
445
450
  for (let i = 0; i < imports.length; i++) {
446
451
  const importStatement = imports[i];
447
452
  const exportStatement = exp[i];
448
453
  if (!content.includes(importStatement.trim()))
449
454
  content = annotationForGeneratedFile + importStatement + content + exportStatement;
450
455
  }
451
- fs.writeFileSync(filePath, content, "utf-8");
456
+ fs.writeFileSync(filePath, content, 'utf-8');
452
457
  }
453
458
 
454
459
  _insertImports(importArray) {
455
460
  if (fs.existsSync(this.options.outputPath)) {
456
- const content = fs.readFileSync(this.options.outputPath, "utf-8");
461
+ const content = fs.readFileSync(this.options.outputPath, 'utf-8');
457
462
  if (content) importArray.push(content);
458
- const output = importArray.join("");
459
- fs.writeFileSync(this.options.outputPath, `${output}`, "utf-8");
460
- } else
463
+ const output = importArray.join('');
464
+ fs.writeFileSync(this.options.outputPath, `${output}`, 'utf-8');
465
+ } else {
461
466
  fs.writeFileSync(
462
467
  this.options.outputPath,
463
- `${annotationForGeneratedFile}${baseImport}\n${importArray.join("")}`,
464
- "utf-8"
468
+ `${annotationForGeneratedFile}${baseImport}\n${importArray.join('')}`,
469
+ 'utf-8',
465
470
  );
471
+ }
466
472
  }
467
473
  }
468
474