@lcap/nasl 3.8.0-beta.5 → 3.8.0-beta.7
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/.mocharc.js +1 -0
- package/out/common/BaseNode.d.ts +21 -5
- package/out/common/BaseNode.js +94 -12
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/AbstractInterface__.js.map +1 -1
- package/out/concepts/Annotation__.js +1 -1
- package/out/concepts/Annotation__.js.map +1 -1
- package/out/concepts/App__.d.ts +3 -0
- package/out/concepts/App__.js +985 -6
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Argument__.js +3 -3
- package/out/concepts/Argument__.js.map +1 -1
- package/out/concepts/BatchAssignment__.d.ts +1 -1
- package/out/concepts/BatchAssignment__.js +2 -2
- package/out/concepts/BatchAssignment__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +7 -7
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.js +3 -4
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindStyle__.js +1 -1
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BusinessComponent__.d.ts +2 -0
- package/out/concepts/BusinessComponent__.js +48 -0
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.d.ts +1 -0
- package/out/concepts/BusinessLogic__.js +10 -0
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallEvent__.d.ts +2 -0
- package/out/concepts/CallEvent__.js +75 -0
- package/out/concepts/CallEvent__.js.map +1 -1
- package/out/concepts/CallInterface__.d.ts +1 -0
- package/out/concepts/CallInterface__.js +26 -15
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +4 -0
- package/out/concepts/CallLogic__.js +65 -5
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +3 -3
- package/out/concepts/Entity__.js +4 -0
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/EnumItem__.d.ts +13 -0
- package/out/concepts/EnumItem__.js +31 -0
- package/out/concepts/EnumItem__.js.map +1 -1
- package/out/concepts/Event__.d.ts +2 -0
- package/out/concepts/Event__.js +30 -0
- package/out/concepts/Event__.js.map +1 -1
- package/out/concepts/FrontendType__.d.ts +2 -0
- package/out/concepts/FrontendType__.js +32 -0
- package/out/concepts/FrontendType__.js.map +1 -1
- package/out/concepts/Frontend__.d.ts +2 -0
- package/out/concepts/Frontend__.js +48 -0
- package/out/concepts/Frontend__.js.map +1 -1
- package/out/concepts/IfStatement__.js +6 -6
- package/out/concepts/IfStatement__.js.map +1 -1
- package/out/concepts/InterfaceParam__.d.ts +1 -0
- package/out/concepts/InterfaceParam__.js +23 -4
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Interface__.d.ts +2 -1
- package/out/concepts/Interface__.js +29 -5
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/JSBlock__.d.ts +1 -0
- package/out/concepts/JSBlock__.js +6 -0
- package/out/concepts/JSBlock__.js.map +1 -1
- package/out/concepts/LogicDeclaration__.d.ts +1 -0
- package/out/concepts/LogicDeclaration__.js +58 -7
- package/out/concepts/LogicDeclaration__.js.map +1 -1
- package/out/concepts/Logic__.js +46 -27
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchCase__.js +1 -2
- package/out/concepts/MatchCase__.js.map +1 -1
- package/out/concepts/Match__.js +3 -18
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +4 -4
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.d.ts +4 -0
- package/out/concepts/Module__.js +92 -0
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/NewComposite__.d.ts +1 -1
- package/out/concepts/NewComposite__.js +2 -2
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/NullLiteral__.js +6 -0
- package/out/concepts/NullLiteral__.js.map +1 -1
- package/out/concepts/Paginate__.d.ts +1 -0
- package/out/concepts/Paginate__.js +15 -7
- package/out/concepts/Paginate__.js.map +1 -1
- package/out/concepts/QueryFromExpression__.js +2 -2
- package/out/concepts/QueryFromExpression__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +3 -4
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.d.ts +13 -0
- package/out/concepts/StructureProperty__.js +31 -0
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +1 -0
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +2 -0
- package/out/concepts/ViewElement__.js +61 -41
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +1 -0
- package/out/concepts/View__.js +55 -1
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
- package/out/generator/genBundleFiles.js +36 -22
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genHash.d.ts +2 -2
- package/out/generator/genHash.js +30 -30
- package/out/generator/genHash.js.map +1 -1
- package/out/generator/genMetaData.js +7 -49
- package/out/generator/genMetaData.js.map +1 -1
- package/out/generator/permission.d.ts +8 -1
- package/out/generator/permission.js +321 -23
- package/out/generator/permission.js.map +1 -1
- package/out/generator/release-body/body.d.ts +5 -0
- package/out/generator/release-body/body.js +62 -12
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/data.js +6 -2
- package/out/generator/release-body/data.js.map +1 -1
- package/out/generator/release-body/index.d.ts +1 -0
- package/out/generator/release-body/index.js +1 -0
- package/out/generator/release-body/index.js.map +1 -1
- package/out/generator/release-body/utils.js +3 -3
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/generator/release-body/validation.js +2 -2
- package/out/generator/release-body/validation.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js.map +1 -1
- package/out/natural/genNaturalTS.d.ts +24 -56
- package/out/natural/genNaturalTS.js +116 -184
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +2 -3
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +26 -35
- package/out/natural/getContext/index.js +172 -311
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/index.d.ts +0 -1
- package/out/natural/index.js +0 -1
- package/out/natural/index.js.map +1 -1
- package/out/natural/transformTS2UI.js +31 -14
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.js +26 -10
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/entity2LogicNamespace.d.ts +2 -2
- package/out/server/entity2LogicNamespace.js +321 -310
- package/out/server/entity2LogicNamespace.js.map +1 -1
- package/out/server/extendBaseNode.js +25 -0
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/getLogics.js +1 -1
- package/out/server/getLogics.js.map +1 -1
- package/out/server/naslServer.d.ts +10 -4
- package/out/server/naslServer.js +77 -19
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +12 -0
- package/out/server/translator.js.map +1 -1
- package/out/templator/genCreateBlock.js +3 -3
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +2 -2
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +5 -5
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEditTableBlock.js +1 -1
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +3 -3
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.js +1 -1
- package/out/templator/utils.js.map +1 -1
- package/out/translator/types.d.ts +2 -0
- package/package.json +5 -5
- package/sandbox/stdlib/nasl.processV2.ts +1 -1
- package/sandbox/stdlib/nasl.ui.definition.ts +0 -18
- package/src/common/BaseNode.ts +100 -16
- package/src/concepts/AbstractInterface__.ts +1 -0
- package/src/concepts/Annotation__.ts +1 -1
- package/src/concepts/App__.ts +126 -6
- package/src/concepts/Argument__.ts +3 -3
- package/src/concepts/BatchAssignment__.ts +2 -2
- package/src/concepts/BindAttribute__.ts +7 -7
- package/src/concepts/BindDirective__.ts +3 -4
- package/src/concepts/BindStyle__.ts +1 -1
- package/src/concepts/BusinessComponent__.ts +54 -1
- package/src/concepts/BusinessLogic__.ts +10 -1
- package/src/concepts/CallEvent__.ts +66 -0
- package/src/concepts/CallInterface__.ts +21 -9
- package/src/concepts/CallLogic__.ts +66 -5
- package/src/concepts/Entity__.ts +7 -1
- package/src/concepts/EnumItem__.ts +40 -1
- package/src/concepts/Event__.ts +32 -0
- package/src/concepts/FrontendType__.ts +34 -1
- package/src/concepts/Frontend__.ts +51 -0
- package/src/concepts/IfStatement__.ts +6 -6
- package/src/concepts/InterfaceParam__.ts +23 -4
- package/src/concepts/Interface__.ts +29 -5
- package/src/concepts/JSBlock__.ts +5 -0
- package/src/concepts/LogicDeclaration__.ts +65 -7
- package/src/concepts/Logic__.ts +49 -31
- package/src/concepts/MatchCase__.ts +1 -2
- package/src/concepts/Match__.ts +3 -21
- package/src/concepts/MemberExpression__.ts +4 -4
- package/src/concepts/Module__.ts +109 -0
- package/src/concepts/NewComposite__.ts +2 -2
- package/src/concepts/NullLiteral__.ts +7 -0
- package/src/concepts/Paginate__.ts +14 -7
- package/src/concepts/QueryFromExpression__.ts +2 -2
- package/src/concepts/StringLiteral__.ts +3 -4
- package/src/concepts/StructureProperty__.ts +41 -0
- package/src/concepts/TypeAnnotation__.ts +1 -0
- package/src/concepts/ViewElement__.ts +40 -19
- package/src/concepts/View__.ts +56 -1
- package/src/concepts/basics/stdlib/nasl.processV2.ts +1 -1
- package/src/generator/genBundleFiles.ts +39 -26
- package/src/generator/genHash.ts +32 -6
- package/src/generator/genMetaData.ts +11 -32
- package/src/generator/permission.ts +333 -23
- package/src/generator/release-body/body.ts +74 -15
- package/src/generator/release-body/data.ts +7 -2
- package/src/generator/release-body/index.ts +1 -0
- package/src/generator/release-body/utils.ts +3 -3
- package/src/generator/release-body/validation.ts +1 -1
- package/src/index.ts +13 -1
- package/src/natural/genNaturalTS.ts +148 -330
- package/src/natural/getContext/getUILib.ts +2 -3
- package/src/natural/getContext/index.ts +188 -357
- package/src/natural/index.ts +0 -1
- package/src/natural/transformTS2UI.ts +28 -14
- package/src/natural/transformTSCode.ts +25 -10
- package/src/server/entity2LogicNamespace.ts +13 -1
- package/src/server/extendBaseNode.ts +31 -0
- package/src/server/getLogics.ts +1 -1
- package/src/server/naslServer.ts +107 -27
- package/src/server/translator.ts +15 -0
- package/src/templator/genCreateBlock.ts +4 -4
- package/src/templator/genCurdEditMultipleKeyBlock.ts +2 -2
- package/src/templator/genCurdMultipleKeyBlock.ts +8 -8
- package/src/templator/genEditTableBlock.ts +4 -4
- package/src/templator/genGetBlock.ts +1 -1
- package/src/templator/genGridViewBlock.ts +2 -2
- package/src/templator/genSelectBlock.ts +3 -3
- package/src/templator/genTableBlock.ts +2 -2
- package/src/templator/genUpdateBlock.ts +6 -6
- package/src/templator/utils.ts +1 -1
- package/src/translator/types.ts +2 -0
- package/test/concepts/string-literal/__snapshots__/toVue.spec.ts.snap +1 -1
- package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +6 -2
- package/out/natural/tools.d.ts +0 -11
- package/out/natural/tools.js +0 -155
- package/out/natural/tools.js.map +0 -1
- package/src/natural/tools.ts +0 -130
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure
|
|
1
|
+
import { App, View, Logic, BaseNode, Frontend, Namespace, Module, TypeAnnotation, Structure } from '../../concepts';
|
|
2
2
|
import { shiftState, createCompilerState, TranslatorState, indent } from '../../translator';
|
|
3
3
|
import { getPreDeclaration, getUILib, handleMaterial, getExtensionsMaterial } from './getUILib';
|
|
4
4
|
import { getNASLStdlibMap } from './naslStdlibMap';
|
|
@@ -6,8 +6,6 @@ import { getNASLStdlibMap } from './naslStdlibMap';
|
|
|
6
6
|
export interface Snippet {
|
|
7
7
|
description: string;
|
|
8
8
|
code: string;
|
|
9
|
-
codeWithDetail?: string;
|
|
10
|
-
namespace?: string;
|
|
11
9
|
}
|
|
12
10
|
export interface SnippetBlock {
|
|
13
11
|
namespace: string;
|
|
@@ -18,34 +16,8 @@ export const wrapTSBlock = (code: string) => {
|
|
|
18
16
|
return `\`\`\`ts\n${code.trimEnd()}\n\`\`\`\n`;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
// 获取有引用的 structures
|
|
22
|
-
export function getReferenceStructures(referenceStructures: { typeNamespace: string; typeName: string; }[], structures: Structure[]): any {
|
|
23
|
-
const relationStructures = [] as any;
|
|
24
|
-
referenceStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
|
|
25
|
-
structures?.filter((structure: any) => structure?.name === reference?.typeName)
|
|
26
|
-
?.forEach((structure: any) => {
|
|
27
|
-
structure.properties?.forEach((property: any) => {
|
|
28
|
-
if (property?.typeAnnotation?.typeKind === 'reference') {
|
|
29
|
-
const { typeNamespace, typeName } = property?.typeAnnotation || {};
|
|
30
|
-
relationStructures.push({ typeNamespace, typeName });
|
|
31
|
-
}
|
|
32
|
-
if (property?.typeAnnotation?.typeArguments?.length) {
|
|
33
|
-
property?.typeAnnotation?.typeArguments?.forEach((typeArg: TypeAnnotation) => {
|
|
34
|
-
if (typeArg.typeKind === 'reference') {
|
|
35
|
-
const { typeNamespace, typeName } = typeArg || {};
|
|
36
|
-
relationStructures.push({ typeNamespace, typeName });
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
if (!relationStructures.length) return relationStructures;
|
|
44
|
-
return [...relationStructures, ...getReferenceStructures(relationStructures, structures)];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
19
|
// 获取logic用到的数据结构(带属性版)
|
|
48
|
-
export function
|
|
20
|
+
export function getLogicStructures(logic: Logic, type: string, desc: { description: string; codeStr: string; }, namespace: string) {
|
|
49
21
|
const { params, returns } = logic || {};
|
|
50
22
|
if (!params?.length && !returns?.length) return '';
|
|
51
23
|
let code = '';
|
|
@@ -68,32 +40,30 @@ export function getLogicWithStructuresCode(logic: Logic, type: string, desc: { d
|
|
|
68
40
|
});
|
|
69
41
|
}
|
|
70
42
|
});
|
|
71
|
-
|
|
72
|
-
let structures = [] as any;
|
|
73
|
-
if (type === 'connector') {
|
|
74
|
-
structures = logic?.connector?.structures;
|
|
75
|
-
} else if (type === 'extension' || type === 'interface') {
|
|
76
|
-
structures = (logic?.parentNode as Module)?.structures;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const relationStructures = getReferenceStructures(referenceStructures, structures);
|
|
80
|
-
|
|
81
|
-
const newRelationStructures = [...relationStructures, ...referenceStructures];
|
|
82
|
-
|
|
83
|
-
if (namespace && newRelationStructures?.length) {
|
|
43
|
+
if (namespace && referenceStructures?.length) {
|
|
84
44
|
code += `declare namespace ${namespace} {\n`;
|
|
85
45
|
}
|
|
86
46
|
|
|
87
|
-
|
|
88
|
-
const { typeName } = reference || {};
|
|
47
|
+
referenceStructures?.forEach((reference: { typeNamespace: string; typeName: string; }) => {
|
|
48
|
+
const { typeNamespace, typeName } = reference || {};
|
|
89
49
|
const state = createCompilerState();
|
|
90
50
|
const tabSize = namespace ? shiftState(state, code, { tabSize: 1 }) : undefined;
|
|
91
|
-
|
|
92
|
-
?.
|
|
93
|
-
|
|
94
|
-
|
|
51
|
+
if (typeNamespace?.includes('extensions.') && type === 'connector') {
|
|
52
|
+
logic?.connector?.structures
|
|
53
|
+
?.filter((structure) => structure?.name === typeName)
|
|
54
|
+
?.forEach((structure) => {
|
|
55
|
+
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if ((typeNamespace?.includes('extensions.') && type === 'extension') || (typeNamespace?.includes('apis.') && type === 'interface')) {
|
|
59
|
+
(logic?.parentNode as Module)?.structures
|
|
60
|
+
?.filter((structure) => structure?.name === typeName)
|
|
61
|
+
?.forEach((structure) => {
|
|
62
|
+
code += `${structure?.toNaturalTS(tabSize)}\n`;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
95
65
|
});
|
|
96
|
-
if (namespace &&
|
|
66
|
+
if (namespace && referenceStructures?.length) {
|
|
97
67
|
code += `}\n`;
|
|
98
68
|
}
|
|
99
69
|
const { description, codeStr } = desc || {};
|
|
@@ -119,60 +89,37 @@ export function getNaslUtil() {
|
|
|
119
89
|
return { code, naslUtil };
|
|
120
90
|
}
|
|
121
91
|
|
|
122
|
-
export const getNaslUI = (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
material:
|
|
126
|
-
|
|
127
|
-
basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string; };
|
|
128
|
-
extensionMaterials: {
|
|
129
|
-
name: string;
|
|
130
|
-
title: string;
|
|
131
|
-
description: string;
|
|
132
|
-
tsDescription: string;
|
|
133
|
-
}[];
|
|
134
|
-
},
|
|
135
|
-
) => {
|
|
136
|
-
let naslUI = [] as any;
|
|
137
|
-
if (material.basicMaterials) {
|
|
138
|
-
naslUI = typeof material.basicMaterials === 'string' ? getUILib(material.basicMaterials as 'pc' | 'h5') : handleMaterial(material.basicMaterials);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const extensionMaterials = typeof material.extensionMaterials === 'string' ? getExtensionsMaterial(app, frontendType) : material.extensionMaterials || [];
|
|
142
|
-
naslUI.push(...extensionMaterials);
|
|
92
|
+
export const getNaslUI = (app: App, frontendType: 'pc' | 'h5', material: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; } | string, requiredIndexes?: string[]) => {
|
|
93
|
+
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
94
|
+
const uiLib = typeof material === 'string' ? getUILib(material as 'pc' | 'h5') : handleMaterial(material.basicMaterials);
|
|
95
|
+
const extensionMaterials = typeof material === 'string' ? getExtensionsMaterial(app, frontendType) : material.extensionMaterials || [];
|
|
96
|
+
uiLib.push(...extensionMaterials);
|
|
143
97
|
|
|
144
|
-
|
|
145
|
-
|
|
98
|
+
if (!hasModuleIndexList) {
|
|
99
|
+
const naslUI = uiLib;
|
|
100
|
+
const code = naslUI.map((item, index) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
101
|
+
return { code, naslUI };
|
|
102
|
+
}
|
|
146
103
|
|
|
147
|
-
export const getNaslUICode = (naslUI: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
148
|
-
let code = '';
|
|
149
104
|
const preDeclaration = getPreDeclaration();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (codeType === 'detail') {
|
|
163
|
-
code = wrapTSBlock(
|
|
164
|
-
`${preDeclaration}\n${uiLib
|
|
165
|
-
.map(
|
|
166
|
-
(item: any) => `/**
|
|
105
|
+
const naslUI = uiLib.filter(
|
|
106
|
+
(item, index) =>
|
|
107
|
+
requiredIndexes.includes(`3-${index}`) ||
|
|
108
|
+
item.name.endsWith('LinearLayout') ||
|
|
109
|
+
item.name.endsWith('Text') ||
|
|
110
|
+
item.name.endsWith('Link') ||
|
|
111
|
+
item.name.endsWith('Button')
|
|
112
|
+
);
|
|
113
|
+
const code = wrapTSBlock(
|
|
114
|
+
`${preDeclaration}\n${naslUI.map(
|
|
115
|
+
(item) =>
|
|
116
|
+
`/**
|
|
167
117
|
* ${item.name}
|
|
168
118
|
* ${item.title}
|
|
169
119
|
* ${item.description}
|
|
170
120
|
*/
|
|
171
121
|
${item.tsDeclaration}`).join('\n')}`);
|
|
172
|
-
|
|
173
|
-
code += uiLib.map((item: any, index: number) => `[3-${index}] ${item.name} | ${item.title} | ${item.description}`).join('\n');
|
|
174
|
-
}
|
|
175
|
-
return code;
|
|
122
|
+
return { code, naslUI };
|
|
176
123
|
};
|
|
177
124
|
|
|
178
125
|
export const getNaslUIOld = () => {
|
|
@@ -187,121 +134,92 @@ export function getNaslOQL() {
|
|
|
187
134
|
return { code, naslOql };
|
|
188
135
|
}
|
|
189
136
|
|
|
190
|
-
export function getEnums(app: App, state: TranslatorState) {
|
|
137
|
+
export function getEnums(app: App, state: TranslatorState, requiredIndexes?: string[]) {
|
|
138
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
191
139
|
const namespace = 'app.enums';
|
|
192
140
|
const data = [] as Snippet[];
|
|
141
|
+
let code = '';
|
|
142
|
+
code += `declare namespace ${namespace} {\n`;
|
|
193
143
|
app.enums.forEach((enumeration) => {
|
|
194
|
-
const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace
|
|
144
|
+
const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace })}`;
|
|
145
|
+
code += temp;
|
|
195
146
|
data.push({ description: enumeration?.description || enumeration?.name, code: temp });
|
|
196
147
|
});
|
|
197
|
-
return { namespace, enums: { namespace, data } };
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export const getEnumsCode = (enums: any) => {
|
|
201
|
-
let code = '';
|
|
202
|
-
code += `declare namespace ${enums?.namespace} {\n`;
|
|
203
|
-
enums?.data?.forEach((item: any) => {
|
|
204
|
-
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
205
|
-
code += `${item.code}\n`;
|
|
206
|
-
});
|
|
207
148
|
code += `}\n`;
|
|
208
149
|
code = wrapTSBlock(code);
|
|
209
|
-
return code;
|
|
210
|
-
}
|
|
150
|
+
return { code, namespace, enums: { namespace, data } };
|
|
151
|
+
}
|
|
211
152
|
|
|
212
|
-
export function getEntities(app: App, state: TranslatorState) {
|
|
153
|
+
export function getEntities(app: App, state: TranslatorState, requiredIndexes?: string[]) {
|
|
154
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
213
155
|
const entities = [] as SnippetBlock[];
|
|
156
|
+
let code = '';
|
|
214
157
|
app.dataSources.forEach((dataSource) => {
|
|
215
158
|
const data = [] as Snippet[];
|
|
216
159
|
const namespace = `app.dataSources.${dataSource?.name}.entities`;
|
|
160
|
+
code += `declare namespace ${namespace} {\n`;
|
|
217
161
|
dataSource.entities
|
|
218
162
|
.filter((entity) => !entity.name.startsWith('LCAP') || entity.name === 'LCAPUser')
|
|
219
163
|
.forEach((entity) => {
|
|
220
|
-
const entityName = `app.dataSources.${dataSource?.name}.entities.${entity?.name}
|
|
221
|
-
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace
|
|
164
|
+
const entityName = needNamespace ? `app.dataSources.${dataSource?.name}.entities.${entity?.name}` : undefined;
|
|
165
|
+
const tempCode = `${entity?.toNaturalTS({ ...state, needNamespace }, entityName)}`;
|
|
166
|
+
code += tempCode;
|
|
222
167
|
data.push({ description: entity?.description || entity?.name, code: tempCode });
|
|
223
168
|
});
|
|
224
169
|
entities.push({ namespace, data });
|
|
225
|
-
});
|
|
226
|
-
return { entities };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export const getEntitiesCode = (entities: any) => {
|
|
230
|
-
let code = '';
|
|
231
|
-
entities?.forEach((entity: any) => {
|
|
232
|
-
code += `declare namespace ${entity?.namespace} {\n`;
|
|
233
|
-
entity?.data?.forEach((item: any) => {
|
|
234
|
-
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
235
|
-
code += `${item.code}\n`;
|
|
236
|
-
});
|
|
237
170
|
code += `}\n`;
|
|
238
171
|
});
|
|
239
172
|
code = wrapTSBlock(code);
|
|
240
|
-
return code;
|
|
241
|
-
}
|
|
173
|
+
return { code, entities };
|
|
174
|
+
}
|
|
242
175
|
|
|
243
|
-
export function getStructures(app: App, state: TranslatorState) {
|
|
176
|
+
export function getStructures(app: App, state: TranslatorState, requiredIndexes?: string[]) {
|
|
177
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
244
178
|
const data = [] as Snippet[];
|
|
245
179
|
const namespace = `app.structures`;
|
|
180
|
+
let code = '';
|
|
181
|
+
code += `declare namespace ${namespace} {\n`;
|
|
246
182
|
app.structures
|
|
247
183
|
.filter((entity) => !entity.name.startsWith('LCAP'))
|
|
248
184
|
.forEach((structure) => {
|
|
249
|
-
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace
|
|
185
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace })}`;
|
|
186
|
+
code += tempCode;
|
|
250
187
|
data.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
251
188
|
});
|
|
252
|
-
return { structures: { namespace, data } };
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export const getStructuresCode = (structures: any) => {
|
|
256
|
-
let code = '';
|
|
257
|
-
code += `declare namespace ${structures?.namespace} {\n`;
|
|
258
|
-
structures?.data?.forEach((item: any) => {
|
|
259
|
-
code += item?.description ? `/* ${item.description} */ \n` : '';
|
|
260
|
-
code += `${item.code}\n`;
|
|
261
|
-
});
|
|
262
189
|
code += `}\n`;
|
|
263
190
|
code = wrapTSBlock(code);
|
|
264
|
-
return code;
|
|
265
|
-
}
|
|
266
|
-
|
|
191
|
+
return { code, structures: { namespace, data } };
|
|
192
|
+
}
|
|
267
193
|
|
|
268
|
-
export function getLogics(app: App, currentNode: BaseNode) {
|
|
194
|
+
export function getLogics(app: App, currentNode: BaseNode, requiredIndexes?: string[]) {
|
|
195
|
+
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
269
196
|
const data = [] as Snippet[];
|
|
270
197
|
const namespace = `app.logics`;
|
|
198
|
+
let code = '';
|
|
271
199
|
app?.logics
|
|
272
200
|
?.filter((logic) => logic !== currentNode && !logic.name.startsWith('LCAP'))
|
|
273
|
-
?.forEach((logic) => {
|
|
274
|
-
const
|
|
275
|
-
|
|
201
|
+
?.forEach((logic, index) => {
|
|
202
|
+
const logicIndex = `6-${index}`;
|
|
203
|
+
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
204
|
+
const rename = requiredIndexes?.length >= 0 ? logic?.calleewholeKey : undefined;
|
|
205
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
206
|
+
const tempCode = `${logic?.toNaturalTS({ needNamespace, rename, declaration: true })}`;
|
|
276
207
|
const description = logic?.description || '';
|
|
277
|
-
|
|
208
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
278
209
|
data.push({ description, code: tempCode });
|
|
279
210
|
});
|
|
280
|
-
return { appLogics: { namespace, data } };
|
|
211
|
+
return { code, appLogics: { namespace, data } };
|
|
281
212
|
}
|
|
282
213
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
let code = '';
|
|
286
|
-
appLogics?.data?.forEach((item: any, index: number) => {
|
|
287
|
-
const logicIndex = `6-${index}`;
|
|
288
|
-
if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
|
|
289
|
-
const tempCode = codeType === 'short' ? item.code.replace(`${appLogics.namespace}.`, '') : item.code;
|
|
290
|
-
code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
291
|
-
});
|
|
292
|
-
return code;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
export function getModuleInterfaces(modules: Module[], state: TranslatorState) {
|
|
214
|
+
export function getModuleInterfaces(app: App, state: TranslatorState, requiredIndexes?: string[]) {
|
|
215
|
+
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
297
216
|
const interfaceDependencies = [] as {
|
|
298
217
|
name: string;
|
|
299
218
|
structures: SnippetBlock;
|
|
300
219
|
logics: SnippetBlock;
|
|
301
220
|
}[];
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
interfaceDependency.parentKey = 'interfaceDependencies';
|
|
221
|
+
let code = '';
|
|
222
|
+
app?.interfaceDependencies?.forEach((interfaceDependency, moduleIndex) => {
|
|
305
223
|
const name = interfaceDependency?.name;
|
|
306
224
|
let structures = {} as SnippetBlock;
|
|
307
225
|
let logics = {} as SnippetBlock;
|
|
@@ -316,46 +234,37 @@ export function getModuleInterfaces(modules: Module[], state: TranslatorState) {
|
|
|
316
234
|
|
|
317
235
|
const logicNamespace = `${namespace}.interfaces`;
|
|
318
236
|
const logicData = [] as Snippet[];
|
|
319
|
-
interfaceDependency?.interfaces?.forEach((interface_: any) => {
|
|
237
|
+
interfaceDependency?.interfaces?.forEach((interface_: any, index) => {
|
|
238
|
+
const interfaceIndex = `7-${moduleIndex}-${index}`;
|
|
239
|
+
if (hasModuleIndexList && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
320
240
|
const description = interface_?.description || '';
|
|
321
|
-
const interfaceName = interface_?.calleewholeKey;
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
logicData.push({ description, code: tempCode
|
|
241
|
+
const interfaceName = requiredIndexes?.length >= 0 ? interface_?.calleewholeKey : undefined;
|
|
242
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
243
|
+
const tempCode = interface_?.toNaturalTS(createCompilerState('', { needNamespace }), interfaceName);
|
|
244
|
+
logicData.push({ description, code: tempCode });
|
|
245
|
+
|
|
246
|
+
if (requiredIndexes?.includes(interfaceIndex)) {
|
|
247
|
+
code += getLogicStructures(interface_, 'interface', { description, codeStr: tempCode }, structureNamespace);
|
|
248
|
+
} else {
|
|
249
|
+
code += `[${interfaceIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
250
|
+
}
|
|
325
251
|
});
|
|
326
252
|
logics = { namespace: logicNamespace, data: logicData };
|
|
327
253
|
|
|
328
254
|
interfaceDependencies.push({ name, structures, logics });
|
|
329
255
|
});
|
|
330
|
-
return { interfaceDependencies };
|
|
256
|
+
return { code, interfaceDependencies };
|
|
331
257
|
}
|
|
332
258
|
|
|
333
|
-
export
|
|
334
|
-
|
|
335
|
-
interfaceDependencies.forEach((interfaceDependency: any, index: number) => {
|
|
336
|
-
interfaceDependency?.logics?.data?.forEach((item: any, idx: number) => {
|
|
337
|
-
const interfaceIndex = `7-${index}-${idx}`;
|
|
338
|
-
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
339
|
-
if (codeType === 'short') {
|
|
340
|
-
const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
|
|
341
|
-
code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
342
|
-
} else {
|
|
343
|
-
code += item.codeWithDetail;
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
return code;
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
// 连接
|
|
352
|
-
export function getConnections(modules: Connection[], state: TranslatorState) {
|
|
259
|
+
export function getConnectors(app: App, state: TranslatorState, requiredIndexes?: string[]) {
|
|
260
|
+
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
353
261
|
const connections = [] as {
|
|
354
262
|
name: string;
|
|
355
263
|
structures: SnippetBlock;
|
|
356
264
|
logics: SnippetBlock;
|
|
357
265
|
}[];
|
|
358
|
-
|
|
266
|
+
let code = '';
|
|
267
|
+
app?.connections?.forEach((connection, connectionIndex) => {
|
|
359
268
|
const name = connection?.name;
|
|
360
269
|
|
|
361
270
|
let structures = {} as SnippetBlock;
|
|
@@ -370,172 +279,98 @@ export function getConnections(modules: Connection[], state: TranslatorState) {
|
|
|
370
279
|
});
|
|
371
280
|
structures = { namespace: structureNamespace, data: structureData };
|
|
372
281
|
|
|
282
|
+
code += `[8-${connectionIndex}] ${connection?.connector?.title}\n`;
|
|
373
283
|
const logicData = [] as Snippet[];
|
|
374
|
-
connection?.connector?.namespaces?.forEach((namespace: Namespace) => {
|
|
375
|
-
|
|
376
|
-
|
|
284
|
+
connection?.connector?.namespaces?.forEach((namespace: Namespace, namespaceIndex: number) => {
|
|
285
|
+
namespace?.logics?.forEach((logic: Logic, index) => {
|
|
286
|
+
const logicIndex = `8-${connectionIndex}-${namespaceIndex}-${index}`;
|
|
287
|
+
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
377
288
|
const description = `${logic?.description || logic?.title || ''}`;
|
|
378
|
-
const rename = `${connection?.name}.${logic?.calleewholeKey}
|
|
379
|
-
const
|
|
380
|
-
const
|
|
381
|
-
logicData.push({ description, code: tempCode
|
|
289
|
+
const rename = requiredIndexes?.length >= 0 ? `${connection?.name}.${logic?.calleewholeKey}` : undefined;
|
|
290
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
291
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, code, { needNamespace, rename, declaration: true }))}`;
|
|
292
|
+
logicData.push({ description, code: tempCode });
|
|
293
|
+
|
|
294
|
+
if (requiredIndexes?.includes(logicIndex)) {
|
|
295
|
+
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
296
|
+
} else {
|
|
297
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
298
|
+
}
|
|
382
299
|
});
|
|
383
300
|
});
|
|
384
301
|
|
|
385
302
|
if (!connection?.connector?.namespaces?.length && connection?.connector?.logics?.length) {
|
|
386
|
-
connection?.connector?.logics.forEach((logic: Logic) => {
|
|
303
|
+
connection?.connector?.logics.forEach((logic: Logic, index: number) => {
|
|
304
|
+
const logicIndex = `8-${connectionIndex}-${index}`;
|
|
305
|
+
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
387
306
|
const description = logic?.description || '';
|
|
388
|
-
const rename = `${connection?.name}.${logic?.calleewholeKey}
|
|
389
|
-
const
|
|
390
|
-
const
|
|
391
|
-
logicData.push({ description, code: tempCode
|
|
307
|
+
const rename = requiredIndexes?.length >= 0 ? `${connection?.name}.${logic?.calleewholeKey}` : undefined;
|
|
308
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
309
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, code, { needNamespace, rename, declaration: true }))}`;
|
|
310
|
+
logicData.push({ description, code: tempCode });
|
|
311
|
+
|
|
312
|
+
if (requiredIndexes?.includes(logicIndex)) {
|
|
313
|
+
code += getLogicStructures(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
314
|
+
} else {
|
|
315
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
316
|
+
}
|
|
392
317
|
});
|
|
393
318
|
}
|
|
394
319
|
logics = { namespace: connectionNamespace, data: logicData };
|
|
395
320
|
connections.push({ name, structures, logics });
|
|
396
321
|
});
|
|
397
|
-
return { connections };
|
|
322
|
+
return { code, connections };
|
|
398
323
|
}
|
|
399
324
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const connectors = [] as {
|
|
403
|
-
name: string;
|
|
404
|
-
structures: SnippetBlock;
|
|
405
|
-
logics: SnippetBlock;
|
|
406
|
-
}[];
|
|
407
|
-
modules?.forEach((connector) => {
|
|
408
|
-
connector = new Connector(connector);
|
|
409
|
-
connector.parentKey = 'connectorDependencies';
|
|
410
|
-
const { name } = connector;
|
|
411
|
-
let structures = {} as SnippetBlock;
|
|
412
|
-
let logics = {} as SnippetBlock;
|
|
413
|
-
|
|
414
|
-
const connectorNamespace = `${name}.connector.${name}`;
|
|
415
|
-
const structureNamespace = `connector.${name}.structures`;
|
|
416
|
-
const structureData = [] as Snippet[];
|
|
417
|
-
connector?.structures?.forEach((structure: Structure) => {
|
|
418
|
-
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
419
|
-
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
420
|
-
});
|
|
421
|
-
structures = { namespace: structureNamespace, data: structureData };
|
|
422
|
-
|
|
423
|
-
const logicData = [] as Snippet[];
|
|
424
|
-
connector?.namespaces?.forEach((namespace: Namespace) => {
|
|
425
|
-
const curNameSpace = `${connectorNamespace}.${namespace?.name}`;
|
|
426
|
-
namespace?.logics?.forEach((logic: Logic) => {
|
|
427
|
-
const description = `${logic?.description || logic?.title || ''}`;
|
|
428
|
-
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
429
|
-
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
430
|
-
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
431
|
-
logicData.push({ description, code: tempCode, codeWithDetail, namespace: curNameSpace });
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
if (!connector?.namespaces?.length && connector?.logics?.length) {
|
|
436
|
-
connector?.logics.forEach((logic: Logic) => {
|
|
437
|
-
const description = logic?.description || '';
|
|
438
|
-
const rename = `${name}.${logic?.calleewholeKey}`;
|
|
439
|
-
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
440
|
-
const codeWithDetail = getLogicWithStructuresCode(logic, 'connector', { description, codeStr: tempCode }, structureNamespace);
|
|
441
|
-
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
logics = { namespace: connectorNamespace, data: logicData };
|
|
445
|
-
connectors.push({ name, structures, logics });
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
return { connectors };
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
export const getConnectorsCode = (connections: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
452
|
-
let code = '';
|
|
453
|
-
connections.forEach((connection: any, index: number) => {
|
|
454
|
-
connection?.logics?.data?.forEach((item: any, idx: number) => {
|
|
455
|
-
const interfaceIndex = `8-${index}-${idx}`;
|
|
456
|
-
if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
|
|
457
|
-
if (codeType === 'short') {
|
|
458
|
-
const namespace = item?.namespace || connection?.logics.namespace;
|
|
459
|
-
const tempCode = item.code.replace(`${namespace}.`, '');
|
|
460
|
-
code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
|
|
461
|
-
} else {
|
|
462
|
-
code += item.codeWithDetail;
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
});
|
|
466
|
-
return code;
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
export function getDependencies(modules: Module[], state: TranslatorState, logicType: any, frontendType: 'pc' | 'h5') {
|
|
325
|
+
export function getDependencies(app: App, state: TranslatorState, requiredIndexes?: string[]) {
|
|
326
|
+
const hasModuleIndexList = requiredIndexes?.length > 0;
|
|
471
327
|
const dependencies = [] as {
|
|
472
328
|
name: string;
|
|
473
329
|
structures: SnippetBlock;
|
|
474
330
|
logics: SnippetBlock;
|
|
475
331
|
}[];
|
|
476
|
-
modules?.forEach((module) => {
|
|
477
|
-
module = new Module(module);
|
|
478
|
-
module.parentKey = 'dependencies';
|
|
479
|
-
// 根据类型获取对应的逻辑
|
|
480
|
-
let curLogics = module?.logics;
|
|
481
|
-
if (logicType !== 'global_logic' && frontendType) {
|
|
482
|
-
module?.frontends?.forEach((frontend: any) => {
|
|
483
|
-
if (frontend.type === frontendType) {
|
|
484
|
-
curLogics = curLogics.concat([...frontend?.logics]);
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
if (curLogics?.length) {
|
|
490
|
-
const name = module?.name;
|
|
491
|
-
let structures = {} as SnippetBlock;
|
|
492
|
-
let logics = {} as SnippetBlock;
|
|
493
|
-
const namespace = `extensions.${name}`;
|
|
494
|
-
const structureNamespace = `${namespace}.structures`;
|
|
495
|
-
const structureData = [] as Snippet[];
|
|
496
|
-
module?.structures?.forEach((structure) => {
|
|
497
|
-
const tempCode = structure?.toNaturalTS ? `${structure?.toNaturalTS({ ...state, needNamespace: true })}` : '';
|
|
498
|
-
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
499
|
-
});
|
|
500
|
-
structures = { namespace: structureNamespace, data: structureData };
|
|
501
|
-
|
|
502
|
-
let logicsNamespace = '';
|
|
503
|
-
const logicData = [] as Snippet[];
|
|
504
|
-
curLogics?.forEach((logic) => {
|
|
505
|
-
const description = logic?.description || '';
|
|
506
|
-
const rename = logic?.calleewholeKey;
|
|
507
|
-
logicsNamespace = logic?.calleewholeKey.replace(`.${logic.name}`, '');
|
|
508
|
-
const tempCode = `${logic?.toNaturalTS(shiftState(state, '', { needNamespace: true, rename, declaration: true }))}`;
|
|
509
|
-
const codeWithDetail = getLogicWithStructuresCode(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
510
|
-
|
|
511
|
-
logicData.push({ description, code: tempCode, codeWithDetail });
|
|
512
|
-
});
|
|
513
|
-
logics = { namespace: logicsNamespace, data: logicData };
|
|
514
|
-
|
|
515
|
-
dependencies.push({ name, structures, logics });
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
return { dependencies };
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
export const getDependenciesCode = (dependencies: any, codeType: 'detail' | 'short', requiredIndexes?: string[]) => {
|
|
523
332
|
let code = '';
|
|
524
|
-
dependencies
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
333
|
+
app?.dependencies
|
|
334
|
+
?.filter((dependency) => dependency.concept === 'Module')
|
|
335
|
+
?.forEach((module, moduleIndex) => {
|
|
336
|
+
// 区分一下扩展组件和依赖库
|
|
337
|
+
if (module?.logics?.length) {
|
|
338
|
+
const name = module?.name;
|
|
339
|
+
let structures = {} as SnippetBlock;
|
|
340
|
+
let logics = {} as SnippetBlock;
|
|
341
|
+
const namespace = `extensions.${name}`;
|
|
342
|
+
const structureNamespace = `${namespace}.structures`;
|
|
343
|
+
const structureData = [] as Snippet[];
|
|
344
|
+
module?.structures?.forEach((structure) => {
|
|
345
|
+
const tempCode = `${structure?.toNaturalTS({ ...state, needNamespace: true })}`;
|
|
346
|
+
structureData.push({ description: structure?.description || structure?.name, code: tempCode });
|
|
347
|
+
});
|
|
348
|
+
structures = { namespace: structureNamespace, data: structureData };
|
|
349
|
+
|
|
350
|
+
const logicsNamespace = `${namespace}.logics`;
|
|
351
|
+
const logicData = [] as Snippet[];
|
|
352
|
+
module?.logics?.forEach((logic, index) => {
|
|
353
|
+
const logicIndex = `9-${moduleIndex}-${index}`;
|
|
354
|
+
if (hasModuleIndexList && !requiredIndexes?.includes(logicIndex)) return;
|
|
355
|
+
const description = logic?.description || '';
|
|
356
|
+
const rename = requiredIndexes?.length >= 0 ? logic?.calleewholeKey : undefined;
|
|
357
|
+
const needNamespace = requiredIndexes?.length >= 0;
|
|
358
|
+
const tempCode = `${logic?.toNaturalTS(shiftState(state, code, { needNamespace, rename, declaration: true }))}`;
|
|
359
|
+
logicData.push({ description, code: tempCode });
|
|
360
|
+
|
|
361
|
+
if (requiredIndexes?.includes(logicIndex)) {
|
|
362
|
+
code += getLogicStructures(logic, 'extension', { description, codeStr: tempCode }, structureNamespace);
|
|
363
|
+
} else {
|
|
364
|
+
code += `[${logicIndex}] ${description ? `${description}: ` : ''}\`${tempCode}\`\n`;
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
logics = { namespace: logicsNamespace, data: logicData };
|
|
368
|
+
|
|
369
|
+
dependencies.push({ name, structures, logics });
|
|
533
370
|
}
|
|
534
371
|
});
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
};
|
|
538
|
-
|
|
372
|
+
return { code, dependencies };
|
|
373
|
+
}
|
|
539
374
|
|
|
540
375
|
export function getFrontendVariables(frontend: Frontend, state: TranslatorState) {
|
|
541
376
|
let code = '';
|
|
@@ -593,17 +428,7 @@ export function getFrontendViews(frontend: Frontend, state: TranslatorState, cur
|
|
|
593
428
|
return { code: wrapTSBlock(code), views: { namespace, data } };
|
|
594
429
|
}
|
|
595
430
|
|
|
596
|
-
export
|
|
597
|
-
let code = '';
|
|
598
|
-
views?.data?.forEach((item: any) => {
|
|
599
|
-
code += `/* ${item.description} */ \n`;
|
|
600
|
-
code += item.code;
|
|
601
|
-
code += `\n`;
|
|
602
|
-
});
|
|
603
|
-
return wrapTSBlock(code);
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string) {
|
|
431
|
+
export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: string, experimental?: boolean) {
|
|
607
432
|
let code = '';
|
|
608
433
|
let view: View;
|
|
609
434
|
if (currentNode?.concept === 'View') {
|
|
@@ -631,16 +456,22 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
|
|
|
631
456
|
}),
|
|
632
457
|
function (state) {
|
|
633
458
|
let code = '';
|
|
634
|
-
code += `\n${indent(state.tabSize
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
code +=
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
)
|
|
642
|
-
|
|
643
|
-
|
|
459
|
+
code += `\n${indent(state.tabSize)}`;
|
|
460
|
+
|
|
461
|
+
if (experimental) {
|
|
462
|
+
code += this.elements[0].toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
|
|
463
|
+
} else {
|
|
464
|
+
code += `const $refs = {\n`;
|
|
465
|
+
// 生成所有的name和类型定义
|
|
466
|
+
this.elements.forEach((element) => {
|
|
467
|
+
code += element.toNaturalTSDefinition(
|
|
468
|
+
shiftState(state, code, {
|
|
469
|
+
tabSize: state.tabSize + 1,
|
|
470
|
+
})
|
|
471
|
+
);
|
|
472
|
+
});
|
|
473
|
+
code += `${indent(state.tabSize + 1)}}\n`;
|
|
474
|
+
}
|
|
644
475
|
// 逻辑
|
|
645
476
|
if (currentNode?.concept === 'Logic') {
|
|
646
477
|
code += '\n';
|