oak-domain 4.5.0 → 5.0.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/lib/base-app-domain/ActionDefDict.d.ts +1 -1
- package/lib/base-app-domain/ActionDefDict.js +4 -4
- package/lib/base-app-domain/I18n/Storage.js +0 -1
- package/lib/base-app-domain/Modi/Action.d.ts +1 -1
- package/lib/base-app-domain/Modi/Action.js +2 -2
- package/lib/base-app-domain/Modi/Style.d.ts +3 -0
- package/lib/base-app-domain/Modi/Style.js +16 -0
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +14 -0
- package/lib/base-app-domain/OperEntity/Schema.d.ts +14 -0
- package/lib/base-app-domain/StyleDict.d.ts +3 -0
- package/lib/base-app-domain/StyleDict.js +9 -0
- package/lib/base-app-domain/User/Action.d.ts +1 -1
- package/lib/base-app-domain/User/Action.js +2 -2
- package/lib/base-app-domain/User/Style.d.ts +3 -0
- package/lib/base-app-domain/User/Style.js +14 -0
- package/lib/base-app-domain/index.d.ts +1 -0
- package/lib/base-app-domain/index.js +1 -0
- package/lib/compiler/dependencyBuilder.d.ts +21 -0
- package/lib/compiler/dependencyBuilder.js +873 -0
- package/lib/compiler/env.d.ts +1 -1
- package/lib/compiler/env.js +2 -8
- package/lib/compiler/localeBuilder.js +13 -7
- package/lib/compiler/routerBuilder.js +29 -44
- package/lib/compiler/schemalBuilder.js +67 -8
- package/lib/entities/I18n.js +0 -3
- package/lib/entities/Modi.js +13 -0
- package/lib/entities/User.js +11 -0
- package/lib/store/IntrinsicCheckers.d.ts +2 -2
- package/lib/store/IntrinsicCheckers.js +83 -17
- package/lib/store/IntrinsicLogics.d.ts +2 -2
- package/lib/store/IntrinsicLogics.js +3 -3
- package/lib/store/filter.d.ts +47 -0
- package/lib/store/filter.js +49 -6
- package/lib/types/Action.d.ts +1 -1
- package/lib/types/Configuration.d.ts +42 -7
- package/lib/types/Configuration.js +0 -1
- package/lib/types/Connector.d.ts +3 -0
- package/lib/types/EntityDesc.d.ts +10 -3
- package/lib/types/Style.d.ts +35 -6
- package/lib/utils/SimpleConnector.d.ts +6 -10
- package/lib/utils/SimpleConnector.js +33 -20
- package/lib/utils/assert.d.ts +1 -0
- package/lib/utils/lodash.d.ts +10 -1
- package/lib/utils/lodash.js +27 -1
- package/lib/utils/module/combine.common.d.ts +15 -0
- package/lib/utils/module/combine.common.js +27 -0
- package/lib/utils/module/combine.d.ts +1 -0
- package/lib/utils/module/combine.dev.d.ts +17 -0
- package/lib/utils/module/combine.dev.js +55 -0
- package/lib/utils/module/combine.js +4 -0
- package/lib/utils/module/combine.prod.d.ts +8 -0
- package/lib/utils/module/combine.prod.js +8 -0
- package/lib/utils/module/combine.server.d.ts +17 -0
- package/lib/utils/module/combine.server.js +55 -0
- package/lib/utils/relationPath.js +1 -1
- package/package.json +1 -1
- package/src/entities/ActionAuth.ts +41 -41
- package/src/entities/I18n.ts +0 -3
- package/src/entities/Modi.ts +13 -0
- package/src/entities/ModiEntity.ts +26 -26
- package/src/entities/OperEntity.ts +27 -27
- package/src/entities/Path.ts +43 -43
- package/src/entities/Relation.ts +43 -43
- package/src/entities/RelationAuth.ts +44 -44
- package/src/entities/User.ts +12 -1
- package/src/entities/UserEntityClaim.ts +29 -29
- package/src/entities/UserEntityGrant.ts +24 -24
- package/src/entities/UserRelation.ts +50 -50
- package/lib/actions/relation.d.ts +0 -5
- package/lib/actions/relation.js +0 -25
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +0 -5
- package/lib/base-app-domain/UserEntityGrant/Action.js +0 -5
|
@@ -0,0 +1,873 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeDepedency = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
9
|
+
const string_1 = require("../utils/string");
|
|
10
|
+
const env_1 = require("./env");
|
|
11
|
+
const fs_extra_1 = require("fs-extra");
|
|
12
|
+
const { factory } = ts;
|
|
13
|
+
/**
|
|
14
|
+
* 构建项目依赖关系图
|
|
15
|
+
* @param cwd
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
function analyzeDepedency(cwd) {
|
|
19
|
+
const depGraph = {
|
|
20
|
+
nodeDict: {},
|
|
21
|
+
roots: [],
|
|
22
|
+
ascOrder: [],
|
|
23
|
+
};
|
|
24
|
+
function analyzeOne(dir, name, parent) {
|
|
25
|
+
const node = {
|
|
26
|
+
name,
|
|
27
|
+
parent,
|
|
28
|
+
};
|
|
29
|
+
if (name) {
|
|
30
|
+
depGraph.nodeDict[name] = node;
|
|
31
|
+
if (!parent) {
|
|
32
|
+
depGraph.roots.push(node);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let dependencies = [];
|
|
36
|
+
const depConfigTsFile = join(dir, 'src', 'configuration', 'dependency.ts');
|
|
37
|
+
if ((0, fs_1.existsSync)(depConfigTsFile)) {
|
|
38
|
+
// 这里依赖配置是ts文件,得翻译成js再读取
|
|
39
|
+
const result = ts.transpileModule((0, fs_1.readFileSync)(depConfigTsFile, 'utf-8'), { compilerOptions: { module: ts.ModuleKind.CommonJS } });
|
|
40
|
+
dependencies = eval(result.outputText);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const depConfigJsFile = join(dir, 'lib', 'configuration', 'dependency.js');
|
|
44
|
+
if ((0, fs_1.existsSync)(depConfigJsFile)) {
|
|
45
|
+
dependencies = require(depConfigJsFile);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// 没有依赖文件,直接返回
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
dependencies.forEach((dep) => {
|
|
53
|
+
const n2 = depGraph.nodeDict[dep];
|
|
54
|
+
if (n2) {
|
|
55
|
+
(0, assert_1.default)(name);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
let dir2 = join(cwd, 'node_modules', dep);
|
|
59
|
+
if (!(0, fs_1.existsSync)(dir2)) {
|
|
60
|
+
dir2 = join(dir, 'node_modules', dep);
|
|
61
|
+
if (!(0, fs_1.existsSync)(dir2)) {
|
|
62
|
+
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
analyzeOne(dir2, dep, name ? node : undefined);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
analyzeOne(cwd, '');
|
|
70
|
+
// 输出一个从底向上的序列,因为当前的项目中最多只有一个依赖,所以暂时不写
|
|
71
|
+
const deps = Object.keys(depGraph.nodeDict);
|
|
72
|
+
(0, assert_1.default)(deps.length <= 1);
|
|
73
|
+
depGraph.ascOrder = deps;
|
|
74
|
+
return depGraph;
|
|
75
|
+
}
|
|
76
|
+
exports.analyzeDepedency = analyzeDepedency;
|
|
77
|
+
function join(...paths) {
|
|
78
|
+
const path = (0, path_1.join)(...paths);
|
|
79
|
+
return path.replaceAll('\\', '/');
|
|
80
|
+
}
|
|
81
|
+
function destructVariableDeclaration(vd) {
|
|
82
|
+
(0, assert_1.default)(ts.isIdentifier(vd.name));
|
|
83
|
+
(0, assert_1.default)(vd.name.text.startsWith('total'));
|
|
84
|
+
const on = (0, string_1.firstLetterLowerCase)(vd.name.text.slice(5));
|
|
85
|
+
const { initializer } = vd;
|
|
86
|
+
(0, assert_1.default)(ts.isCallExpression(initializer));
|
|
87
|
+
(0, assert_1.default)(ts.isIdentifier(initializer.expression) && initializer.expression.text === 'mergeConcatMany');
|
|
88
|
+
(0, assert_1.default)(initializer.arguments.length === 1);
|
|
89
|
+
const [arg] = initializer.arguments;
|
|
90
|
+
(0, assert_1.default)(ts.isAsExpression(arg));
|
|
91
|
+
const { expression } = arg;
|
|
92
|
+
(0, assert_1.default)(ts.isArrayLiteralExpression(expression));
|
|
93
|
+
return {
|
|
94
|
+
on,
|
|
95
|
+
expression,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function outputPolyfillDts(dependencies, briefNames, sourceFile, printer, filename) {
|
|
99
|
+
let statements2 = [];
|
|
100
|
+
if (dependencies.length > 0) {
|
|
101
|
+
const { statements } = sourceFile;
|
|
102
|
+
(0, assert_1.default)(ts.isImportDeclaration(statements[5]) && ts.isModuleDeclaration(statements[6]));
|
|
103
|
+
const importStatements = [];
|
|
104
|
+
dependencies.forEach((dep, idx) => {
|
|
105
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`))])), factory.createStringLiteral(`${dep}/es/features`), undefined), factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("AspectDict"), factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(briefNames[idx])}AspectDict`))])), factory.createStringLiteral(`${dep}/es/aspects`), undefined));
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* declare global {
|
|
109
|
+
const OakComponent: MakeOakComponent<
|
|
110
|
+
EntityDict,
|
|
111
|
+
BackendRuntimeContext,
|
|
112
|
+
FrontendRuntimeContext,
|
|
113
|
+
AspectDict & OgbAspectDict<EntityDict, BackendRuntimeContext>,
|
|
114
|
+
FeatureDict & OgbFeatureDict<EntityDict>
|
|
115
|
+
>;
|
|
116
|
+
const features: FeatureDict & OgbFeatureDict<EntityDict>;
|
|
117
|
+
}
|
|
118
|
+
*/
|
|
119
|
+
const stmt6 = statements[6];
|
|
120
|
+
const { body } = stmt6;
|
|
121
|
+
const [ocStmt, featuresStmt] = body.statements;
|
|
122
|
+
(0, assert_1.default)(ts.isVariableStatement(ocStmt) && ts.isVariableStatement(featuresStmt));
|
|
123
|
+
const [ocVd] = ocStmt.declarationList.declarations;
|
|
124
|
+
const [featuresVd] = featuresStmt.declarationList.declarations;
|
|
125
|
+
(0, assert_1.default)(ts.isVariableDeclaration(ocVd) && ts.isIdentifier(ocVd.name) && ocVd.name.text === 'OakComponent');
|
|
126
|
+
(0, assert_1.default)(ts.isVariableDeclaration(featuresVd) && ts.isIdentifier(featuresVd.name) && featuresVd.name.text === 'features');
|
|
127
|
+
const ocType = ocVd.type;
|
|
128
|
+
(0, assert_1.default)(ts.isTypeReferenceNode(ocType) && ocType.typeArguments?.length === 5);
|
|
129
|
+
const aspectTypeNode = ocType.typeArguments[3];
|
|
130
|
+
const featureTypeNode = ocType.typeArguments[4];
|
|
131
|
+
(0, assert_1.default)(ts.isTypeReferenceNode(aspectTypeNode) && ts.isTypeReferenceNode(featureTypeNode));
|
|
132
|
+
Object.assign(ocType, {
|
|
133
|
+
typeArguments: [
|
|
134
|
+
...ocType.typeArguments.slice(0, 3),
|
|
135
|
+
factory.createIntersectionTypeNode([
|
|
136
|
+
aspectTypeNode,
|
|
137
|
+
...briefNames.map((ele) => factory.createTypeReferenceNode(factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(ele)}AspectDict`), [
|
|
138
|
+
factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)
|
|
139
|
+
]))
|
|
140
|
+
]),
|
|
141
|
+
factory.createIntersectionTypeNode([
|
|
142
|
+
featureTypeNode,
|
|
143
|
+
...briefNames.map((ele) => factory.createTypeReferenceNode(factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(ele)}FeatureDict`), [
|
|
144
|
+
factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined),
|
|
145
|
+
factory.createTypeReferenceNode(factory.createIdentifier("BackendRuntimeContext"), undefined)
|
|
146
|
+
]))
|
|
147
|
+
])
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
const featureType = featuresVd.type;
|
|
151
|
+
(0, assert_1.default)(ts.isTypeReferenceNode(featureType));
|
|
152
|
+
Object.assign(featuresVd, {
|
|
153
|
+
type: factory.createIntersectionTypeNode([
|
|
154
|
+
featureType,
|
|
155
|
+
...briefNames.map((ele) => factory.createTypeReferenceNode(factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(ele)}FeatureDict`), [
|
|
156
|
+
factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined),
|
|
157
|
+
factory.createTypeReferenceNode(factory.createIdentifier("BackendRuntimeContext"), undefined)
|
|
158
|
+
]))
|
|
159
|
+
])
|
|
160
|
+
});
|
|
161
|
+
statements2 = [
|
|
162
|
+
...statements.slice(0, 6),
|
|
163
|
+
...importStatements,
|
|
164
|
+
...statements.slice(6)
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
statements2 = [...sourceFile.statements];
|
|
169
|
+
}
|
|
170
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
171
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
172
|
+
console.log(`构建${filename}文件成功`);
|
|
173
|
+
}
|
|
174
|
+
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename) {
|
|
175
|
+
let statements2 = [];
|
|
176
|
+
if (dependencies.length > 0) {
|
|
177
|
+
const { statements } = sourceFile;
|
|
178
|
+
(0, assert_1.default)(ts.isImportDeclaration(statements[2]) && ts.isFunctionDeclaration(statements[3]));
|
|
179
|
+
const importStatements = [];
|
|
180
|
+
dependencies.forEach((dep, idx) => {
|
|
181
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("makeException"), factory.createIdentifier(`make${(0, string_1.firstLetterUpperCase)(briefNames[idx])}Exception`))])), factory.createStringLiteral(dep), undefined));
|
|
182
|
+
});
|
|
183
|
+
const stmt3 = statements[3];
|
|
184
|
+
const funcStmt0 = stmt3.body?.statements[0];
|
|
185
|
+
(0, assert_1.default)(ts.isVariableStatement(funcStmt0));
|
|
186
|
+
const vd = funcStmt0.declarationList.declarations[0];
|
|
187
|
+
const { name, initializer } = vd;
|
|
188
|
+
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'e');
|
|
189
|
+
(0, assert_1.default)(ts.isCallExpression(initializer));
|
|
190
|
+
const callExpressions = briefNames.map(ele => factory.createCallExpression(factory.createIdentifier(`make${(0, string_1.firstLetterUpperCase)(ele)}Exception`), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)], [factory.createIdentifier("data")]));
|
|
191
|
+
const rightExpression = callExpressions.length === 1 ? callExpressions[0] :
|
|
192
|
+
callExpressions.length === 2 ? factory.createBinaryExpression(callExpressions[0], factory.createToken(ts.SyntaxKind.BarBarToken), callExpressions[1]) : callExpressions.slice(2).reduce((prev, next) => factory.createBinaryExpression(prev, factory.createToken(ts.SyntaxKind.BarBarToken), next), factory.createBinaryExpression(callExpressions[0], factory.createToken(ts.SyntaxKind.BarBarToken), callExpressions[1]));
|
|
193
|
+
Object.assign(vd, {
|
|
194
|
+
initializer: factory.createBinaryExpression(initializer, factory.createToken(ts.SyntaxKind.BarBarToken), rightExpression)
|
|
195
|
+
});
|
|
196
|
+
statements2 = [
|
|
197
|
+
...statements.slice(0, 3),
|
|
198
|
+
...importStatements,
|
|
199
|
+
...statements.slice(3)
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
statements2 = [...sourceFile.statements];
|
|
204
|
+
}
|
|
205
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
206
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
207
|
+
console.log(`构建${filename}文件成功`);
|
|
208
|
+
}
|
|
209
|
+
function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filename) {
|
|
210
|
+
let statements2 = [];
|
|
211
|
+
if (dependencies.length > 0) {
|
|
212
|
+
const { statements } = sourceFile;
|
|
213
|
+
const importStatements = [];
|
|
214
|
+
const stmt9 = statements[9];
|
|
215
|
+
const stmt10 = statements[10];
|
|
216
|
+
(0, assert_1.default)(ts.isTypeAliasDeclaration(stmt9) && ts.isIdentifier(stmt9.name) && stmt9.name.text === 'AAD');
|
|
217
|
+
(0, assert_1.default)(ts.isTypeAliasDeclaration(stmt10) && ts.isIdentifier(stmt10.name) && stmt10.name.text === 'AFD');
|
|
218
|
+
(0, assert_1.default)(ts.isImportDeclaration(statements[5]) && ts.isTypeAliasDeclaration(statements[6]));
|
|
219
|
+
const AADs = [];
|
|
220
|
+
const AFDs = [];
|
|
221
|
+
dependencies.forEach((dep, idx) => {
|
|
222
|
+
const featureName = `${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`;
|
|
223
|
+
const aspectName = `${(0, string_1.firstLetterUpperCase)(briefNames[idx])}AspectDict`;
|
|
224
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
225
|
+
factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(featureName)),
|
|
226
|
+
factory.createImportSpecifier(false, factory.createIdentifier("AspectDict"), factory.createIdentifier(aspectName))
|
|
227
|
+
])), factory.createStringLiteral(dep), undefined));
|
|
228
|
+
AFDs.push(featureName);
|
|
229
|
+
AADs.push(aspectName);
|
|
230
|
+
});
|
|
231
|
+
{
|
|
232
|
+
const { type } = stmt9;
|
|
233
|
+
(0, assert_1.default)(ts.isTypeReferenceNode(type));
|
|
234
|
+
Object.assign(stmt9, {
|
|
235
|
+
type: factory.createIntersectionTypeNode([
|
|
236
|
+
type,
|
|
237
|
+
...AADs.map(ele => factory.createTypeReferenceNode(factory.createIdentifier(ele), [factory.createTypeReferenceNode('EntityDict')]))
|
|
238
|
+
])
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
{
|
|
242
|
+
const { type } = stmt10;
|
|
243
|
+
(0, assert_1.default)(ts.isIntersectionTypeNode(type));
|
|
244
|
+
const { types } = type;
|
|
245
|
+
Object.assign(type, {
|
|
246
|
+
types: [
|
|
247
|
+
...types,
|
|
248
|
+
...AFDs.map(ele => factory.createTypeReferenceNode(factory.createIdentifier(ele), [factory.createTypeReferenceNode('EntityDict')]))
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
statements2 = [
|
|
253
|
+
...statements.slice(0, 6),
|
|
254
|
+
...importStatements,
|
|
255
|
+
...statements.slice(6)
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
statements2 = [
|
|
260
|
+
...sourceFile.statements
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
264
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
265
|
+
console.log(`构建${filename}文件成功`);
|
|
266
|
+
}
|
|
267
|
+
function outputDependentContext(depGraph, printer, filename) {
|
|
268
|
+
// 目前只支持单向依赖,未来可以利用mixin来实现多类的继承
|
|
269
|
+
(0, assert_1.default)(depGraph.roots.length <= 1);
|
|
270
|
+
let root = depGraph.roots[0] ? depGraph.roots[0].name : 'oak-frontend-base';
|
|
271
|
+
const statements = [
|
|
272
|
+
factory.createExportDeclaration(undefined, false, factory.createNamedExports([
|
|
273
|
+
factory.createExportSpecifier(false, undefined, factory.createIdentifier("BackendRuntimeContext")),
|
|
274
|
+
factory.createExportSpecifier(false, undefined, factory.createIdentifier("FrontendRuntimeContext"))
|
|
275
|
+
]), factory.createStringLiteral(root), undefined)
|
|
276
|
+
];
|
|
277
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS));
|
|
278
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
279
|
+
console.log(`构建${filename}文件成功`);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 生成initialize.prod.ts
|
|
283
|
+
* @param cwd
|
|
284
|
+
* @param dependencies
|
|
285
|
+
* @param briefNames
|
|
286
|
+
* @param sourceFile
|
|
287
|
+
* @param printer
|
|
288
|
+
*/
|
|
289
|
+
function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
|
290
|
+
const { statements } = sourceFile;
|
|
291
|
+
const objectDict = {};
|
|
292
|
+
// 所有的import
|
|
293
|
+
const importStatements = [];
|
|
294
|
+
dependencies.forEach((dep, idx) => {
|
|
295
|
+
const depDir = join(cwd, 'node_modules', dep);
|
|
296
|
+
if (!(0, fs_1.existsSync)(depDir)) {
|
|
297
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录【${depDir}】`);
|
|
298
|
+
}
|
|
299
|
+
const esDir = join(depDir, 'es');
|
|
300
|
+
const libDir = join(depDir, 'lib');
|
|
301
|
+
const esDirExisted = (0, fs_1.existsSync)(esDir);
|
|
302
|
+
const libDirExisted = (0, fs_1.existsSync)(libDir);
|
|
303
|
+
if (!esDirExisted && !libDirExisted) {
|
|
304
|
+
throw new Error(`依赖模块${dep}中没有es或者lib目录`);
|
|
305
|
+
}
|
|
306
|
+
const destDir = esDirExisted ? esDir : libDir;
|
|
307
|
+
const destDirName = esDirExisted ? 'es' : 'lib';
|
|
308
|
+
const objectDirs = ['checkers'];
|
|
309
|
+
objectDirs.forEach((o) => {
|
|
310
|
+
if ((0, fs_1.existsSync)(join(destDir, o))) {
|
|
311
|
+
const variableName = `${briefNames[idx]}${(0, string_1.firstLetterUpperCase)(o)}`;
|
|
312
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, o)), undefined));
|
|
313
|
+
if (objectDict[o]) {
|
|
314
|
+
objectDict[o].push(variableName);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
objectDict[o] = [variableName];
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
// common
|
|
322
|
+
if ((0, fs_1.existsSync)(join(destDir, 'configuration'))) {
|
|
323
|
+
const variableName = `${briefNames[idx]}Common`;
|
|
324
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'configuration')), undefined));
|
|
325
|
+
if (objectDict.common) {
|
|
326
|
+
objectDict.common.push(variableName);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
objectDict.common = [variableName];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// render
|
|
333
|
+
if ((0, fs_1.existsSync)(join(destDir, 'configuration', 'render.js'))) {
|
|
334
|
+
const variableName = `${briefNames[idx]}Render`;
|
|
335
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'configuration', 'render')), undefined));
|
|
336
|
+
if (objectDict.render) {
|
|
337
|
+
objectDict.render.push(variableName);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
objectDict.render = [variableName];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
// features
|
|
344
|
+
if ((0, fs_1.existsSync)(join(destDir, 'features'))) {
|
|
345
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
346
|
+
factory.createImportSpecifier(false, factory.createIdentifier("create"), factory.createIdentifier(`create${(0, string_1.firstLetterUpperCase)(briefNames[idx])}Features`)),
|
|
347
|
+
factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`))
|
|
348
|
+
])), factory.createStringLiteral(join(dep, destDirName, 'features')), undefined));
|
|
349
|
+
if (objectDict.features) {
|
|
350
|
+
objectDict.features.push(briefNames[idx]);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
objectDict.features = [briefNames[idx]];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
const funcStmt = statements.find((stmt) => ts.isFunctionDeclaration(stmt) && stmt.modifiers?.find(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) && stmt.modifiers.find(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword));
|
|
358
|
+
(0, assert_1.default)(funcStmt);
|
|
359
|
+
const idx = statements.indexOf(funcStmt);
|
|
360
|
+
const statements2 = [
|
|
361
|
+
...statements.slice(0, idx),
|
|
362
|
+
...importStatements,
|
|
363
|
+
...statements.slice(idx)
|
|
364
|
+
];
|
|
365
|
+
const stmt0 = funcStmt.body?.statements[0];
|
|
366
|
+
(0, assert_1.default)(ts.isVariableStatement(stmt0));
|
|
367
|
+
let vdl = stmt0.declarationList;
|
|
368
|
+
vdl.declarations.forEach((declaration) => {
|
|
369
|
+
const { on, expression } = destructVariableDeclaration(declaration);
|
|
370
|
+
if (objectDict[on]) {
|
|
371
|
+
const { elements } = expression;
|
|
372
|
+
Object.assign(expression, {
|
|
373
|
+
elements: elements.concat(...objectDict[on].map(ele => factory.createIdentifier(ele)))
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
if (objectDict.features) {
|
|
378
|
+
const stmt1 = funcStmt.body?.statements[1];
|
|
379
|
+
(0, assert_1.default)(ts.isVariableStatement(stmt1));
|
|
380
|
+
const tfDec = stmt1.declarationList.declarations[0];
|
|
381
|
+
const { name, initializer } = tfDec;
|
|
382
|
+
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'totalFeatures');
|
|
383
|
+
(0, assert_1.default)(ts.isAsExpression(initializer));
|
|
384
|
+
const { type } = initializer;
|
|
385
|
+
(0, assert_1.default)(ts.isIntersectionTypeNode(type));
|
|
386
|
+
Object.assign(type, {
|
|
387
|
+
types: type.types.concat(objectDict.features.map(ele => factory.createTypeReferenceNode(`${(0, string_1.firstLetterUpperCase)(ele)}FeatureDict`, [
|
|
388
|
+
factory.createTypeReferenceNode('EntityDict')
|
|
389
|
+
])))
|
|
390
|
+
});
|
|
391
|
+
Object.assign(funcStmt.body, {
|
|
392
|
+
statements: [
|
|
393
|
+
...funcStmt.body.statements.slice(0, 4),
|
|
394
|
+
...objectDict.features.map((ele) => [
|
|
395
|
+
factory.createVariableStatement(undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(`${ele}Features`), undefined, undefined, factory.createCallExpression(factory.createIdentifier(`create${(0, string_1.firstLetterUpperCase)(ele)}Features`), undefined, [factory.createIdentifier("totalFeatures")]))], ts.NodeFlags.Const)),
|
|
396
|
+
factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("assign")), undefined, [
|
|
397
|
+
factory.createIdentifier("totalFeatures"),
|
|
398
|
+
factory.createIdentifier(`${ele}Features`)
|
|
399
|
+
]))
|
|
400
|
+
]).flat(),
|
|
401
|
+
...funcStmt.body.statements.slice(4),
|
|
402
|
+
]
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
406
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
407
|
+
console.log(`构建${filename}文件成功`);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* 生成initialize.dev.ts
|
|
411
|
+
* @param cwd
|
|
412
|
+
* @param dependencies
|
|
413
|
+
* @param briefNames
|
|
414
|
+
* @param sourceFile
|
|
415
|
+
* @param printer
|
|
416
|
+
*/
|
|
417
|
+
function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
|
418
|
+
const { statements } = sourceFile;
|
|
419
|
+
const objectDict = {};
|
|
420
|
+
// 所有的import
|
|
421
|
+
const importStatements = [];
|
|
422
|
+
dependencies.forEach((dep, idx) => {
|
|
423
|
+
const depDir = join(cwd, 'node_modules', dep);
|
|
424
|
+
if (!(0, fs_1.existsSync)(depDir)) {
|
|
425
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录【${depDir}】`);
|
|
426
|
+
}
|
|
427
|
+
const esDir = join(depDir, 'es');
|
|
428
|
+
const libDir = join(depDir, 'lib');
|
|
429
|
+
const esDirExisted = (0, fs_1.existsSync)(esDir);
|
|
430
|
+
const libDirExisted = (0, fs_1.existsSync)(libDir);
|
|
431
|
+
if (!esDirExisted && !libDirExisted) {
|
|
432
|
+
throw new Error(`依赖模块${dep}中没有es或者lib目录`);
|
|
433
|
+
}
|
|
434
|
+
const destDir = esDirExisted ? esDir : libDir;
|
|
435
|
+
const destDirName = esDirExisted ? 'es' : 'lib';
|
|
436
|
+
const objectDirs = ['triggers', 'checkers', 'watchers', 'timers', 'data', 'aspects'];
|
|
437
|
+
objectDirs.forEach((o) => {
|
|
438
|
+
if ((0, fs_1.existsSync)(join(destDir, o))) {
|
|
439
|
+
const variableName = `${briefNames[idx]}${(0, string_1.firstLetterUpperCase)(o)}`;
|
|
440
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, o)), undefined));
|
|
441
|
+
if (objectDict[o]) {
|
|
442
|
+
objectDict[o].push(variableName);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
objectDict[o] = [variableName];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
// startRoutine
|
|
450
|
+
if ((0, fs_1.existsSync)(join(destDir, 'routines', 'start'))) {
|
|
451
|
+
const variableName = `${briefNames[idx]}StartRoutines`;
|
|
452
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'routines/start')), undefined));
|
|
453
|
+
if (objectDict.startRoutines) {
|
|
454
|
+
objectDict.startRoutines.push(variableName);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
objectDict.startRoutines = [variableName];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// common
|
|
461
|
+
if ((0, fs_1.existsSync)(join(destDir, 'configuration'))) {
|
|
462
|
+
const variableName = `${briefNames[idx]}Common`;
|
|
463
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'configuration')), undefined));
|
|
464
|
+
if (objectDict.common) {
|
|
465
|
+
objectDict.common.push(variableName);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
objectDict.common = [variableName];
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
// render
|
|
472
|
+
if ((0, fs_1.existsSync)(join(destDir, 'configuration', 'render.js'))) {
|
|
473
|
+
const variableName = `${briefNames[idx]}Render`;
|
|
474
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'configuration', 'render')), undefined));
|
|
475
|
+
if (objectDict.render) {
|
|
476
|
+
objectDict.render.push(variableName);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
objectDict.render = [variableName];
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
// features
|
|
483
|
+
if ((0, fs_1.existsSync)(join(destDir, 'features'))) {
|
|
484
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
485
|
+
factory.createImportSpecifier(false, factory.createIdentifier("create"), factory.createIdentifier(`create${(0, string_1.firstLetterUpperCase)(briefNames[idx])}Features`)),
|
|
486
|
+
factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`))
|
|
487
|
+
])), factory.createStringLiteral(join(dep, destDirName, 'features')), undefined));
|
|
488
|
+
if (objectDict.features) {
|
|
489
|
+
objectDict.features.push(briefNames[idx]);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
objectDict.features = [briefNames[idx]];
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// ports
|
|
496
|
+
if ((0, fs_1.existsSync)(join(destDir, 'ports'))) {
|
|
497
|
+
const importVariableName = `${briefNames[idx]}Importations`;
|
|
498
|
+
const exportVariableName = `${briefNames[idx]}Exportations`;
|
|
499
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
500
|
+
factory.createImportSpecifier(false, factory.createIdentifier("importations"), factory.createIdentifier(importVariableName)),
|
|
501
|
+
factory.createImportSpecifier(false, factory.createIdentifier("exportations"), factory.createIdentifier(exportVariableName))
|
|
502
|
+
])), factory.createStringLiteral(join(dep, destDirName, 'ports')), undefined));
|
|
503
|
+
if (objectDict.importations) {
|
|
504
|
+
objectDict.importations.push(importVariableName);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
objectDict.importations = [importVariableName];
|
|
508
|
+
}
|
|
509
|
+
if (objectDict.exportations) {
|
|
510
|
+
objectDict.exportations.push(exportVariableName);
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
objectDict.exportations = [exportVariableName];
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
const funcStmt = statements.find((stmt) => ts.isFunctionDeclaration(stmt) && stmt.modifiers?.find(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) && stmt.modifiers.find(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword));
|
|
518
|
+
(0, assert_1.default)(funcStmt);
|
|
519
|
+
const idx = statements.indexOf(funcStmt);
|
|
520
|
+
const statements2 = [
|
|
521
|
+
...statements.slice(0, idx),
|
|
522
|
+
...importStatements,
|
|
523
|
+
...statements.slice(idx)
|
|
524
|
+
];
|
|
525
|
+
const stmt0 = funcStmt.body?.statements[0];
|
|
526
|
+
(0, assert_1.default)(ts.isVariableStatement(stmt0));
|
|
527
|
+
let vdl = stmt0.declarationList;
|
|
528
|
+
vdl.declarations.forEach((declaration) => {
|
|
529
|
+
const { on, expression } = destructVariableDeclaration(declaration);
|
|
530
|
+
if (objectDict[on]) {
|
|
531
|
+
const { elements } = expression;
|
|
532
|
+
Object.assign(expression, {
|
|
533
|
+
elements: elements.concat(...objectDict[on].map(ele => factory.createIdentifier(ele)))
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
if (objectDict.features) {
|
|
538
|
+
const stmt2 = funcStmt.body?.statements[2];
|
|
539
|
+
(0, assert_1.default)(ts.isVariableStatement(stmt2));
|
|
540
|
+
const tfDec = stmt2.declarationList.declarations[0];
|
|
541
|
+
const { name, initializer } = tfDec;
|
|
542
|
+
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'totalFeatures');
|
|
543
|
+
(0, assert_1.default)(ts.isAsExpression(initializer));
|
|
544
|
+
const { type } = initializer;
|
|
545
|
+
(0, assert_1.default)(ts.isIntersectionTypeNode(type));
|
|
546
|
+
Object.assign(type, {
|
|
547
|
+
types: type.types.concat(objectDict.features.map(ele => factory.createTypeReferenceNode(`${(0, string_1.firstLetterUpperCase)(ele)}FeatureDict`, [
|
|
548
|
+
factory.createTypeReferenceNode('EntityDict')
|
|
549
|
+
])))
|
|
550
|
+
});
|
|
551
|
+
Object.assign(funcStmt.body, {
|
|
552
|
+
statements: [
|
|
553
|
+
...funcStmt.body.statements.slice(0, 5),
|
|
554
|
+
...objectDict.features.map((ele) => [
|
|
555
|
+
factory.createVariableStatement(undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(`${ele}Features`), undefined, undefined, factory.createCallExpression(factory.createIdentifier(`create${(0, string_1.firstLetterUpperCase)(ele)}Features`), undefined, [factory.createIdentifier("totalFeatures")]))], ts.NodeFlags.Const)),
|
|
556
|
+
factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), factory.createIdentifier("assign")), undefined, [
|
|
557
|
+
factory.createIdentifier("totalFeatures"),
|
|
558
|
+
factory.createIdentifier(`${ele}Features`)
|
|
559
|
+
]))
|
|
560
|
+
]).flat(),
|
|
561
|
+
...funcStmt.body.statements.slice(5),
|
|
562
|
+
]
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
566
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
567
|
+
console.log(`构建${filename}文件成功`);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* 根据依赖关系,输出features/index.ts
|
|
571
|
+
* @param cwd
|
|
572
|
+
* @param dependencies
|
|
573
|
+
* @param briefNames
|
|
574
|
+
* @param printer
|
|
575
|
+
* @param filename
|
|
576
|
+
*/
|
|
577
|
+
function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filename) {
|
|
578
|
+
const { statements } = sourceFile;
|
|
579
|
+
let statements2 = [];
|
|
580
|
+
if (dependencies.length > 0) {
|
|
581
|
+
const importStatements = [];
|
|
582
|
+
const fdNames = [];
|
|
583
|
+
dependencies.forEach((dep, idx) => {
|
|
584
|
+
const fdName = `${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`;
|
|
585
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(fdName))])), factory.createStringLiteral(dep), undefined));
|
|
586
|
+
fdNames.push(fdName);
|
|
587
|
+
});
|
|
588
|
+
const stmt4 = statements[4], stmt5 = statements[5];
|
|
589
|
+
(0, assert_1.default)(ts.isImportDeclaration(stmt4) && ts.isFunctionDeclaration(stmt5));
|
|
590
|
+
const { name, parameters } = stmt5;
|
|
591
|
+
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'create' && parameters.length === 1);
|
|
592
|
+
const [param] = parameters;
|
|
593
|
+
const { name: paramName, type } = param;
|
|
594
|
+
(0, assert_1.default)(ts.isIdentifier(paramName) && paramName.text === 'features' && ts.isTypeReferenceNode(type));
|
|
595
|
+
Object.assign(param, {
|
|
596
|
+
type: factory.createIntersectionTypeNode([
|
|
597
|
+
type,
|
|
598
|
+
...fdNames.map(ele => factory.createTypeReferenceNode(ele, [
|
|
599
|
+
factory.createTypeReferenceNode('EntityDict')
|
|
600
|
+
]))
|
|
601
|
+
])
|
|
602
|
+
});
|
|
603
|
+
statements2 = [
|
|
604
|
+
...statements.slice(0, 5),
|
|
605
|
+
...importStatements,
|
|
606
|
+
...statements.slice(5)
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
statements2 = [...statements];
|
|
611
|
+
}
|
|
612
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
613
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
614
|
+
console.log(`构建${filename}文件成功`);
|
|
615
|
+
}
|
|
616
|
+
function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
|
617
|
+
const { statements } = sourceFile;
|
|
618
|
+
const features = [];
|
|
619
|
+
// 所有的import
|
|
620
|
+
const importStatements = [];
|
|
621
|
+
// 如果有oak-general-business,需要AccessConfiguration,自动注入
|
|
622
|
+
if (dependencies.includes('oak-general-business')) {
|
|
623
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier("accessConfiguration"), undefined), factory.createStringLiteral("@project/configuration/access"), undefined));
|
|
624
|
+
}
|
|
625
|
+
dependencies.forEach((dep, idx) => {
|
|
626
|
+
const depDir = join(cwd, 'node_modules', dep);
|
|
627
|
+
if (!(0, fs_1.existsSync)(depDir)) {
|
|
628
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录【${depDir}】`);
|
|
629
|
+
}
|
|
630
|
+
const esDir = join(depDir, 'es');
|
|
631
|
+
const libDir = join(depDir, 'lib');
|
|
632
|
+
const esDirExisted = (0, fs_1.existsSync)(esDir);
|
|
633
|
+
const libDirExisted = (0, fs_1.existsSync)(libDir);
|
|
634
|
+
if (!esDirExisted && !libDirExisted) {
|
|
635
|
+
throw new Error(`依赖模块${dep}中没有es或者lib目录`);
|
|
636
|
+
}
|
|
637
|
+
const destDir = esDirExisted ? esDir : libDir;
|
|
638
|
+
const destDirName = esDirExisted ? 'es' : 'lib';
|
|
639
|
+
// features
|
|
640
|
+
if ((0, fs_1.existsSync)(join(destDir, 'features'))) {
|
|
641
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
642
|
+
factory.createImportSpecifier(false, factory.createIdentifier("initialize"), factory.createIdentifier(`initialize${(0, string_1.firstLetterUpperCase)(briefNames[idx])}Features`)),
|
|
643
|
+
factory.createImportSpecifier(false, factory.createIdentifier("FeatureDict"), factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(briefNames[idx])}FeatureDict`))
|
|
644
|
+
])), factory.createStringLiteral(join(dep, destDirName, 'features')), undefined));
|
|
645
|
+
features.push(briefNames[idx]);
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
const funcStmt = statements.find((stmt) => ts.isFunctionDeclaration(stmt) && stmt.modifiers?.find(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) && stmt.modifiers.find(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword));
|
|
649
|
+
(0, assert_1.default)(funcStmt);
|
|
650
|
+
const idx = statements.indexOf(funcStmt);
|
|
651
|
+
const statements2 = [
|
|
652
|
+
...statements.slice(0, idx),
|
|
653
|
+
...importStatements,
|
|
654
|
+
...statements.slice(idx)
|
|
655
|
+
];
|
|
656
|
+
if (features.length > 0) {
|
|
657
|
+
(0, assert_1.default)(funcStmt.parameters.length === 1);
|
|
658
|
+
const [param] = funcStmt.parameters;
|
|
659
|
+
const { type } = param;
|
|
660
|
+
(0, assert_1.default)(ts.isIntersectionTypeNode(type));
|
|
661
|
+
Object.assign(type, {
|
|
662
|
+
types: type.types.concat(features.map(ele => factory.createTypeReferenceNode(`${(0, string_1.firstLetterUpperCase)(ele)}FeatureDict`, [
|
|
663
|
+
factory.createTypeReferenceNode('EntityDict')
|
|
664
|
+
])))
|
|
665
|
+
});
|
|
666
|
+
Object.assign(funcStmt.body, {
|
|
667
|
+
statements: [
|
|
668
|
+
...features.map((ele, idx) => {
|
|
669
|
+
const args = [
|
|
670
|
+
factory.createIdentifier("features"),
|
|
671
|
+
];
|
|
672
|
+
if (dependencies[idx] === 'oak-general-business') {
|
|
673
|
+
args.push(factory.createIdentifier("accessConfiguration"));
|
|
674
|
+
}
|
|
675
|
+
return factory.createExpressionStatement(factory.createAwaitExpression(factory.createCallExpression(factory.createIdentifier(`initialize${(0, string_1.firstLetterUpperCase)(ele)}Features`), undefined, args)));
|
|
676
|
+
}).flat(),
|
|
677
|
+
...funcStmt.body.statements,
|
|
678
|
+
]
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
682
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
683
|
+
console.log(`构建${filename}文件成功`);
|
|
684
|
+
}
|
|
685
|
+
function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|
686
|
+
const sourceFile = ts.createSourceFile('index.ts', (0, fs_1.readFileSync)(dataIndexFile, 'utf-8'), ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
|
|
687
|
+
const { statements } = sourceFile;
|
|
688
|
+
const importStatements = briefNames.map((ele) => factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(`${ele}Data`), undefined), factory.createStringLiteral(`./${ele}Data`), undefined));
|
|
689
|
+
/**
|
|
690
|
+
* 在文件末尾的这个位置上注入引用
|
|
691
|
+
export default {
|
|
692
|
+
relation: relations,
|
|
693
|
+
actionAuth,
|
|
694
|
+
relationAuth,
|
|
695
|
+
path,
|
|
696
|
+
i18n,
|
|
697
|
+
};
|
|
698
|
+
*/
|
|
699
|
+
const exportStmt = statements[statements.length - 1];
|
|
700
|
+
(0, assert_1.default)(ts.isExportAssignment(exportStmt));
|
|
701
|
+
const { expression } = exportStmt;
|
|
702
|
+
(0, assert_1.default)(ts.isObjectLiteralExpression(expression));
|
|
703
|
+
const { properties } = expression;
|
|
704
|
+
Object.assign(expression, {
|
|
705
|
+
properties: [
|
|
706
|
+
...properties,
|
|
707
|
+
...briefNames.map((ele) => factory.createSpreadAssignment(factory.createIdentifier(`${ele}Data`)))
|
|
708
|
+
]
|
|
709
|
+
});
|
|
710
|
+
const statements2 = [
|
|
711
|
+
...importStatements,
|
|
712
|
+
...statements,
|
|
713
|
+
];
|
|
714
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
715
|
+
(0, fs_1.writeFileSync)(dataIndexFile, result, { flag: 'w' });
|
|
716
|
+
console.log(`注入${dataIndexFile}文件成功,共注入了${briefNames.length}个初始化数据引用`);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* 尝试将pages目录下的页面移到项目目录中。
|
|
720
|
+
* 目前简化处理,假设目录结构都是pages/namespace/entity结构,以entity目录作为单元,如果有就放弃,没有就移植
|
|
721
|
+
* @param cwdPageDir
|
|
722
|
+
* @param modulePageDir
|
|
723
|
+
*/
|
|
724
|
+
function tryCopyPages(cwdPageDir, modulePageDir) {
|
|
725
|
+
// 各个namespace处理
|
|
726
|
+
const nss = (0, fs_1.readdirSync)(modulePageDir);
|
|
727
|
+
nss.forEach((namespace) => {
|
|
728
|
+
const pages = (0, fs_1.readdirSync)(join(modulePageDir, namespace));
|
|
729
|
+
pages.forEach((page) => {
|
|
730
|
+
const destDir = join(cwdPageDir, namespace, page);
|
|
731
|
+
if (!(0, fs_1.existsSync)(destDir)) {
|
|
732
|
+
(0, fs_extra_1.mkdirSync)(destDir);
|
|
733
|
+
const srcDir = join(modulePageDir, namespace, page);
|
|
734
|
+
console.log(`拷贝${srcDir}到${destDir}下`);
|
|
735
|
+
(0, fs_extra_1.copySync)(srcDir, destDir, {
|
|
736
|
+
recursive: true,
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* 对各个依赖项目,可能有些文件需要被移植到项目目录下,逐步完善
|
|
744
|
+
* @param cwd
|
|
745
|
+
* @param dependencies
|
|
746
|
+
* @param briefNames
|
|
747
|
+
*/
|
|
748
|
+
function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer) {
|
|
749
|
+
const injectDataIndexFileDependencies = [];
|
|
750
|
+
const injectDataIndexFileBriefNames = [];
|
|
751
|
+
dependencies.forEach((dep, idx) => {
|
|
752
|
+
const moduleDir = join(cwd, 'node_modules', dep);
|
|
753
|
+
const moduleTemplateDir = join(moduleDir, 'template');
|
|
754
|
+
if ((0, fs_1.existsSync)(moduleTemplateDir)) {
|
|
755
|
+
const entitiesDir = join(moduleTemplateDir, 'entities');
|
|
756
|
+
if ((0, fs_1.existsSync)(entitiesDir)) {
|
|
757
|
+
// entities目录下的定义直接拷贝过去(如果尚不存在的话)
|
|
758
|
+
const prjEntitiesDir = join(cwd, 'src', 'entities');
|
|
759
|
+
const result = (0, fs_1.readdirSync)(entitiesDir);
|
|
760
|
+
result.forEach((filename) => {
|
|
761
|
+
if (!(0, fs_1.existsSync)(join(prjEntitiesDir, filename))) {
|
|
762
|
+
console.log(`拷贝${join(entitiesDir, filename)}到${prjEntitiesDir}目录下`);
|
|
763
|
+
(0, fs_extra_1.copySync)(join(entitiesDir, filename), join(prjEntitiesDir, filename));
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
// data.ts中规定的初始化数据,拷贝到data目录下,并注入到data/index.ts
|
|
768
|
+
const dataFile = join(moduleTemplateDir, 'data', 'data.ts');
|
|
769
|
+
if ((0, fs_1.existsSync)(dataFile)) {
|
|
770
|
+
const prjDataFile = join(cwd, 'src', 'data', `${briefNames[idx]}Data.ts`);
|
|
771
|
+
if (!(0, fs_1.existsSync)(prjDataFile)) {
|
|
772
|
+
console.log(`拷贝${dataFile}到${prjDataFile}中`);
|
|
773
|
+
(0, fs_extra_1.copySync)(dataFile, prjDataFile);
|
|
774
|
+
injectDataIndexFileDependencies.push(dep);
|
|
775
|
+
injectDataIndexFileBriefNames.push(briefNames[idx]);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
// pages中设计的页面,拷贝到pages对应的目录下,考虑namespace
|
|
779
|
+
const pageDir = join(moduleTemplateDir, 'pages');
|
|
780
|
+
if ((0, fs_1.existsSync)(pageDir)) {
|
|
781
|
+
tryCopyPages(join(cwd, 'src', 'pages'), pageDir);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
if (injectDataIndexFileBriefNames.length > 0) {
|
|
786
|
+
injectDataIndexFile(join(cwd, 'src', 'data', 'index.ts'), injectDataIndexFileBriefNames, printer);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* 本函数用于构建src/initialize.dev, src/initialize.prod, src/initializeFeatures, src/context/FrontendContext, src/contextBackendContext
|
|
791
|
+
* 这些和dependency相关的项目文件
|
|
792
|
+
*/
|
|
793
|
+
function buildDependency(rebuild) {
|
|
794
|
+
const cwd = process.cwd();
|
|
795
|
+
const depConfigFile = join(cwd, 'src', 'configuration', 'dependency.ts');
|
|
796
|
+
if (!(0, fs_1.existsSync)(depConfigFile)) {
|
|
797
|
+
console.error(`${depConfigFile}不存在,无法构建启动文件`);
|
|
798
|
+
}
|
|
799
|
+
const depGraph = analyzeDepedency(cwd);
|
|
800
|
+
// 依赖如果是树形关系,应当从底层的被依赖者开始初始化
|
|
801
|
+
const dependencies = depGraph.ascOrder;
|
|
802
|
+
const briefNames = dependencies.map((dep, idx) => `${dep.split('-').map(ele => ele[0]).join('')}${idx}`);
|
|
803
|
+
const templateFileList = [
|
|
804
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'initialize.dev.ts'),
|
|
805
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'initialize.prod.ts'),
|
|
806
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'initializeFeatures.ts'),
|
|
807
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'RuntimeCxt.ts'),
|
|
808
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'DependentExceptions.ts'),
|
|
809
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'polyfill.d.ts'),
|
|
810
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'features/index.ts')
|
|
811
|
+
];
|
|
812
|
+
const program = ts.createProgram(templateFileList, {});
|
|
813
|
+
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
814
|
+
const initDevFile = join(cwd, 'src', 'initialize.dev.ts');
|
|
815
|
+
if ((0, fs_1.existsSync)(initDevFile) && !rebuild) {
|
|
816
|
+
console.log(`[${initDevFile}]文件已经存在,无需构建启动文件`);
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
outputIntializeDev(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[0]), printer, initDevFile);
|
|
820
|
+
}
|
|
821
|
+
const initProdFile = join(cwd, 'src', 'initialize.prod.ts');
|
|
822
|
+
if ((0, fs_1.existsSync)(initProdFile) && !rebuild) {
|
|
823
|
+
console.log(`[${initProdFile}]文件已经存在,无需构建启动文件`);
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
outputIntializeProd(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[1]), printer, initProdFile);
|
|
827
|
+
}
|
|
828
|
+
const initFeaturesFile = join(cwd, 'src', 'initializeFeatures.ts');
|
|
829
|
+
if ((0, fs_1.existsSync)(initFeaturesFile) && !rebuild) {
|
|
830
|
+
console.log(`[${initFeaturesFile}]文件已经存在,无需构建启动文件`);
|
|
831
|
+
}
|
|
832
|
+
else {
|
|
833
|
+
outputIntializeFeatures(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[2]), printer, initFeaturesFile);
|
|
834
|
+
}
|
|
835
|
+
const dependentContextFile = join(cwd, 'src', 'context', 'DependentContext.ts');
|
|
836
|
+
if ((0, fs_1.existsSync)(dependentContextFile) && !rebuild) {
|
|
837
|
+
console.log(`[${dependentContextFile}]文件已经存在,无需构建启动文件`);
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
outputDependentContext(depGraph, printer, dependentContextFile);
|
|
841
|
+
}
|
|
842
|
+
const runtimeCxtFile = join(cwd, 'src', 'types', 'RuntimeCxt.ts');
|
|
843
|
+
if ((0, fs_1.existsSync)(runtimeCxtFile) && !rebuild) {
|
|
844
|
+
console.log(`[${runtimeCxtFile}]文件已经存在,无需构建启动文件`);
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
outputRuntimeCxt(dependencies, briefNames, program.getSourceFile(templateFileList[3]), printer, runtimeCxtFile);
|
|
848
|
+
}
|
|
849
|
+
const dependentExceptionsFile = join(cwd, 'src', 'types', 'DependentExceptions.ts');
|
|
850
|
+
if ((0, fs_1.existsSync)(dependentExceptionsFile) && !rebuild) {
|
|
851
|
+
console.log(`[${dependentExceptionsFile}]文件已经存在,无需构建启动文件`);
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
outputDependentExceptions(dependencies, briefNames, program.getSourceFile(templateFileList[4]), printer, dependentExceptionsFile);
|
|
855
|
+
}
|
|
856
|
+
const polyfillDtsFile = join(cwd, 'typings', 'polyfill.d.ts');
|
|
857
|
+
if ((0, fs_1.existsSync)(polyfillDtsFile) && !rebuild) {
|
|
858
|
+
console.log(`[${polyfillDtsFile}]文件已经存在,无需构建启动文件`);
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
outputPolyfillDts(dependencies, briefNames, program.getSourceFile(templateFileList[5]), printer, polyfillDtsFile);
|
|
862
|
+
}
|
|
863
|
+
const featureIndexFile = join(cwd, 'src', 'features', 'index.ts');
|
|
864
|
+
if ((0, fs_1.existsSync)(featureIndexFile) && !rebuild) {
|
|
865
|
+
console.log(`[${featureIndexFile}]文件已经存在,无需构建启动文件`);
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
outputFeatureIndex(dependencies, briefNames, program.getSourceFile(templateFileList[6]), printer, featureIndexFile);
|
|
869
|
+
}
|
|
870
|
+
// 把各个依赖项目的一些初始化的文件拷贝过去
|
|
871
|
+
tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer);
|
|
872
|
+
}
|
|
873
|
+
exports.default = buildDependency;
|