oak-domain 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from '../utils/assert';
|
|
2
|
-
import { join as pathJoin } from 'path';
|
|
2
|
+
import { dirname, join as pathJoin } from 'path';
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from 'fs';
|
|
4
4
|
import * as ts from 'typescript';
|
|
5
5
|
import { firstLetterLowerCase, firstLetterUpperCase } from '../utils/string';
|
|
@@ -11,11 +11,30 @@ const PROJECT_NAME_PLACEHOLDER = '__OAK_PROJECT_NAME__';
|
|
|
11
11
|
function uniqueDependencies(dependencies) {
|
|
12
12
|
return Array.from(new Set(dependencies.filter((dep) => !!dep)));
|
|
13
13
|
}
|
|
14
|
+
function resolveInstalledPackageDir(fromDir, packageName) {
|
|
15
|
+
let currentDir = fromDir;
|
|
16
|
+
while (true) {
|
|
17
|
+
const packageDir = join(currentDir, 'node_modules', packageName);
|
|
18
|
+
if (existsSync(join(packageDir, 'package.json'))) {
|
|
19
|
+
return packageDir;
|
|
20
|
+
}
|
|
21
|
+
const parentDir = dirname(currentDir);
|
|
22
|
+
if (parentDir === currentDir) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
currentDir = parentDir;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function writeGeneratedFile(filename, content) {
|
|
29
|
+
mkdirSync(dirname(filename), { recursive: true });
|
|
30
|
+
writeFileSync(filename, content, { flag: 'w' });
|
|
31
|
+
}
|
|
14
32
|
function readInstalledPackageManifest(dir, packageName) {
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
33
|
+
const packageDir = resolveInstalledPackageDir(dir, packageName);
|
|
34
|
+
if (!packageDir) {
|
|
17
35
|
return undefined;
|
|
18
36
|
}
|
|
37
|
+
const packageJsonPath = join(packageDir, 'package.json');
|
|
19
38
|
return JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
20
39
|
}
|
|
21
40
|
function readDependencyConfiguration(dir) {
|
|
@@ -42,10 +61,11 @@ function collectInstalledOakLibDependencies(dir) {
|
|
|
42
61
|
...Object.keys(packageJson.devDependencies || {}),
|
|
43
62
|
]).sort((left, right) => left.localeCompare(right));
|
|
44
63
|
return dependencyNames.filter((dep) => {
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
64
|
+
const packageDir = resolveInstalledPackageDir(dir, dep);
|
|
65
|
+
if (!packageDir) {
|
|
47
66
|
return false;
|
|
48
67
|
}
|
|
68
|
+
const manifestPath = join(packageDir, 'package.json');
|
|
49
69
|
const dependencyManifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
50
70
|
return isOakBusinessModule(dependencyManifest);
|
|
51
71
|
});
|
|
@@ -142,12 +162,10 @@ export function analyzeDepedency(cwd) {
|
|
|
142
162
|
depGraph.dependencies[name][dep] = 1;
|
|
143
163
|
}
|
|
144
164
|
if (!depGraph.nodes[dep]) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
150
|
-
}
|
|
165
|
+
const dir2 = resolveInstalledPackageDir(dir, dep)
|
|
166
|
+
|| resolveInstalledPackageDir(cwd, dep);
|
|
167
|
+
if (!dir2) {
|
|
168
|
+
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
151
169
|
}
|
|
152
170
|
analyzeOne(dir2, dep);
|
|
153
171
|
}
|
|
@@ -281,7 +299,7 @@ function outputPolyfillDts(dependencies, briefNames, sourceFile, printer, filena
|
|
|
281
299
|
statements2 = [...sourceFile.statements];
|
|
282
300
|
}
|
|
283
301
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
284
|
-
|
|
302
|
+
writeGeneratedFile(filename, result);
|
|
285
303
|
console.log(`构建${filename}文件成功`);
|
|
286
304
|
}
|
|
287
305
|
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
@@ -323,7 +341,7 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
|
|
|
323
341
|
});
|
|
324
342
|
}
|
|
325
343
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
326
|
-
|
|
344
|
+
writeGeneratedFile(filename, result);
|
|
327
345
|
console.log(`构建${filename}文件成功`);
|
|
328
346
|
}
|
|
329
347
|
function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filename) {
|
|
@@ -381,7 +399,7 @@ function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filenam
|
|
|
381
399
|
];
|
|
382
400
|
}
|
|
383
401
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
384
|
-
|
|
402
|
+
writeGeneratedFile(filename, result);
|
|
385
403
|
console.log(`构建${filename}文件成功`);
|
|
386
404
|
}
|
|
387
405
|
function outputContext(depGraph, sourceFile, printer, filename) {
|
|
@@ -399,11 +417,14 @@ function outputContext(depGraph, sourceFile, printer, filename) {
|
|
|
399
417
|
...statements
|
|
400
418
|
];
|
|
401
419
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
402
|
-
|
|
420
|
+
writeGeneratedFile(filename, result);
|
|
403
421
|
console.log(`构建${filename}文件成功`);
|
|
404
422
|
}
|
|
405
423
|
function hasRuntimeContextEntry(cwd, dependency, target) {
|
|
406
|
-
const dependencyDir =
|
|
424
|
+
const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
|
|
425
|
+
if (!dependencyDir) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
407
428
|
const fileName = `${target}RuntimeContext`;
|
|
408
429
|
return [
|
|
409
430
|
join(dependencyDir, 'src', 'context', `${fileName}.ts`),
|
|
@@ -497,7 +518,7 @@ export default ${generatedName};
|
|
|
497
518
|
}
|
|
498
519
|
function outputGeneratedContext(cwd, target, isModule) {
|
|
499
520
|
const fileName = join(cwd, 'src', 'context', `generated${target}.ts`);
|
|
500
|
-
|
|
521
|
+
writeGeneratedFile(fileName, renderGeneratedContextSource(cwd, target, isModule));
|
|
501
522
|
console.log(`构建${fileName}文件成功`);
|
|
502
523
|
}
|
|
503
524
|
function outputProjectContextShell(templateFile, targetFile) {
|
|
@@ -505,7 +526,7 @@ function outputProjectContextShell(templateFile, targetFile) {
|
|
|
505
526
|
console.log(`[${targetFile}]文件已经存在,保留项目自定义上下文。`);
|
|
506
527
|
return;
|
|
507
528
|
}
|
|
508
|
-
|
|
529
|
+
writeGeneratedFile(targetFile, readFileSync(templateFile, 'utf-8'));
|
|
509
530
|
console.log(`构建${targetFile}文件成功`);
|
|
510
531
|
}
|
|
511
532
|
export function writeContextCompositionFiles(cwd, isModule, templates) {
|
|
@@ -532,9 +553,9 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
532
553
|
// 所有的import
|
|
533
554
|
const importStatements = [];
|
|
534
555
|
dependencies.forEach((dep, idx) => {
|
|
535
|
-
const depDir =
|
|
536
|
-
if (!
|
|
537
|
-
throw new Error(`依赖模块${dep}
|
|
556
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
557
|
+
if (!depDir) {
|
|
558
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
538
559
|
}
|
|
539
560
|
const esDir = join(depDir, 'es');
|
|
540
561
|
const libDir = join(depDir, 'lib');
|
|
@@ -643,7 +664,7 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
643
664
|
});
|
|
644
665
|
}
|
|
645
666
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
646
|
-
|
|
667
|
+
writeGeneratedFile(filename, result);
|
|
647
668
|
console.log(`构建${filename}文件成功`);
|
|
648
669
|
}
|
|
649
670
|
/**
|
|
@@ -660,9 +681,9 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
660
681
|
// 所有的import
|
|
661
682
|
const importStatements = [];
|
|
662
683
|
dependencies.forEach((dep, idx) => {
|
|
663
|
-
const depDir =
|
|
664
|
-
if (!
|
|
665
|
-
throw new Error(`依赖模块${dep}
|
|
684
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
685
|
+
if (!depDir) {
|
|
686
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
666
687
|
}
|
|
667
688
|
const esDir = join(depDir, 'es');
|
|
668
689
|
const libDir = join(depDir, 'lib');
|
|
@@ -792,7 +813,7 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
792
813
|
});
|
|
793
814
|
}
|
|
794
815
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
795
|
-
|
|
816
|
+
writeGeneratedFile(filename, result);
|
|
796
817
|
console.log(`构建${filename}文件成功`);
|
|
797
818
|
}
|
|
798
819
|
export function renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
@@ -866,12 +887,12 @@ export function renderFeatureIndexSource(dependencies, briefNames, sourceFile, i
|
|
|
866
887
|
*/
|
|
867
888
|
function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
868
889
|
const result = renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer);
|
|
869
|
-
|
|
890
|
+
writeGeneratedFile(filename, result);
|
|
870
891
|
console.log(`构建${filename}文件成功`);
|
|
871
892
|
}
|
|
872
893
|
function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
|
873
894
|
const result = renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer);
|
|
874
|
-
|
|
895
|
+
writeGeneratedFile(filename, result);
|
|
875
896
|
console.log(`构建${filename}文件成功`);
|
|
876
897
|
}
|
|
877
898
|
export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
@@ -879,9 +900,9 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
|
|
|
879
900
|
const features = [];
|
|
880
901
|
const importStatements = [];
|
|
881
902
|
dependencies.forEach((dep, idx) => {
|
|
882
|
-
const depDir =
|
|
883
|
-
if (!
|
|
884
|
-
throw new Error(`依赖模块${dep}
|
|
903
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
904
|
+
if (!depDir) {
|
|
905
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
885
906
|
}
|
|
886
907
|
const esDir = join(depDir, 'es');
|
|
887
908
|
const libDir = join(depDir, 'lib');
|
|
@@ -923,10 +944,15 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
|
|
|
923
944
|
}
|
|
924
945
|
export function resolveDependencyTemplateFile(cwd, dependencies, templateFileName, fallback) {
|
|
925
946
|
const rootPlan = resolveDependencyRootPlan(cwd, dependencies);
|
|
926
|
-
const candidates = rootPlan.rootDependencies.map((dependency) =>
|
|
927
|
-
dependency
|
|
928
|
-
|
|
929
|
-
|
|
947
|
+
const candidates = rootPlan.rootDependencies.map((dependency) => {
|
|
948
|
+
const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
|
|
949
|
+
return {
|
|
950
|
+
dependency,
|
|
951
|
+
filePath: dependencyDir
|
|
952
|
+
? join(dependencyDir, 'template', templateFileName)
|
|
953
|
+
: '',
|
|
954
|
+
};
|
|
955
|
+
}).filter(({ filePath }) => existsSync(filePath));
|
|
930
956
|
if (candidates.length > 1) {
|
|
931
957
|
throw new Error(`多个顶层依赖同时提供 template/${templateFileName}:${candidates.map(({ dependency }) => dependency).join(', ')},无法确定使用哪个模板`);
|
|
932
958
|
}
|
|
@@ -962,7 +988,7 @@ function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|
|
962
988
|
...statements,
|
|
963
989
|
];
|
|
964
990
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
965
|
-
|
|
991
|
+
writeGeneratedFile(dataIndexFile, result);
|
|
966
992
|
console.log(`注入${dataIndexFile}文件成功,共注入了${briefNames.length}个初始化数据引用`);
|
|
967
993
|
}
|
|
968
994
|
/**
|
|
@@ -1013,7 +1039,10 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebu
|
|
|
1013
1039
|
const injectDataIndexFileDependencies = [];
|
|
1014
1040
|
const injectDataIndexFileBriefNames = [];
|
|
1015
1041
|
dependencies.forEach((dep, idx) => {
|
|
1016
|
-
const moduleDir =
|
|
1042
|
+
const moduleDir = resolveInstalledPackageDir(cwd, dep);
|
|
1043
|
+
if (!moduleDir) {
|
|
1044
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
1045
|
+
}
|
|
1017
1046
|
const moduleTemplateDir = join(moduleDir, 'template');
|
|
1018
1047
|
if (existsSync(moduleTemplateDir)) {
|
|
1019
1048
|
// data.ts中规定的初始化数据,拷贝到data目录下,并注入到data/index.ts
|
|
@@ -1100,7 +1129,7 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1100
1129
|
], undefined, factory.createBlock([], true))
|
|
1101
1130
|
];
|
|
1102
1131
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
1103
|
-
|
|
1132
|
+
writeGeneratedFile(featureIndexFile, result);
|
|
1104
1133
|
console.log(`注入${featureIndexFile}文件成功,用户可以自己修正initialize函数的参数和逻辑`);
|
|
1105
1134
|
}
|
|
1106
1135
|
}
|
|
@@ -1111,19 +1140,23 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1111
1140
|
export default function buildDependency(rebuild) {
|
|
1112
1141
|
const cwd = process.cwd();
|
|
1113
1142
|
const { depGraph, dependencies, briefNames, isModule, } = resolveDependencyBuildContext(cwd);
|
|
1143
|
+
const oakCliDir = resolveInstalledPackageDir(cwd, OAK_CLI_MODULE_NAME);
|
|
1144
|
+
if (!oakCliDir) {
|
|
1145
|
+
throw new Error(`找不到依赖包${OAK_CLI_MODULE_NAME}的安装位置,当前包是${cwd}`);
|
|
1146
|
+
}
|
|
1114
1147
|
const defaultTemplateFiles = {
|
|
1115
|
-
initializeServer: join(
|
|
1116
|
-
initializeFeatures: join(
|
|
1117
|
-
runtimeCxt: join(
|
|
1118
|
-
dependentExceptions: join(
|
|
1119
|
-
polyfillDts: join(
|
|
1120
|
-
featureIndex: join(
|
|
1148
|
+
initializeServer: join(oakCliDir, 'scaffold', 'fragments', 'initialize.server.ts'),
|
|
1149
|
+
initializeFeatures: join(oakCliDir, 'scaffold', 'fragments', 'initializeFeatures.ts'),
|
|
1150
|
+
runtimeCxt: join(oakCliDir, 'scaffold', 'fragments', 'RuntimeCxt.ts'),
|
|
1151
|
+
dependentExceptions: join(oakCliDir, 'scaffold', 'fragments', 'DependentExceptions.ts'),
|
|
1152
|
+
polyfillDts: join(oakCliDir, 'scaffold', 'fragments', 'polyfill.d.ts'),
|
|
1153
|
+
featureIndex: join(oakCliDir, 'scaffold', 'fragments', !isModule && dependencies.length === 0
|
|
1121
1154
|
? 'features/index.standalone.ts'
|
|
1122
1155
|
: 'features/index.ts'),
|
|
1123
|
-
backendRuntimeContext: join(
|
|
1156
|
+
backendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
|
|
1124
1157
|
? 'BackendRuntimeContext.standalone.ts'
|
|
1125
1158
|
: 'BackendRuntimeContext.ts'),
|
|
1126
|
-
frontendRuntimeContext: join(
|
|
1159
|
+
frontendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
|
|
1127
1160
|
? 'FrontendRuntimeContext.standalone.ts'
|
|
1128
1161
|
: 'FrontendRuntimeContext.ts'),
|
|
1129
1162
|
};
|
|
@@ -25,11 +25,30 @@ const PROJECT_NAME_PLACEHOLDER = '__OAK_PROJECT_NAME__';
|
|
|
25
25
|
function uniqueDependencies(dependencies) {
|
|
26
26
|
return Array.from(new Set(dependencies.filter((dep) => !!dep)));
|
|
27
27
|
}
|
|
28
|
+
function resolveInstalledPackageDir(fromDir, packageName) {
|
|
29
|
+
let currentDir = fromDir;
|
|
30
|
+
while (true) {
|
|
31
|
+
const packageDir = join(currentDir, 'node_modules', packageName);
|
|
32
|
+
if ((0, fs_1.existsSync)(join(packageDir, 'package.json'))) {
|
|
33
|
+
return packageDir;
|
|
34
|
+
}
|
|
35
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
36
|
+
if (parentDir === currentDir) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
currentDir = parentDir;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function writeGeneratedFile(filename, content) {
|
|
43
|
+
(0, fs_extra_1.mkdirSync)((0, path_1.dirname)(filename), { recursive: true });
|
|
44
|
+
(0, fs_1.writeFileSync)(filename, content, { flag: 'w' });
|
|
45
|
+
}
|
|
28
46
|
function readInstalledPackageManifest(dir, packageName) {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
47
|
+
const packageDir = resolveInstalledPackageDir(dir, packageName);
|
|
48
|
+
if (!packageDir) {
|
|
31
49
|
return undefined;
|
|
32
50
|
}
|
|
51
|
+
const packageJsonPath = join(packageDir, 'package.json');
|
|
33
52
|
return JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
34
53
|
}
|
|
35
54
|
function readDependencyConfiguration(dir) {
|
|
@@ -56,10 +75,11 @@ function collectInstalledOakLibDependencies(dir) {
|
|
|
56
75
|
...Object.keys(packageJson.devDependencies || {}),
|
|
57
76
|
]).sort((left, right) => left.localeCompare(right));
|
|
58
77
|
return dependencyNames.filter((dep) => {
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
78
|
+
const packageDir = resolveInstalledPackageDir(dir, dep);
|
|
79
|
+
if (!packageDir) {
|
|
61
80
|
return false;
|
|
62
81
|
}
|
|
82
|
+
const manifestPath = join(packageDir, 'package.json');
|
|
63
83
|
const dependencyManifest = JSON.parse((0, fs_1.readFileSync)(manifestPath, 'utf-8'));
|
|
64
84
|
return (0, OakPackage_1.isOakBusinessModule)(dependencyManifest);
|
|
65
85
|
});
|
|
@@ -156,12 +176,10 @@ function analyzeDepedency(cwd) {
|
|
|
156
176
|
depGraph.dependencies[name][dep] = 1;
|
|
157
177
|
}
|
|
158
178
|
if (!depGraph.nodes[dep]) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
164
|
-
}
|
|
179
|
+
const dir2 = resolveInstalledPackageDir(dir, dep)
|
|
180
|
+
|| resolveInstalledPackageDir(cwd, dep);
|
|
181
|
+
if (!dir2) {
|
|
182
|
+
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
165
183
|
}
|
|
166
184
|
analyzeOne(dir2, dep);
|
|
167
185
|
}
|
|
@@ -295,7 +313,7 @@ function outputPolyfillDts(dependencies, briefNames, sourceFile, printer, filena
|
|
|
295
313
|
statements2 = [...sourceFile.statements];
|
|
296
314
|
}
|
|
297
315
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
298
|
-
(
|
|
316
|
+
writeGeneratedFile(filename, result);
|
|
299
317
|
console.log(`构建${filename}文件成功`);
|
|
300
318
|
}
|
|
301
319
|
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
@@ -337,7 +355,7 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
|
|
|
337
355
|
});
|
|
338
356
|
}
|
|
339
357
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
340
|
-
(
|
|
358
|
+
writeGeneratedFile(filename, result);
|
|
341
359
|
console.log(`构建${filename}文件成功`);
|
|
342
360
|
}
|
|
343
361
|
function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filename) {
|
|
@@ -395,7 +413,7 @@ function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filenam
|
|
|
395
413
|
];
|
|
396
414
|
}
|
|
397
415
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
398
|
-
(
|
|
416
|
+
writeGeneratedFile(filename, result);
|
|
399
417
|
console.log(`构建${filename}文件成功`);
|
|
400
418
|
}
|
|
401
419
|
function outputContext(depGraph, sourceFile, printer, filename) {
|
|
@@ -413,11 +431,14 @@ function outputContext(depGraph, sourceFile, printer, filename) {
|
|
|
413
431
|
...statements
|
|
414
432
|
];
|
|
415
433
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
416
|
-
(
|
|
434
|
+
writeGeneratedFile(filename, result);
|
|
417
435
|
console.log(`构建${filename}文件成功`);
|
|
418
436
|
}
|
|
419
437
|
function hasRuntimeContextEntry(cwd, dependency, target) {
|
|
420
|
-
const dependencyDir =
|
|
438
|
+
const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
|
|
439
|
+
if (!dependencyDir) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
421
442
|
const fileName = `${target}RuntimeContext`;
|
|
422
443
|
return [
|
|
423
444
|
join(dependencyDir, 'src', 'context', `${fileName}.ts`),
|
|
@@ -511,7 +532,7 @@ export default ${generatedName};
|
|
|
511
532
|
}
|
|
512
533
|
function outputGeneratedContext(cwd, target, isModule) {
|
|
513
534
|
const fileName = join(cwd, 'src', 'context', `generated${target}.ts`);
|
|
514
|
-
(
|
|
535
|
+
writeGeneratedFile(fileName, renderGeneratedContextSource(cwd, target, isModule));
|
|
515
536
|
console.log(`构建${fileName}文件成功`);
|
|
516
537
|
}
|
|
517
538
|
function outputProjectContextShell(templateFile, targetFile) {
|
|
@@ -519,7 +540,7 @@ function outputProjectContextShell(templateFile, targetFile) {
|
|
|
519
540
|
console.log(`[${targetFile}]文件已经存在,保留项目自定义上下文。`);
|
|
520
541
|
return;
|
|
521
542
|
}
|
|
522
|
-
(
|
|
543
|
+
writeGeneratedFile(targetFile, (0, fs_1.readFileSync)(templateFile, 'utf-8'));
|
|
523
544
|
console.log(`构建${targetFile}文件成功`);
|
|
524
545
|
}
|
|
525
546
|
function writeContextCompositionFiles(cwd, isModule, templates) {
|
|
@@ -546,9 +567,9 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
546
567
|
// 所有的import
|
|
547
568
|
const importStatements = [];
|
|
548
569
|
dependencies.forEach((dep, idx) => {
|
|
549
|
-
const depDir =
|
|
550
|
-
if (!
|
|
551
|
-
throw new Error(`依赖模块${dep}
|
|
570
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
571
|
+
if (!depDir) {
|
|
572
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
552
573
|
}
|
|
553
574
|
const esDir = join(depDir, 'es');
|
|
554
575
|
const libDir = join(depDir, 'lib');
|
|
@@ -657,7 +678,7 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
657
678
|
});
|
|
658
679
|
}
|
|
659
680
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
660
|
-
(
|
|
681
|
+
writeGeneratedFile(filename, result);
|
|
661
682
|
console.log(`构建${filename}文件成功`);
|
|
662
683
|
}
|
|
663
684
|
/**
|
|
@@ -674,9 +695,9 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
674
695
|
// 所有的import
|
|
675
696
|
const importStatements = [];
|
|
676
697
|
dependencies.forEach((dep, idx) => {
|
|
677
|
-
const depDir =
|
|
678
|
-
if (!
|
|
679
|
-
throw new Error(`依赖模块${dep}
|
|
698
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
699
|
+
if (!depDir) {
|
|
700
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
680
701
|
}
|
|
681
702
|
const esDir = join(depDir, 'es');
|
|
682
703
|
const libDir = join(depDir, 'lib');
|
|
@@ -806,7 +827,7 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
806
827
|
});
|
|
807
828
|
}
|
|
808
829
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
809
|
-
(
|
|
830
|
+
writeGeneratedFile(filename, result);
|
|
810
831
|
console.log(`构建${filename}文件成功`);
|
|
811
832
|
}
|
|
812
833
|
function renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
@@ -880,12 +901,12 @@ function renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule
|
|
|
880
901
|
*/
|
|
881
902
|
function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
882
903
|
const result = renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer);
|
|
883
|
-
(
|
|
904
|
+
writeGeneratedFile(filename, result);
|
|
884
905
|
console.log(`构建${filename}文件成功`);
|
|
885
906
|
}
|
|
886
907
|
function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
|
887
908
|
const result = renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer);
|
|
888
|
-
(
|
|
909
|
+
writeGeneratedFile(filename, result);
|
|
889
910
|
console.log(`构建${filename}文件成功`);
|
|
890
911
|
}
|
|
891
912
|
function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
@@ -893,9 +914,9 @@ function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFil
|
|
|
893
914
|
const features = [];
|
|
894
915
|
const importStatements = [];
|
|
895
916
|
dependencies.forEach((dep, idx) => {
|
|
896
|
-
const depDir =
|
|
897
|
-
if (!
|
|
898
|
-
throw new Error(`依赖模块${dep}
|
|
917
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
918
|
+
if (!depDir) {
|
|
919
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
899
920
|
}
|
|
900
921
|
const esDir = join(depDir, 'es');
|
|
901
922
|
const libDir = join(depDir, 'lib');
|
|
@@ -937,10 +958,15 @@ function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFil
|
|
|
937
958
|
}
|
|
938
959
|
function resolveDependencyTemplateFile(cwd, dependencies, templateFileName, fallback) {
|
|
939
960
|
const rootPlan = resolveDependencyRootPlan(cwd, dependencies);
|
|
940
|
-
const candidates = rootPlan.rootDependencies.map((dependency) =>
|
|
941
|
-
dependency
|
|
942
|
-
|
|
943
|
-
|
|
961
|
+
const candidates = rootPlan.rootDependencies.map((dependency) => {
|
|
962
|
+
const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
|
|
963
|
+
return {
|
|
964
|
+
dependency,
|
|
965
|
+
filePath: dependencyDir
|
|
966
|
+
? join(dependencyDir, 'template', templateFileName)
|
|
967
|
+
: '',
|
|
968
|
+
};
|
|
969
|
+
}).filter(({ filePath }) => (0, fs_1.existsSync)(filePath));
|
|
944
970
|
if (candidates.length > 1) {
|
|
945
971
|
throw new Error(`多个顶层依赖同时提供 template/${templateFileName}:${candidates.map(({ dependency }) => dependency).join(', ')},无法确定使用哪个模板`);
|
|
946
972
|
}
|
|
@@ -976,7 +1002,7 @@ function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|
|
976
1002
|
...statements,
|
|
977
1003
|
];
|
|
978
1004
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
979
|
-
(
|
|
1005
|
+
writeGeneratedFile(dataIndexFile, result);
|
|
980
1006
|
console.log(`注入${dataIndexFile}文件成功,共注入了${briefNames.length}个初始化数据引用`);
|
|
981
1007
|
}
|
|
982
1008
|
/**
|
|
@@ -1027,7 +1053,10 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebu
|
|
|
1027
1053
|
const injectDataIndexFileDependencies = [];
|
|
1028
1054
|
const injectDataIndexFileBriefNames = [];
|
|
1029
1055
|
dependencies.forEach((dep, idx) => {
|
|
1030
|
-
const moduleDir =
|
|
1056
|
+
const moduleDir = resolveInstalledPackageDir(cwd, dep);
|
|
1057
|
+
if (!moduleDir) {
|
|
1058
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
1059
|
+
}
|
|
1031
1060
|
const moduleTemplateDir = join(moduleDir, 'template');
|
|
1032
1061
|
if ((0, fs_1.existsSync)(moduleTemplateDir)) {
|
|
1033
1062
|
// data.ts中规定的初始化数据,拷贝到data目录下,并注入到data/index.ts
|
|
@@ -1114,7 +1143,7 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1114
1143
|
], undefined, factory.createBlock([], true))
|
|
1115
1144
|
];
|
|
1116
1145
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
1117
|
-
(
|
|
1146
|
+
writeGeneratedFile(featureIndexFile, result);
|
|
1118
1147
|
console.log(`注入${featureIndexFile}文件成功,用户可以自己修正initialize函数的参数和逻辑`);
|
|
1119
1148
|
}
|
|
1120
1149
|
}
|
|
@@ -1125,19 +1154,23 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1125
1154
|
function buildDependency(rebuild) {
|
|
1126
1155
|
const cwd = process.cwd();
|
|
1127
1156
|
const { depGraph, dependencies, briefNames, isModule, } = resolveDependencyBuildContext(cwd);
|
|
1157
|
+
const oakCliDir = resolveInstalledPackageDir(cwd, env_1.OAK_CLI_MODULE_NAME);
|
|
1158
|
+
if (!oakCliDir) {
|
|
1159
|
+
throw new Error(`找不到依赖包${env_1.OAK_CLI_MODULE_NAME}的安装位置,当前包是${cwd}`);
|
|
1160
|
+
}
|
|
1128
1161
|
const defaultTemplateFiles = {
|
|
1129
|
-
initializeServer: join(
|
|
1130
|
-
initializeFeatures: join(
|
|
1131
|
-
runtimeCxt: join(
|
|
1132
|
-
dependentExceptions: join(
|
|
1133
|
-
polyfillDts: join(
|
|
1134
|
-
featureIndex: join(
|
|
1162
|
+
initializeServer: join(oakCliDir, 'scaffold', 'fragments', 'initialize.server.ts'),
|
|
1163
|
+
initializeFeatures: join(oakCliDir, 'scaffold', 'fragments', 'initializeFeatures.ts'),
|
|
1164
|
+
runtimeCxt: join(oakCliDir, 'scaffold', 'fragments', 'RuntimeCxt.ts'),
|
|
1165
|
+
dependentExceptions: join(oakCliDir, 'scaffold', 'fragments', 'DependentExceptions.ts'),
|
|
1166
|
+
polyfillDts: join(oakCliDir, 'scaffold', 'fragments', 'polyfill.d.ts'),
|
|
1167
|
+
featureIndex: join(oakCliDir, 'scaffold', 'fragments', !isModule && dependencies.length === 0
|
|
1135
1168
|
? 'features/index.standalone.ts'
|
|
1136
1169
|
: 'features/index.ts'),
|
|
1137
|
-
backendRuntimeContext: join(
|
|
1170
|
+
backendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
|
|
1138
1171
|
? 'BackendRuntimeContext.standalone.ts'
|
|
1139
1172
|
: 'BackendRuntimeContext.ts'),
|
|
1140
|
-
frontendRuntimeContext: join(
|
|
1173
|
+
frontendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
|
|
1141
1174
|
? 'FrontendRuntimeContext.standalone.ts'
|
|
1142
1175
|
: 'FrontendRuntimeContext.ts'),
|
|
1143
1176
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-domain",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"oak": {
|
|
5
5
|
"package": true,
|
|
6
6
|
"i18n": true,
|
|
@@ -60,9 +60,7 @@
|
|
|
60
60
|
"fs-extra": "^10.0.0",
|
|
61
61
|
"mocha": "^8.2.1",
|
|
62
62
|
"node-watch": "^0.7.4",
|
|
63
|
-
"ts-node": "^10.9.1"
|
|
64
|
-
"tslib": "^2.4.0",
|
|
65
|
-
"typescript": "^5.9.0"
|
|
63
|
+
"ts-node": "^10.9.1"
|
|
66
64
|
},
|
|
67
65
|
"dependencies": {
|
|
68
66
|
"bignumber.js": "^11.1.1",
|
|
@@ -72,6 +70,8 @@
|
|
|
72
70
|
"koa-body": "^5.0.0",
|
|
73
71
|
"node-schedule": "^2.1.1",
|
|
74
72
|
"socket.io": "^4.8.1",
|
|
73
|
+
"tslib": "^2.4.0",
|
|
74
|
+
"typescript": ">=5.9.0 <7",
|
|
75
75
|
"uuid": "^9.0.0"
|
|
76
76
|
}
|
|
77
77
|
}
|