datagrok-tools 4.13.79 → 4.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/bin/utils/func-generation.js +59 -14
- package/package.json +1 -1
- package/plugins/func-gen-plugin.js +104 -86
package/CHANGELOG.md
CHANGED
|
@@ -20,11 +20,13 @@ let pseudoParams = exports.pseudoParams = /*#__PURE__*/function (pseudoParams) {
|
|
|
20
20
|
pseudoParams["INPUT_TYPE"] = "inputType";
|
|
21
21
|
return pseudoParams;
|
|
22
22
|
}({});
|
|
23
|
+
const nonMetaData = ['sidebar', 'editor'];
|
|
24
|
+
const decoratorOptionToAnnotation = new Map([['initialValue', 'default']]);
|
|
23
25
|
let FUNC_TYPES = exports.FUNC_TYPES = /*#__PURE__*/function (FUNC_TYPES) {
|
|
24
26
|
FUNC_TYPES["APP"] = "app";
|
|
25
27
|
FUNC_TYPES["CELL_RENDERER"] = "cellRenderer";
|
|
26
28
|
FUNC_TYPES["FILE_EXPORTER"] = "fileExporter";
|
|
27
|
-
FUNC_TYPES["
|
|
29
|
+
FUNC_TYPES["FILE_HANDLER"] = "file-handler";
|
|
28
30
|
FUNC_TYPES["FILE_VIEWER"] = "fileViewer";
|
|
29
31
|
FUNC_TYPES["SETTINGS_EDITOR"] = "packageSettingsEditor";
|
|
30
32
|
FUNC_TYPES["VIEWER"] = "viewer";
|
|
@@ -38,6 +40,7 @@ let FUNC_TYPES = exports.FUNC_TYPES = /*#__PURE__*/function (FUNC_TYPES) {
|
|
|
38
40
|
FUNC_TYPES["DASHBOARD"] = "dashboard";
|
|
39
41
|
FUNC_TYPES["FUNCTION_ANALYSIS"] = "functionAnalysis";
|
|
40
42
|
FUNC_TYPES["CONVERTER"] = "converter";
|
|
43
|
+
FUNC_TYPES["MODEL"] = "model";
|
|
41
44
|
return FUNC_TYPES;
|
|
42
45
|
}({});
|
|
43
46
|
const typesToAnnotation = exports.typesToAnnotation = {
|
|
@@ -63,17 +66,19 @@ const typesToAnnotation = exports.typesToAnnotation = {
|
|
|
63
66
|
'FuncCall': 'funccall',
|
|
64
67
|
'DG.SemanticValue': 'semantic_value',
|
|
65
68
|
'SemanticValue': 'semantic_value',
|
|
66
|
-
'any': 'dynamic'
|
|
69
|
+
'any': 'dynamic',
|
|
70
|
+
'void': 'void',
|
|
71
|
+
'string': 'string'
|
|
67
72
|
};
|
|
68
73
|
|
|
69
74
|
/** Generates an annotation header for a function based on provided metadata. */
|
|
70
75
|
function getFuncAnnotation(data, comment = '//', sep = '\n') {
|
|
71
76
|
const isFileViewer = data.tags?.includes(FUNC_TYPES.FILE_VIEWER) ?? false;
|
|
72
|
-
const isFileImporter = data.tags?.includes(FUNC_TYPES.
|
|
77
|
+
const isFileImporter = data.tags?.includes(FUNC_TYPES.FILE_HANDLER) ?? false;
|
|
73
78
|
let s = '';
|
|
74
79
|
if (data.name) s += `${comment}name: ${data.name}${sep}`;
|
|
75
80
|
if (pseudoParams.EXTENSION in data && data.tags != null && data.tags.includes(FUNC_TYPES.FILE_EXPORTER)) s += `${comment}description: Save as ${data[pseudoParams.EXTENSION]}${sep}`;else if (data.description) s += `${comment}description: ${data.description}${sep}`;
|
|
76
|
-
if (data.tags) {
|
|
81
|
+
if (data.tags && data.tags?.length > 0) {
|
|
77
82
|
s += `${comment}tags: ${isFileViewer && data[pseudoParams.EXTENSIONS] ? data.tags.concat(data[pseudoParams.EXTENSIONS].map(ext => 'fileViewer-' + ext)).join(', ') : data.tags.join(', ')}${sep}`;
|
|
78
83
|
}
|
|
79
84
|
for (let input of data.inputs ?? []) {
|
|
@@ -88,22 +93,30 @@ function getFuncAnnotation(data, comment = '//', sep = '\n') {
|
|
|
88
93
|
if (input?.options?.type) type = input?.options?.type;else if (annotationType) {
|
|
89
94
|
if (isArray) type = `list<${annotationType}>`;else type = annotationType;
|
|
90
95
|
} else type = 'dynamic';
|
|
91
|
-
console.log(input);
|
|
92
96
|
const options = input?.options?.options ? buildStringOfOptions(input.options.options ?? {}) : '';
|
|
93
|
-
const functionName = (input.options?.name ? input?.options?.name
|
|
97
|
+
const functionName = (input.options?.name ? input?.options?.name : ` ${input.name?.replaceAll('.', '')}`)?.trim();
|
|
94
98
|
s += comment + 'input: ' + type + ' ' + functionName + (input.defaultValue !== undefined ? `= ${input.defaultValue}` : '') + ' ' + options.replaceAll('"', '\'') + sep;
|
|
95
99
|
}
|
|
96
100
|
if (data.outputs) {
|
|
97
|
-
for (const output of data.outputs) s += comment + 'output: ' + output.type + (output.name ? ` ${output.name}` : '') + sep;
|
|
101
|
+
for (const output of data.outputs) if (output.type !== 'void') s += comment + 'output: ' + output.type + (output.name ? ` ${output.name}${output.options ? ` ${buildStringOfOptions(output.options)}` : ''}` : '') + sep;
|
|
98
102
|
}
|
|
99
103
|
if (data.meta) {
|
|
100
104
|
for (let entry of Object.entries(data.meta)) s += `${comment}meta.${entry[0]}: ${entry[1]}${sep}`;
|
|
101
105
|
}
|
|
102
106
|
for (const parameter in data) {
|
|
103
|
-
if (parameter === pseudoParams.EXTENSION || parameter === pseudoParams.INPUT_TYPE || parameter === 'meta') continue;else if (parameter === pseudoParams.EXTENSIONS) {
|
|
107
|
+
if (parameter === pseudoParams.EXTENSION || parameter === pseudoParams.INPUT_TYPE || parameter === 'meta' || parameter === 'isAsync' || parameter === 'test') continue;else if (parameter === pseudoParams.EXTENSIONS) {
|
|
104
108
|
if (isFileViewer) continue;
|
|
105
109
|
s += `${comment}meta.ext: ${data[parameter]}${sep}`;
|
|
106
|
-
} else if (!headerParams.includes(parameter))
|
|
110
|
+
} else if (!headerParams.includes(parameter)) {
|
|
111
|
+
if (nonMetaData.includes(parameter)) s += `${comment}${parameter}: ${data[parameter]}${sep}`;else s += `${comment}meta.${parameter}: ${data[parameter]}${sep}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (data.test) {
|
|
115
|
+
for (let entry of Object.entries(data.test)) {
|
|
116
|
+
if (entry[0] === 'test' || entry[0] === 'wait') s += `${comment}`;else s += `, `;
|
|
117
|
+
s += `${entry[0]}: ${entry[1]} `;
|
|
118
|
+
}
|
|
119
|
+
s += `${sep}`;
|
|
107
120
|
}
|
|
108
121
|
return s;
|
|
109
122
|
}
|
|
@@ -111,8 +124,10 @@ function buildStringOfOptions(options) {
|
|
|
111
124
|
let optionsInString = [];
|
|
112
125
|
for (const [key, value] of Object.entries(options ?? {})) {
|
|
113
126
|
let val = value;
|
|
127
|
+
let option = key;
|
|
128
|
+
option = decoratorOptionToAnnotation.get(option) ?? option;
|
|
114
129
|
if (Array.isArray(value)) val = JSON.stringify(value);
|
|
115
|
-
optionsInString.push(`${
|
|
130
|
+
optionsInString.push(`${option}: ${val}`);
|
|
116
131
|
}
|
|
117
132
|
return `{ ${optionsInString.join('; ')} }`;
|
|
118
133
|
}
|
|
@@ -158,9 +173,9 @@ const reservedDecorators = exports.reservedDecorators = {
|
|
|
158
173
|
},
|
|
159
174
|
genFunc: generateFunc
|
|
160
175
|
},
|
|
161
|
-
|
|
176
|
+
fileHandler: {
|
|
162
177
|
metadata: {
|
|
163
|
-
tags: [FUNC_TYPES.
|
|
178
|
+
tags: [FUNC_TYPES.FILE_HANDLER],
|
|
164
179
|
inputs: [{
|
|
165
180
|
name: 'content',
|
|
166
181
|
type: 'string'
|
|
@@ -323,6 +338,36 @@ const reservedDecorators = exports.reservedDecorators = {
|
|
|
323
338
|
}]
|
|
324
339
|
},
|
|
325
340
|
genFunc: generateFunc
|
|
341
|
+
},
|
|
342
|
+
demo: {
|
|
343
|
+
metadata: {
|
|
344
|
+
tags: [],
|
|
345
|
+
inputs: [],
|
|
346
|
+
outputs: []
|
|
347
|
+
},
|
|
348
|
+
genFunc: generateFunc
|
|
349
|
+
},
|
|
350
|
+
treeBrowser: {
|
|
351
|
+
metadata: {
|
|
352
|
+
tags: [],
|
|
353
|
+
inputs: [{
|
|
354
|
+
name: 'treeNode',
|
|
355
|
+
type: 'dynamic'
|
|
356
|
+
}, {
|
|
357
|
+
name: 'browseView',
|
|
358
|
+
type: 'view'
|
|
359
|
+
}],
|
|
360
|
+
outputs: []
|
|
361
|
+
},
|
|
362
|
+
genFunc: generateFunc
|
|
363
|
+
},
|
|
364
|
+
model: {
|
|
365
|
+
metadata: {
|
|
366
|
+
tags: [FUNC_TYPES.MODEL],
|
|
367
|
+
inputs: [],
|
|
368
|
+
outputs: []
|
|
369
|
+
},
|
|
370
|
+
genFunc: generateFunc
|
|
326
371
|
}
|
|
327
372
|
};
|
|
328
373
|
|
|
@@ -332,10 +377,10 @@ function generateClassFunc(annotation, className, sep = '\n') {
|
|
|
332
377
|
}
|
|
333
378
|
|
|
334
379
|
/** Generates a DG function. */
|
|
335
|
-
function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = []) {
|
|
380
|
+
function generateFunc(annotation, funcName, sep = '\n', className = '', inputs = [], isAsync = false) {
|
|
336
381
|
let funcSigNature = inputs.map(e => `${e.name}: ${e.type}`).join(', ');
|
|
337
382
|
let funcArguments = inputs.map(e => e.name).join(', ');
|
|
338
|
-
return annotation + `export function
|
|
383
|
+
return annotation + `export ${isAsync ? 'async ' : ''}function ${funcName}(${funcSigNature}) {${sep} return ${className.length > 0 ? `${className}.` : ''}${funcName}(${funcArguments});${sep}}${sep.repeat(2)}`;
|
|
339
384
|
}
|
|
340
385
|
function generateImport(className, path, sep = '\n') {
|
|
341
386
|
return `import {${className}} from '${path}';${sep}`;
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ const {
|
|
|
12
12
|
typesToAnnotation
|
|
13
13
|
} = require("../bin/utils/func-generation");
|
|
14
14
|
|
|
15
|
-
const baseImport = '\
|
|
15
|
+
const baseImport = '\n';
|
|
16
16
|
|
|
17
17
|
class FuncGeneratorPlugin {
|
|
18
18
|
constructor(options = { outputPath: "./src/package.g.ts" }) {
|
|
@@ -33,6 +33,9 @@ class FuncGeneratorPlugin {
|
|
|
33
33
|
|
|
34
34
|
for (const file of tsFiles) {
|
|
35
35
|
const content = fs.readFileSync(file, "utf-8");
|
|
36
|
+
if(!content.includes('@grok.decorators.'))
|
|
37
|
+
continue;
|
|
38
|
+
|
|
36
39
|
if (!content) continue;
|
|
37
40
|
const ast = tsParser.parse(content, {
|
|
38
41
|
sourceType: "module",
|
|
@@ -44,11 +47,6 @@ class FuncGeneratorPlugin {
|
|
|
44
47
|
});
|
|
45
48
|
const functions = [];
|
|
46
49
|
let imports = new Set();
|
|
47
|
-
|
|
48
|
-
const fileName = path.basename(file);
|
|
49
|
-
if(fileName === 'package-functions.ts')
|
|
50
|
-
imports = new Set([... this._readImports(content)]);
|
|
51
|
-
|
|
52
50
|
this._walk(ast, (node, parentClass) => {
|
|
53
51
|
const decorators = node.decorators;
|
|
54
52
|
if (!decorators || decorators.length === 0) return;
|
|
@@ -58,12 +56,14 @@ class FuncGeneratorPlugin {
|
|
|
58
56
|
|
|
59
57
|
if (node?.type === "MethodDefinition")
|
|
60
58
|
this._addNodeData(node, file, srcDirPath, functions, imports, genImports, genExports, parentClass);
|
|
61
|
-
|
|
59
|
+
});
|
|
62
60
|
this._insertImports([...imports]);
|
|
63
|
-
fs.appendFileSync(this.options.outputPath, functions.join("
|
|
61
|
+
fs.appendFileSync(this.options.outputPath, functions.join(""), "utf-8");
|
|
64
62
|
}
|
|
63
|
+
this._checkPackageFileForDecoratorsExport(packageFilePath);
|
|
64
|
+
// Uncommment to add obvious import/export
|
|
65
|
+
// this._writeToPackageFile(packageFilePath, genImports, genExports);
|
|
65
66
|
|
|
66
|
-
this._writeToPackageFile(packageFilePath, genImports, genExports);
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -87,26 +87,33 @@ class FuncGeneratorPlugin {
|
|
|
87
87
|
const decoratorOptions = this._readDecoratorOptions(exp.arguments[0].properties);
|
|
88
88
|
decoratorOptions.set('tags', [...(reservedDecorators[name]['metadata']['tags'] ?? [] ), ...(decoratorOptions.get('tags') ?? [])])
|
|
89
89
|
const functionParams = node?.type === 'MethodDefinition' ? this._readMethodParamas(node) : [];
|
|
90
|
-
|
|
91
90
|
const annotationByReturnType = node?.type === 'MethodDefinition' ? this._readFunctionReturnTypeInfo(node) : '';
|
|
92
91
|
const annotationByReturnTypeObj = { name: 'result', type: annotationByReturnType };
|
|
93
|
-
|
|
92
|
+
const isMethodAsync = this._isMethodAsync(node);
|
|
94
93
|
let importString = generateImport(node?.type === 'MethodDefinition' ? className : identifierName, modifyImportPath(path.dirname(this.options.outputPath), file));
|
|
95
94
|
imports.add(importString);
|
|
96
|
-
const funcName =
|
|
95
|
+
const funcName = `${node?.type === 'MethodDefinition' ? '' : '_'}${identifierName}`;
|
|
97
96
|
const funcAnnotaionOptions = {
|
|
98
97
|
...reservedDecorators[name]['metadata'],
|
|
99
98
|
...(annotationByReturnType ? {outputs: [annotationByReturnTypeObj ?? {}]} : {}),
|
|
100
99
|
...Object.fromEntries(decoratorOptions),
|
|
101
100
|
...{inputs: functionParams},
|
|
101
|
+
...{isAsync: isMethodAsync}
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
if (!funcAnnotaionOptions.name)
|
|
104
|
+
funcAnnotaionOptions.name = identifierName;
|
|
105
|
+
functions.push(reservedDecorators[name]['genFunc'](getFuncAnnotation(funcAnnotaionOptions), identifierName,'\n', (className ?? ''), functionParams, funcAnnotaionOptions.isAsync ?? false));
|
|
106
106
|
genImports.push(generateImport(funcName, modifyImportPath(srcDirPath, this.options.outputPath)));
|
|
107
107
|
genExports.push(generateExport(funcName));
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
_isMethodAsync(node){
|
|
111
|
+
let result = false;
|
|
112
|
+
if (node.type === 'MethodDefinition')
|
|
113
|
+
result = node.value.async;
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
110
117
|
_readImports (content) {
|
|
111
118
|
const importRegex = /(import(?:[\s\w{},*]+from\s*)?['"]([^'"]+)['"];)/g;
|
|
112
119
|
const results = [];
|
|
@@ -152,13 +159,14 @@ class FuncGeneratorPlugin {
|
|
|
152
159
|
_readMethodParamas(node) {
|
|
153
160
|
const params = node?.value?.params?.map(param => {
|
|
154
161
|
let baseParam = param.type === 'TSNonNullExpression' ? param.expression : param;
|
|
155
|
-
let defaultValue = undefined;
|
|
156
162
|
const options = param.decorators?.length > 0? Object.fromEntries(this._readDecoratorOptions(param.decorators[0]?.expression?.arguments[0].properties)) : undefined;
|
|
157
163
|
|
|
164
|
+
// Commented code finds value by default of function's variable
|
|
165
|
+
// let defaultValue = undefined;
|
|
158
166
|
if(baseParam.type === 'AssignmentPattern')
|
|
159
167
|
{
|
|
160
|
-
if (baseParam?.right?.type === 'Literal')
|
|
161
|
-
|
|
168
|
+
// if (baseParam?.right?.type === 'Literal')
|
|
169
|
+
// defaultValue = baseParam?.right?.raw;
|
|
162
170
|
baseParam = baseParam?.left;
|
|
163
171
|
}
|
|
164
172
|
|
|
@@ -167,50 +175,52 @@ class FuncGeneratorPlugin {
|
|
|
167
175
|
baseParam.type === 'RestElement'
|
|
168
176
|
? `...${baseParam.argument.name}`
|
|
169
177
|
: baseParam.name;
|
|
170
|
-
|
|
171
178
|
if (baseParam?.argument?.typeAnnotation)
|
|
172
179
|
name += ': ' + generate(baseParam.argument.typeAnnotation.typeAnnotation).code;
|
|
173
180
|
|
|
174
181
|
let type = '';
|
|
175
|
-
if (baseParam?.typeAnnotation)
|
|
176
|
-
type = generate(baseParam.typeAnnotation.typeAnnotation).code;
|
|
177
|
-
else
|
|
182
|
+
if (baseParam?.typeAnnotation?.typeAnnotation?.typeName || baseParam?.typeAnnotation?.typeAnnotation?.elementType?.typeName)
|
|
178
183
|
type = 'any';
|
|
179
|
-
|
|
180
|
-
return { name: name, type: type, defaultValue: defaultValue, options: options };
|
|
181
|
-
}
|
|
182
|
-
else if (baseParam.type === 'ObjectPattern' || baseParam.type === 'ArrayPattern') {
|
|
183
|
-
let name = '';
|
|
184
|
-
if (baseParam.type === 'ObjectPattern') {
|
|
185
|
-
const properties = baseParam.properties.map(prop => {
|
|
186
|
-
if (prop.type === 'Property' && prop.key.type === 'Identifier')
|
|
187
|
-
return prop.key.name;
|
|
188
|
-
else if (prop.type === 'RestElement' && prop.argument.type === 'Identifier')
|
|
189
|
-
return `...${prop.argument.name}`;
|
|
190
|
-
else
|
|
191
|
-
return generate(prop).code;
|
|
192
|
-
});
|
|
193
|
-
name = `{ ${properties.join(', ')} }`;
|
|
194
|
-
} else {
|
|
195
|
-
const elements = baseParam.elements.map(elem => {
|
|
196
|
-
if (elem) {
|
|
197
|
-
if (elem.type === 'Identifier')
|
|
198
|
-
return elem.name;
|
|
199
|
-
else
|
|
200
|
-
return generate(elem).code;
|
|
201
|
-
} else return '';
|
|
202
|
-
});
|
|
203
|
-
name = `[${elements.join(', ')}]`;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let type = '';
|
|
207
|
-
if (baseParam.typeAnnotation)
|
|
184
|
+
else if (baseParam?.typeAnnotation?.typeAnnotation)
|
|
208
185
|
type = generate(baseParam.typeAnnotation.typeAnnotation).code;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return { name: name, type: type,
|
|
186
|
+
let params = baseParam.typeAnnotation.typeAnnotation.typeArguments?.params;
|
|
187
|
+
if(type !== 'any' && params && params.length > 0)
|
|
188
|
+
type += `<${params.map((e)=>e.typeName.name).join(',')}>`;
|
|
189
|
+
return { name: name, type: type, options: options };
|
|
213
190
|
}
|
|
191
|
+
// Commented code belove sets more strong types for ObjectPatterns and ArrayPatterns
|
|
192
|
+
// else if (baseParam.type === 'ObjectPattern' || baseParam.type === 'ArrayPattern') {
|
|
193
|
+
// let name = '';
|
|
194
|
+
// if (baseParam.type === 'ObjectPattern') {
|
|
195
|
+
// const properties = baseParam.properties.map(prop => {
|
|
196
|
+
// if (prop.type === 'Property' && prop.key.type === 'Identifier')
|
|
197
|
+
// return prop.key.name;
|
|
198
|
+
// else if (prop.type === 'RestElement' && prop.argument.type === 'Identifier')
|
|
199
|
+
// return `...${prop.argument.name}`;
|
|
200
|
+
// else
|
|
201
|
+
// return generate(prop).code;
|
|
202
|
+
// });
|
|
203
|
+
// name = `{ ${properties.join(', ')} }`;
|
|
204
|
+
// } else {
|
|
205
|
+
// const elements = baseParam.elements.map(elem => {
|
|
206
|
+
// if (elem) {
|
|
207
|
+
// if (elem.type === 'Identifier')
|
|
208
|
+
// return elem.name;
|
|
209
|
+
// else
|
|
210
|
+
// return generate(elem).code;
|
|
211
|
+
// } else return '';
|
|
212
|
+
// });
|
|
213
|
+
// name = `[${elements.join(', ')}]`;
|
|
214
|
+
// }
|
|
215
|
+
|
|
216
|
+
// let type = '';
|
|
217
|
+
// if (baseParam.typeAnnotation)
|
|
218
|
+
// type = generate(baseParam.typeAnnotation.typeAnnotation).code;
|
|
219
|
+
// else
|
|
220
|
+
// type = 'any';
|
|
221
|
+
|
|
222
|
+
// return { name: name, type: type, options: options };
|
|
223
|
+
// }
|
|
214
224
|
return { name: 'value', type: 'any', options: undefined };
|
|
215
225
|
});
|
|
216
226
|
return params;
|
|
@@ -219,7 +229,7 @@ class FuncGeneratorPlugin {
|
|
|
219
229
|
_getTsFiles(root) {
|
|
220
230
|
const tsFiles = [];
|
|
221
231
|
const extPattern = /\.tsx?$/;
|
|
222
|
-
const excludedFiles = ["package
|
|
232
|
+
const excludedFiles = ["package-test.ts", "package.g.ts"];
|
|
223
233
|
|
|
224
234
|
function findFiles(dir) {
|
|
225
235
|
const files = fs.readdirSync(dir);
|
|
@@ -257,41 +267,42 @@ class FuncGeneratorPlugin {
|
|
|
257
267
|
_readFunctionReturnTypeInfo(node) {
|
|
258
268
|
let resultType = 'any';
|
|
259
269
|
let isArray = false;
|
|
260
|
-
const annotation = node.value
|
|
261
|
-
if (annotation
|
|
262
|
-
|
|
263
|
-
const argumnets = annotation.typeArguments?.params;
|
|
264
|
-
if (argumnets && argumnets.length===1)
|
|
270
|
+
const annotation = node.value?.returnType?.typeAnnotation;
|
|
271
|
+
if (annotation) {
|
|
272
|
+
if (annotation?.typeName?.name === 'Promise')
|
|
265
273
|
{
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
274
|
+
const argumnets = annotation.typeArguments?.params;
|
|
275
|
+
if (argumnets && argumnets.length===1)
|
|
276
|
+
{
|
|
277
|
+
if (argumnets[0].typeName)
|
|
278
|
+
resultType = argumnets[0].typeName?.right?.name ?? argumnets[0].typeName?.name;
|
|
279
|
+
else if (argumnets[0].type !== 'TSArrayType')
|
|
280
|
+
resultType = this._getTypeNameFromNode(argumnets[0]);
|
|
281
|
+
else if (argumnets[0].elementType.type !== 'TSTypeReference'){
|
|
282
|
+
isArray = true;
|
|
283
|
+
resultType = this._getTypeNameFromNode(argumnets[0]?.elementType);
|
|
284
|
+
}
|
|
285
|
+
else{
|
|
286
|
+
isArray = true;
|
|
287
|
+
resultType = argumnets[0].elementType?.typeName?.name || argumnets[0].elementType?.typeName?.right?.name;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else{
|
|
292
|
+
if (annotation.type === 'TSTypeReference')
|
|
293
|
+
resultType = annotation.typeName?.right?.name ?? annotation.typeName?.name;
|
|
294
|
+
else if (annotation.type !== 'TSArrayType')
|
|
295
|
+
resultType = this._getTypeNameFromNode(annotation);
|
|
296
|
+
else if (annotation.elementType.type !== 'TSTypeReference'){
|
|
271
297
|
isArray = true;
|
|
272
|
-
resultType = this._getTypeNameFromNode(
|
|
298
|
+
resultType = this._getTypeNameFromNode(annotation?.elementType);
|
|
273
299
|
}
|
|
274
300
|
else{
|
|
275
301
|
isArray = true;
|
|
276
|
-
resultType =
|
|
302
|
+
resultType = (annotation?.elementType?.typeName?.name || annotation?.elementType?.typeName?.right?.name);
|
|
277
303
|
}
|
|
278
304
|
}
|
|
279
305
|
}
|
|
280
|
-
else{
|
|
281
|
-
if (annotation.type === 'TSTypeReference')
|
|
282
|
-
resultType = annotation.typeName?.right?.name ?? annotation.typeName?.name;
|
|
283
|
-
else if (annotation.type !== 'TSArrayType')
|
|
284
|
-
resultType = this._getTypeNameFromNode(annotation);
|
|
285
|
-
else if (annotation.elementType.type !== 'TSTypeReference'){
|
|
286
|
-
isArray = true;
|
|
287
|
-
resultType = this._getTypeNameFromNode(annotation?.elementType);
|
|
288
|
-
}
|
|
289
|
-
else{
|
|
290
|
-
isArray = true;
|
|
291
|
-
resultType = (annotation?.elementType?.typeName?.name || annotation?.elementType?.typeName?.right?.name);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
306
|
resultType = typesToAnnotation[resultType];
|
|
296
307
|
if (isArray && resultType)
|
|
297
308
|
resultType = `list<${resultType}>`
|
|
@@ -318,12 +329,19 @@ class FuncGeneratorPlugin {
|
|
|
318
329
|
fs.writeFileSync(this.options.outputPath, baseImport);
|
|
319
330
|
}
|
|
320
331
|
|
|
321
|
-
|
|
322
|
-
|
|
332
|
+
_checkPackageFileForDecoratorsExport(packagePath){
|
|
333
|
+
const content = fs.readFileSync(packagePath, "utf-8");
|
|
334
|
+
const decoratorsExportRegex = /export\s*\*\s*from\s*'\.\/package\.g';/;
|
|
335
|
+
if (!decoratorsExportRegex.test(content))
|
|
336
|
+
console.warn(`\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`);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
_writeToPackageFile(filePath, imports, exp) {
|
|
340
|
+
if (imports.length !== exp.length) return;
|
|
323
341
|
let content = fs.readFileSync(filePath, "utf-8");
|
|
324
342
|
for (let i = 0; i < imports.length; i++) {
|
|
325
343
|
const importStatement = imports[i];
|
|
326
|
-
const exportStatement =
|
|
344
|
+
const exportStatement = exp[i];
|
|
327
345
|
if (!content.includes(importStatement.trim()))
|
|
328
346
|
content = importStatement + content + exportStatement;
|
|
329
347
|
}
|