@simplysm/sd-cli 7.3.1 → 10.0.4
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/.eslintrc.cjs +18 -0
- package/dist/build-cluster.js +75 -0
- package/dist/build-cluster.js.map +1 -0
- package/dist/builders/SdCliJsLibLinter.d.ts +18 -0
- package/dist/builders/SdCliJsLibLinter.js +69 -0
- package/dist/builders/SdCliJsLibLinter.js.map +1 -0
- package/dist/builders/SdCliTsLibBuilder.d.ts +20 -0
- package/dist/builders/SdCliTsLibBuilder.js +205 -0
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -0
- package/dist/commons.d.ts +3 -117
- package/dist/commons.js +2 -0
- package/dist/commons.js.map +1 -0
- package/dist/entry/SdCliProject.d.ts +28 -0
- package/dist/entry/SdCliProject.js +269 -0
- package/dist/entry/SdCliProject.js.map +1 -0
- package/dist/sd-cli.js +118 -0
- package/dist/sd-cli.js.map +1 -0
- package/dist/utils/SdCliBuildResultUtil.d.ts +1 -4
- package/dist/utils/SdCliBuildResultUtil.js +37 -0
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -0
- package/dist/utils/SdCliConfigUtil.js +69 -0
- package/dist/utils/SdCliConfigUtil.js.map +1 -0
- package/package.json +10 -59
- package/src/build-cluster.ts +82 -0
- package/src/builders/SdCliJsLibLinter.ts +84 -0
- package/src/builders/SdCliTsLibBuilder.ts +265 -0
- package/src/commons.ts +3 -123
- package/src/entry/SdCliProject.ts +351 -0
- package/src/sd-cli.ts +135 -0
- package/src/utils/SdCliBuildResultUtil.ts +5 -38
- package/tsconfig.json +18 -0
- package/README.md +0 -105
- package/assets/client-files/assets/icons/icon-128x128.png +0 -0
- package/assets/client-files/assets/icons/icon-144x144.png +0 -0
- package/assets/client-files/assets/icons/icon-152x152.png +0 -0
- package/assets/client-files/assets/icons/icon-192x192.png +0 -0
- package/assets/client-files/assets/icons/icon-384x384.png +0 -0
- package/assets/client-files/assets/icons/icon-512x512.png +0 -0
- package/assets/client-files/assets/icons/icon-72x72.png +0 -0
- package/assets/client-files/assets/icons/icon-96x96.png +0 -0
- package/assets/client-files/favicon.ico +0 -0
- package/dist/SdCliBuildResultError.d.ts +0 -5
- package/dist/SdCliBuildResultError.mjs +0 -8
- package/dist/bin/sd-cli.d.ts +0 -2
- package/dist/bin/sd-cli.mjs +0 -410
- package/dist/build-tool/SdCliCacheCompilerHost.d.ts +0 -10
- package/dist/build-tool/SdCliCacheCompilerHost.mjs +0 -51
- package/dist/build-tool/SdCliCordova.d.ts +0 -16
- package/dist/build-tool/SdCliCordova.mjs +0 -212
- package/dist/build-tool/SdCliElectron.d.ts +0 -9
- package/dist/build-tool/SdCliElectron.mjs +0 -71
- package/dist/build-tool/SdCliGithubApi.d.ts +0 -13
- package/dist/build-tool/SdCliGithubApi.mjs +0 -92
- package/dist/build-tool/SdCliIndexFileGenerator.d.ts +0 -13
- package/dist/build-tool/SdCliIndexFileGenerator.mjs +0 -62
- package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +0 -12
- package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +0 -43
- package/dist/build-tool/SdCliPackageLinter.d.ts +0 -8
- package/dist/build-tool/SdCliPackageLinter.mjs +0 -62
- package/dist/builder/SdCliClientBuilder.d.ts +0 -26
- package/dist/builder/SdCliClientBuilder.mjs +0 -761
- package/dist/builder/SdCliJsLibBuilder.d.ts +0 -14
- package/dist/builder/SdCliJsLibBuilder.mjs +0 -54
- package/dist/builder/SdCliServerBuilder.d.ts +0 -28
- package/dist/builder/SdCliServerBuilder.mjs +0 -482
- package/dist/builder/SdCliTsLibBuilder.d.ts +0 -35
- package/dist/builder/SdCliTsLibBuilder.mjs +0 -317
- package/dist/commons.mjs +0 -2
- package/dist/entry-points/SdCliFileCrypto.d.ts +0 -7
- package/dist/entry-points/SdCliFileCrypto.mjs +0 -72
- package/dist/entry-points/SdCliLocalUpdate.d.ts +0 -13
- package/dist/entry-points/SdCliLocalUpdate.mjs +0 -100
- package/dist/entry-points/SdCliPrepare.d.ts +0 -5
- package/dist/entry-points/SdCliPrepare.mjs +0 -86
- package/dist/entry-points/SdCliProject.d.ts +0 -34
- package/dist/entry-points/SdCliProject.mjs +0 -416
- package/dist/entry-points/SdCliProjectGenerator.d.ts +0 -44
- package/dist/entry-points/SdCliProjectGenerator.mjs +0 -326
- package/dist/entry-points/file/base/fc_package_eslintrc.d.ts +0 -3
- package/dist/entry-points/file/base/fc_package_eslintrc.mjs +0 -31
- package/dist/entry-points/file/base/fc_package_npmconfig.d.ts +0 -9
- package/dist/entry-points/file/base/fc_package_npmconfig.mjs +0 -32
- package/dist/entry-points/file/base/fc_package_tsconfig.d.ts +0 -5
- package/dist/entry-points/file/base/fc_package_tsconfig.mjs +0 -13
- package/dist/entry-points/file/client/fc_package_AppModule.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_AppModule.mjs +0 -37
- package/dist/entry-points/file/client/fc_package_AppPage.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_AppPage.mjs +0 -14
- package/dist/entry-points/file/client/fc_package_Page.d.ts +0 -4
- package/dist/entry-points/file/client/fc_package_Page.mjs +0 -19
- package/dist/entry-points/file/client/fc_package_client_main.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_client_main.mjs +0 -19
- package/dist/entry-points/file/client/fc_package_index.d.ts +0 -3
- package/dist/entry-points/file/client/fc_package_index.mjs +0 -88
- package/dist/entry-points/file/client/fc_package_manifest.d.ts +0 -5
- package/dist/entry-points/file/client/fc_package_manifest.mjs +0 -54
- package/dist/entry-points/file/client/fc_package_polyfills.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_polyfills.mjs +0 -11
- package/dist/entry-points/file/client/fc_package_styles.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_styles.mjs +0 -7
- package/dist/entry-points/file/db/fc_package_DbContext.d.ts +0 -3
- package/dist/entry-points/file/db/fc_package_DbContext.mjs +0 -14
- package/dist/entry-points/file/db/fc_package_DbModel.d.ts +0 -4
- package/dist/entry-points/file/db/fc_package_DbModel.mjs +0 -12
- package/dist/entry-points/file/project/fc_project_editor_config.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_editor_config.mjs +0 -22
- package/dist/entry-points/file/project/fc_project_eslintrc.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_eslintrc.mjs +0 -30
- package/dist/entry-points/file/project/fc_project_gitattributes.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_gitattributes.mjs +0 -6
- package/dist/entry-points/file/project/fc_project_gitignore.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_gitignore.mjs +0 -27
- package/dist/entry-points/file/project/fc_project_npmconfig.d.ts +0 -7
- package/dist/entry-points/file/project/fc_project_npmconfig.mjs +0 -37
- package/dist/entry-points/file/project/fc_project_readme.d.ts +0 -3
- package/dist/entry-points/file/project/fc_project_readme.mjs +0 -13
- package/dist/entry-points/file/project/fc_project_simplysm.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_simplysm.mjs +0 -2
- package/dist/entry-points/file/project/fc_project_tsconfig.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_tsconfig.mjs +0 -25
- package/dist/entry-points/file/server/fc_package_server_main.d.ts +0 -5
- package/dist/entry-points/file/server/fc_package_server_main.mjs +0 -60
- package/dist/index.d.ts +0 -54
- package/dist/index.mjs +0 -55
- package/dist/ng-tools/SdCliNgModuleGenerator.d.ts +0 -29
- package/dist/ng-tools/SdCliNgModuleGenerator.mjs +0 -502
- package/dist/ng-tools/babel/SdCliBbFileMetadata.d.ts +0 -25
- package/dist/ng-tools/babel/SdCliBbFileMetadata.mjs +0 -539
- package/dist/ng-tools/babel/SdCliBbRootMetadata.d.ts +0 -23
- package/dist/ng-tools/babel/SdCliBbRootMetadata.mjs +0 -247
- package/dist/ng-tools/babel/SdCliBbUtil.d.ts +0 -5
- package/dist/ng-tools/babel/SdCliBbUtil.mjs +0 -14
- package/dist/ng-tools/babel/TSdCliBbNgMetadata.d.ts +0 -42
- package/dist/ng-tools/babel/TSdCliBbNgMetadata.mjs +0 -216
- package/dist/ng-tools/babel/TSdCliBbTypeMetadata.d.ts +0 -55
- package/dist/ng-tools/babel/TSdCliBbTypeMetadata.mjs +0 -151
- package/dist/ng-tools/commons.d.ts +0 -9
- package/dist/ng-tools/commons.mjs +0 -2
- package/dist/ng-tools/typescript/SdCliTsFileMetadata.d.ts +0 -61
- package/dist/ng-tools/typescript/SdCliTsFileMetadata.mjs +0 -325
- package/dist/ng-tools/typescript/SdCliTsRootMetadata.d.ts +0 -8
- package/dist/ng-tools/typescript/SdCliTsRootMetadata.mjs +0 -28
- package/dist/ng-tools/typescript/SdCliTsUtil.d.ts +0 -5
- package/dist/ng-tools/typescript/SdCliTsUtil.mjs +0 -28
- package/dist/packages/SdCliPackage.d.ts +0 -22
- package/dist/packages/SdCliPackage.mjs +0 -206
- package/dist/utils/SdCliBuildResultUtil.mjs +0 -63
- package/dist/utils/SdCliConfigUtil.mjs +0 -69
- package/dist/utils/SdCliNpmConfigUtil.d.ts +0 -7
- package/dist/utils/SdCliNpmConfigUtil.mjs +0 -15
- package/dist/worker/build-worker.mjs +0 -67
- package/dist/worker/server-worker.mjs +0 -67
- package/docs/client-add-page.md +0 -8
- package/docs/client-router.md +0 -85
- package/docs/client-sw.md +0 -101
- package/docs/conf-orm.md +0 -81
- package/docs/conf-usage.md +0 -5
- package/docs/lib-local-update.md +0 -50
- package/docs/lib-ts-paths.md +0 -25
- package/lib/cordova-entry.js +0 -22
- package/src/SdCliBuildResultError.ts +0 -9
- package/src/bin/sd-cli.ts +0 -493
- package/src/build-tool/SdCliCacheCompilerHost.ts +0 -79
- package/src/build-tool/SdCliCordova.ts +0 -263
- package/src/build-tool/SdCliElectron.ts +0 -84
- package/src/build-tool/SdCliGithubApi.ts +0 -111
- package/src/build-tool/SdCliIndexFileGenerator.ts +0 -79
- package/src/build-tool/SdCliNgCacheCompilerHost.ts +0 -58
- package/src/build-tool/SdCliPackageLinter.ts +0 -74
- package/src/builder/SdCliClientBuilder.ts +0 -871
- package/src/builder/SdCliJsLibBuilder.ts +0 -70
- package/src/builder/SdCliServerBuilder.ts +0 -552
- package/src/builder/SdCliTsLibBuilder.ts +0 -450
- package/src/entry-points/SdCliFileCrypto.ts +0 -87
- package/src/entry-points/SdCliLocalUpdate.ts +0 -121
- package/src/entry-points/SdCliPrepare.ts +0 -86
- package/src/entry-points/SdCliProject.ts +0 -491
- package/src/entry-points/SdCliProjectGenerator.ts +0 -402
- package/src/entry-points/file/base/fc_package_eslintrc.ts +0 -30
- package/src/entry-points/file/base/fc_package_npmconfig.ts +0 -43
- package/src/entry-points/file/base/fc_package_tsconfig.ts +0 -12
- package/src/entry-points/file/client/fc_package_AppModule.ts +0 -36
- package/src/entry-points/file/client/fc_package_AppPage.ts +0 -13
- package/src/entry-points/file/client/fc_package_Page.ts +0 -19
- package/src/entry-points/file/client/fc_package_client_main.ts +0 -18
- package/src/entry-points/file/client/fc_package_index.ts +0 -87
- package/src/entry-points/file/client/fc_package_manifest.ts +0 -53
- package/src/entry-points/file/client/fc_package_polyfills.ts +0 -10
- package/src/entry-points/file/client/fc_package_styles.ts +0 -6
- package/src/entry-points/file/db/fc_package_DbContext.ts +0 -14
- package/src/entry-points/file/db/fc_package_DbModel.ts +0 -11
- package/src/entry-points/file/project/fc_project_editor_config.ts +0 -21
- package/src/entry-points/file/project/fc_project_eslintrc.ts +0 -29
- package/src/entry-points/file/project/fc_project_gitattributes.ts +0 -5
- package/src/entry-points/file/project/fc_project_gitignore.ts +0 -26
- package/src/entry-points/file/project/fc_project_npmconfig.ts +0 -36
- package/src/entry-points/file/project/fc_project_readme.ts +0 -12
- package/src/entry-points/file/project/fc_project_simplysm.ts +0 -1
- package/src/entry-points/file/project/fc_project_tsconfig.ts +0 -24
- package/src/entry-points/file/server/fc_package_server_main.ts +0 -62
- package/src/index.ts +0 -54
- package/src/ng-tools/SdCliNgModuleGenerator.ts +0 -672
- package/src/ng-tools/babel/SdCliBbFileMetadata.ts +0 -629
- package/src/ng-tools/babel/SdCliBbRootMetadata.ts +0 -292
- package/src/ng-tools/babel/SdCliBbUtil.ts +0 -15
- package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +0 -251
- package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +0 -212
- package/src/ng-tools/commons.ts +0 -3
- package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +0 -384
- package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +0 -32
- package/src/ng-tools/typescript/SdCliTsUtil.ts +0 -29
- package/src/packages/SdCliPackage.ts +0 -259
- package/src/utils/SdCliNpmConfigUtil.ts +0 -16
- package/src/worker/build-worker.ts +0 -73
- package/src/worker/server-worker.ts +0 -72
- /package/dist/{worker/build-worker.d.ts → build-cluster.d.ts} +0 -0
- /package/dist/{worker/server-worker.d.ts → sd-cli.d.ts} +0 -0
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
import { SdCliTsRootMetadata } from "./typescript/SdCliTsRootMetadata";
|
|
2
|
-
import { SdCliBbRootMetadata, TSdCliBbMetadata } from "./babel/SdCliBbRootMetadata";
|
|
3
|
-
import {
|
|
4
|
-
SdCliBbArrayMetadata,
|
|
5
|
-
SdCliBbClassMetadata,
|
|
6
|
-
SdCliBbConditionMetadata,
|
|
7
|
-
SdCliBbObjectMetadata
|
|
8
|
-
} from "./babel/TSdCliBbTypeMetadata";
|
|
9
|
-
import {
|
|
10
|
-
SdCliBbNgComponentMetadata,
|
|
11
|
-
SdCliBbNgDirectiveMetadata,
|
|
12
|
-
SdCliBbNgModuleMetadata,
|
|
13
|
-
SdCliBbNgPipeMetadata
|
|
14
|
-
} from "./babel/TSdCliBbNgMetadata";
|
|
15
|
-
import { NeverEntryError, ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
|
|
16
|
-
import { TSdCliMetaRef } from "./commons";
|
|
17
|
-
import { SdCliTsNgInjectableMetadata } from "./typescript/SdCliTsFileMetadata";
|
|
18
|
-
import path from "path";
|
|
19
|
-
import { JSDOM } from "jsdom";
|
|
20
|
-
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
21
|
-
import { INpmConfig } from "../commons";
|
|
22
|
-
|
|
23
|
-
export class SdCliNgModuleGenerator {
|
|
24
|
-
private readonly _logger: Logger;
|
|
25
|
-
|
|
26
|
-
private readonly _bbMeta: SdCliBbRootMetadata;
|
|
27
|
-
private readonly _tsMeta: SdCliTsRootMetadata;
|
|
28
|
-
|
|
29
|
-
private readonly _srcPath: string;
|
|
30
|
-
private readonly _modulesPath: string;
|
|
31
|
-
|
|
32
|
-
private readonly _fileWriterCache = new Map<string, string>();
|
|
33
|
-
|
|
34
|
-
public constructor(packagePath: string,
|
|
35
|
-
private readonly _srcDirRelPaths: string[],
|
|
36
|
-
private readonly _routeOpts: {
|
|
37
|
-
glob: string;
|
|
38
|
-
fileEndsWith: string;
|
|
39
|
-
rootClassName: string;
|
|
40
|
-
} | undefined) {
|
|
41
|
-
this._srcPath = path.resolve(packagePath, "src");
|
|
42
|
-
this._modulesPath = path.resolve(packagePath, "src", "_modules");
|
|
43
|
-
|
|
44
|
-
this._bbMeta = new SdCliBbRootMetadata(packagePath);
|
|
45
|
-
this._tsMeta = new SdCliTsRootMetadata(packagePath);
|
|
46
|
-
|
|
47
|
-
const glob = FsUtil.glob(path.resolve(this._modulesPath, "**", "*.ts"));
|
|
48
|
-
for (const currFilePath of glob) {
|
|
49
|
-
const content = FsUtil.readFile(currFilePath);
|
|
50
|
-
this._fileWriterCache.set(currFilePath, content);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const npmConfig: INpmConfig = FsUtil.readJson(path.resolve(packagePath, "package.json"));
|
|
54
|
-
this._logger = Logger.get(["simplysm", "sd-cli", this.constructor.name, npmConfig.name]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public removeCaches(changedFilePaths: string[]): void {
|
|
58
|
-
this._bbMeta.removeCaches(changedFilePaths);
|
|
59
|
-
this._tsMeta.removeCaches(changedFilePaths);
|
|
60
|
-
for (const changedFilePath of changedFilePaths) {
|
|
61
|
-
if (this._fileWriterCache.has(changedFilePath) && !FsUtil.exists(changedFilePath)) {
|
|
62
|
-
this._fileWriterCache.delete(changedFilePath);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public async runAsync(): Promise<void> {
|
|
68
|
-
this._logger.debug("Babel NgModule 정의 가져오기...");
|
|
69
|
-
const bbNgModules = this._getBbNgModuleDefs();
|
|
70
|
-
|
|
71
|
-
this._logger.debug("NgModule Preset 구성...");
|
|
72
|
-
const tsPreset = this._getTsGenNgModulePreset();
|
|
73
|
-
|
|
74
|
-
this._logger.debug("RoutingModule 정의 구성...");
|
|
75
|
-
const genNgRoutingModules = await this._getGenNgRoutingModuleDefsAsync();
|
|
76
|
-
|
|
77
|
-
this._logger.debug("NgModule 정의 구성...");
|
|
78
|
-
const genNgModules = this._getGenNgModuleDefs(bbNgModules, tsPreset.modules, tsPreset.sources);
|
|
79
|
-
|
|
80
|
-
this._logger.debug("NgModule 순환참조 병합...");
|
|
81
|
-
const mergedGenNgModules = this._mergeNgModuleCircularDependency(genNgModules);
|
|
82
|
-
|
|
83
|
-
this._logger.debug("생성할 파일 내용 구성...");
|
|
84
|
-
const files = [
|
|
85
|
-
...this._getGenNgRoutingModuleFiles(genNgRoutingModules),
|
|
86
|
-
...this._getGenNgModuleFiles(mergedGenNgModules)
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
this._logger.debug("파일 쓰기...");
|
|
90
|
-
await this._writeFilesAsync(files);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private _mergeNgModuleCircularDependency(mods: ITsGenNgModuleDef[]): ITsGenNgModuleDef[] {
|
|
94
|
-
// 중복 'check'목록 구성
|
|
95
|
-
const check = (mod: ITsGenNgModuleDef, ref: { filePath: string; name: string }, chain: ITsGenNgModuleDef[]): ITsGenNgModuleDef[][] => {
|
|
96
|
-
const result: ITsGenNgModuleDef[][] = [];
|
|
97
|
-
for (const imp of mod.imports) {
|
|
98
|
-
if ("filePath" in imp) {
|
|
99
|
-
if (imp.filePath === ref.filePath || imp.name === ref.name) {
|
|
100
|
-
result.push(chain.concat([mod]));
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const childMod = mods.single((item) => item.filePath === imp.filePath && item.name === imp.name);
|
|
104
|
-
if (childMod) {
|
|
105
|
-
if (chain.some((item) => item.filePath === childMod.filePath && item.name === childMod.name)) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
result.push(
|
|
110
|
-
...check(childMod, ref, chain.concat([mod]))
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return result;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const checkedList: ITsGenNgModuleDef[][] = [];
|
|
121
|
-
for (const mod of mods) {
|
|
122
|
-
const circularDepModules = check(mod, { filePath: mod.filePath, name: mod.name }, []);
|
|
123
|
-
if (circularDepModules.length > 0) {
|
|
124
|
-
checkedList.push(...circularDepModules);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
const mergeModPacks = checkedList.map((item) => item.orderBy((item1) => item1.filePath)).distinct();
|
|
128
|
-
|
|
129
|
-
// 'merge'목록 구성
|
|
130
|
-
const currMergedList: ITsGenNgModuleDef[] = [];
|
|
131
|
-
for (const mergeModPack of mergeModPacks) {
|
|
132
|
-
let currMerged = mergeModPack[0];
|
|
133
|
-
for (const mergeMod of mergeModPack.slice(1)) {
|
|
134
|
-
currMerged = {
|
|
135
|
-
filePath: currMerged.filePath,
|
|
136
|
-
name: currMerged.name,
|
|
137
|
-
imports: currMerged.imports.concat(mergeMod.imports).distinct(),
|
|
138
|
-
exports: currMerged.exports.concat(mergeMod.exports).distinct(),
|
|
139
|
-
providers: currMerged.providers.concat(mergeMod.providers).distinct()
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
currMerged.imports.remove((imp) => (
|
|
143
|
-
"filePath" in imp &&
|
|
144
|
-
mergeModPack.some((mergeMod) => (
|
|
145
|
-
imp.filePath === mergeMod.filePath &&
|
|
146
|
-
imp.name === mergeMod.name
|
|
147
|
-
))
|
|
148
|
-
));
|
|
149
|
-
|
|
150
|
-
currMergedList.push(currMerged);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 기존 'check'된 것들 모두 삭제
|
|
154
|
-
const result: ITsGenNgModuleDef[] = ObjectUtil.clone(mods);
|
|
155
|
-
for (const delMod of mergeModPacks.mapMany()) {
|
|
156
|
-
result.remove((item) => item.filePath === delMod.filePath && item.name === delMod.name);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 'merge'된 것들 등록
|
|
160
|
-
result.push(...currMergedList);
|
|
161
|
-
|
|
162
|
-
// 모든 결과물에서 'import'에 'merge'된것들이 있으면 'merge'결과물 파일로 변경후, distinct
|
|
163
|
-
for (const resultItem of result) {
|
|
164
|
-
for (const imp of resultItem.imports) {
|
|
165
|
-
if (!("filePath" in imp)) continue;
|
|
166
|
-
|
|
167
|
-
for (const mergeModPack of mergeModPacks) {
|
|
168
|
-
if (mergeModPack.some((mergeModPackItem) => mergeModPackItem.filePath === imp.filePath && mergeModPackItem.name === imp.name)) {
|
|
169
|
-
imp.filePath = mergeModPack[0].filePath;
|
|
170
|
-
imp.name = mergeModPack[0].name;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
resultItem.imports = resultItem.imports.distinct();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return result;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
private _findBbMetasFromMeta(srcMeta: TSdCliBbMetadata): TSdCliBbMetadata[] {
|
|
181
|
-
const metaTmp = typeof srcMeta !== "string" && "__TSdCliMetaRef__" in srcMeta ? this._bbMeta.findMeta(srcMeta) : srcMeta;
|
|
182
|
-
return metaTmp instanceof Array ? metaTmp : [metaTmp];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private _getBbNgModuleProvClass(modProvMeta: TSdCliBbMetadata): { moduleName: string; name: string }[] {
|
|
186
|
-
const result: { moduleName: string; name: string }[] = [];
|
|
187
|
-
|
|
188
|
-
if (modProvMeta instanceof SdCliBbObjectMetadata) {
|
|
189
|
-
// 무시
|
|
190
|
-
}
|
|
191
|
-
else if (modProvMeta instanceof SdCliBbClassMetadata) {
|
|
192
|
-
const ref = this._bbMeta.findExportRef({
|
|
193
|
-
filePath: modProvMeta.filePath,
|
|
194
|
-
name: modProvMeta.name
|
|
195
|
-
});
|
|
196
|
-
if (ref) {
|
|
197
|
-
result.push(ref);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else if (modProvMeta instanceof SdCliBbConditionMetadata) {
|
|
201
|
-
if (modProvMeta.consequent !== undefined) {
|
|
202
|
-
result.push(
|
|
203
|
-
...this._getBbNgModuleProvClass(modProvMeta.consequent)
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (modProvMeta.alternate !== undefined) {
|
|
208
|
-
result.push(
|
|
209
|
-
...this._getBbNgModuleProvClass(modProvMeta.alternate)
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
else if (modProvMeta instanceof SdCliBbArrayMetadata) {
|
|
214
|
-
for (const modProvMetaValue of modProvMeta.value) {
|
|
215
|
-
if (modProvMetaValue !== undefined) {
|
|
216
|
-
result.push(...this._getBbNgModuleProvClass(modProvMetaValue));
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
throw new NeverEntryError();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return result;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private _getBbNgModuleDefs(): IBbNgModuleDef[] {
|
|
228
|
-
const entryRecord = this._bbMeta.getEntryFileMetaRecord();
|
|
229
|
-
const result: IBbNgModuleDef[] = [];
|
|
230
|
-
|
|
231
|
-
for (const moduleName of Object.keys(entryRecord)) {
|
|
232
|
-
const fileMeta = entryRecord[moduleName];
|
|
233
|
-
for (const exp of fileMeta.exports) {
|
|
234
|
-
const metas = this._findBbMetasFromMeta(exp.target);
|
|
235
|
-
|
|
236
|
-
for (const meta of metas) {
|
|
237
|
-
if (meta instanceof SdCliBbClassMetadata) {
|
|
238
|
-
if (meta.ngDecl instanceof SdCliBbNgModuleMetadata) {
|
|
239
|
-
const ngDecl = meta.ngDecl;
|
|
240
|
-
|
|
241
|
-
const resultItem: IBbNgModuleDef = {
|
|
242
|
-
moduleName,
|
|
243
|
-
name: exp.exportedName === "*" ? meta.name : exp.exportedName,
|
|
244
|
-
providers: [],
|
|
245
|
-
exports: [],
|
|
246
|
-
selectors: [],
|
|
247
|
-
pipeNames: []
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
for (const modProv of ngDecl.def.providers) {
|
|
251
|
-
const modProvMetas = this._findBbMetasFromMeta(modProv);
|
|
252
|
-
if (modProvMetas.length === 0) {
|
|
253
|
-
throw new NeverEntryError();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
for (const modProvMeta of modProvMetas) {
|
|
257
|
-
resultItem.providers.push(...this._getBbNgModuleProvClass(modProvMeta));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
for (const modExp of ngDecl.def.exports) {
|
|
262
|
-
const modExpMetas = this._findBbMetasFromMeta(modExp);
|
|
263
|
-
if (modExpMetas.length === 0) {
|
|
264
|
-
throw new NeverEntryError();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
for (const modExpMeta of modExpMetas) {
|
|
268
|
-
if (modExpMeta instanceof SdCliBbClassMetadata) {
|
|
269
|
-
const ref = this._bbMeta.findExportRef({
|
|
270
|
-
filePath: modExpMeta.filePath,
|
|
271
|
-
name: modExpMeta.name
|
|
272
|
-
});
|
|
273
|
-
if (ref) {
|
|
274
|
-
resultItem.exports.push(ref);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (modExpMeta.ngDecl instanceof SdCliBbNgDirectiveMetadata) {
|
|
278
|
-
resultItem.selectors.push(modExpMeta.ngDecl.selector);
|
|
279
|
-
}
|
|
280
|
-
else if (modExpMeta.ngDecl instanceof SdCliBbNgComponentMetadata) {
|
|
281
|
-
resultItem.selectors.push(modExpMeta.ngDecl.selector);
|
|
282
|
-
}
|
|
283
|
-
else if (modExpMeta.ngDecl instanceof SdCliBbNgPipeMetadata) {
|
|
284
|
-
resultItem.pipeNames.push(modExpMeta.ngDecl.pipeName);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
throw new NeverEntryError();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
result.push(resultItem);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return result;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
private _getTsGenNgModulePreset(): { modules: ITsNgPresetModuleDef[]; sources: ITsNgPresetSourceDef[] } {
|
|
303
|
-
const fileMetas = this._tsMeta.getFileMetas();
|
|
304
|
-
|
|
305
|
-
const result: { modules: ITsNgPresetModuleDef[]; sources: ITsNgPresetSourceDef[] } = { modules: [], sources: [] };
|
|
306
|
-
|
|
307
|
-
for (const fileMeta of fileMetas) {
|
|
308
|
-
if (!this._srcDirRelPaths.some((item) => fileMeta.filePath.startsWith(path.resolve(this._srcPath, item)))) {
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
for (const cls of fileMeta.directExportClasses) {
|
|
313
|
-
if (cls.target.ngDecl) {
|
|
314
|
-
if (cls.target.ngDecl instanceof SdCliTsNgInjectableMetadata) {
|
|
315
|
-
if (cls.target.ngDecl.providedIn === "root") {
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const moduleClassName = cls.exportedName + "Module";
|
|
321
|
-
const moduleFilePath = path.resolve(this._modulesPath, path.relative(this._srcPath, path.dirname(fileMeta.filePath)), moduleClassName);
|
|
322
|
-
|
|
323
|
-
result.sources.push({
|
|
324
|
-
filePath: fileMeta.filePath.replace(/\.[^.]*$/, ""),
|
|
325
|
-
name: cls.exportedName,
|
|
326
|
-
module: {
|
|
327
|
-
filePath: moduleFilePath,
|
|
328
|
-
name: moduleClassName
|
|
329
|
-
},
|
|
330
|
-
imports: fileMeta.imports,
|
|
331
|
-
template: "template" in cls.target.ngDecl ? cls.target.ngDecl.template : undefined,
|
|
332
|
-
isProvider: cls.target.ngDecl instanceof SdCliTsNgInjectableMetadata
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
result.modules.push({
|
|
336
|
-
filePath: moduleFilePath,
|
|
337
|
-
name: moduleClassName,
|
|
338
|
-
source: {
|
|
339
|
-
filePath: fileMeta.filePath.replace(/\.[^.]*$/, ""),
|
|
340
|
-
name: cls.exportedName
|
|
341
|
-
},
|
|
342
|
-
selector: "selector" in cls.target.ngDecl ? cls.target.ngDecl.selector : undefined,
|
|
343
|
-
pipeName: "pipeName" in cls.target.ngDecl ? cls.target.ngDecl.pipeName : undefined
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return result;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private _getGenNgModuleDefs(bbModules: IBbNgModuleDef[], presetModules: ITsNgPresetModuleDef[], presetSources: ITsNgPresetSourceDef[]): ITsGenNgModuleDef[] {
|
|
353
|
-
const result: ITsGenNgModuleDef[] = [];
|
|
354
|
-
|
|
355
|
-
for (const presetSource of presetSources) {
|
|
356
|
-
const imports: TSdCliMetaRef[] = [];
|
|
357
|
-
for (const imp of presetSource.imports) {
|
|
358
|
-
if ("moduleName" in imp) {
|
|
359
|
-
for (const mod of bbModules) {
|
|
360
|
-
if (mod.exports.some((item) => item.moduleName === imp.moduleName && item.name === imp.name)) {
|
|
361
|
-
imports.push({ moduleName: mod.moduleName, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
362
|
-
}
|
|
363
|
-
if (mod.providers.some((item) => item.moduleName === imp.moduleName && item.name === imp.name)) {
|
|
364
|
-
imports.push({ moduleName: mod.moduleName, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
for (const mod of presetModules) {
|
|
370
|
-
if (mod.source && mod.source.filePath === imp.filePath && mod.source.name === imp.name) {
|
|
371
|
-
imports.push({ filePath: mod.filePath, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
if (presetSource.template !== undefined) {
|
|
378
|
-
const templateDOM = new JSDOM(presetSource.template);
|
|
379
|
-
|
|
380
|
-
for (const mod of bbModules) {
|
|
381
|
-
for (const selector of mod.selectors) {
|
|
382
|
-
if (
|
|
383
|
-
templateDOM.window.document.querySelector([
|
|
384
|
-
selector,
|
|
385
|
-
selector.replace(/\[/g, "[\\[").replace(/]/g, "\\]]"),
|
|
386
|
-
selector.replace(/\[/g, "[\\(").replace(/]/g, "\\)]")
|
|
387
|
-
].join(", ")) != null
|
|
388
|
-
) {
|
|
389
|
-
imports.push({ moduleName: mod.moduleName, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
for (const pipeName of mod.pipeNames) {
|
|
394
|
-
if (new RegExp("| *" + pipeName + "[^\\w]").test(presetSource.template)) {
|
|
395
|
-
imports.push({ moduleName: mod.moduleName, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
for (const mod of presetModules) {
|
|
401
|
-
if (mod.selector !== undefined) {
|
|
402
|
-
if (
|
|
403
|
-
templateDOM.window.document.querySelector([
|
|
404
|
-
mod.selector,
|
|
405
|
-
mod.selector.replace(/\[/g, "[\\[").replace(/]/g, "\\]]"),
|
|
406
|
-
mod.selector.replace(/\[/g, "[\\(").replace(/]/g, "\\)]")
|
|
407
|
-
].join(", ")) != null
|
|
408
|
-
) {
|
|
409
|
-
imports.push({ filePath: mod.filePath, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (mod.pipeName !== undefined) {
|
|
414
|
-
if (new RegExp("| *" + mod.pipeName + "[^\\w]").test(presetSource.template)) {
|
|
415
|
-
imports.push({ filePath: mod.filePath, name: mod.name, __TSdCliMetaRef__: "__TSdCliMetaRef__" });
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
result.push({
|
|
422
|
-
filePath: presetSource.module.filePath,
|
|
423
|
-
name: presetSource.module.name,
|
|
424
|
-
imports: imports.distinct(),
|
|
425
|
-
exports: presetSource.isProvider ? [] : [{ filePath: presetSource.filePath, name: presetSource.name }],
|
|
426
|
-
providers: presetSource.isProvider ? [{ filePath: presetSource.filePath, name: presetSource.name }] : []
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
return result;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
private async _getGenNgRoutingModuleDefsAsync(): Promise<TTsGenNgRoutingModuleDef[]> {
|
|
434
|
-
if (this._routeOpts === undefined) return [];
|
|
435
|
-
|
|
436
|
-
const result: TTsGenNgRoutingModuleDef[] = [];
|
|
437
|
-
|
|
438
|
-
const filePaths = await FsUtil.globAsync(path.resolve(this._srcPath, this._routeOpts.glob));
|
|
439
|
-
for (const filePath of filePaths) {
|
|
440
|
-
const sourceClassName = path.basename(filePath, path.extname(filePath));
|
|
441
|
-
if (sourceClassName === this._routeOpts.rootClassName) {
|
|
442
|
-
const childDirName = StringUtil.toKebabCase(sourceClassName.slice(0, -this._routeOpts.fileEndsWith.length));
|
|
443
|
-
const childDirPath = path.resolve(path.dirname(filePath), childDirName);
|
|
444
|
-
|
|
445
|
-
result.push({
|
|
446
|
-
filePath: path.resolve(this._srcPath, "_routes"),
|
|
447
|
-
children: await this._getGenNgRoutingModuleDefChildrenAsync(childDirPath)
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
const routingModuleClassName = sourceClassName + "RoutingModule";
|
|
452
|
-
const routingModuleFilePath = path.resolve(this._modulesPath, path.relative(this._srcPath, path.dirname(filePath)), routingModuleClassName);
|
|
453
|
-
const childDirName = StringUtil.toKebabCase(sourceClassName.slice(0, -this._routeOpts.fileEndsWith.length));
|
|
454
|
-
const childDirPath = path.resolve(path.dirname(filePath), childDirName);
|
|
455
|
-
|
|
456
|
-
result.push({
|
|
457
|
-
filePath: routingModuleFilePath,
|
|
458
|
-
name: routingModuleClassName,
|
|
459
|
-
component: { filePath: filePath.replace(/\.ts$/, ""), name: sourceClassName },
|
|
460
|
-
children: FsUtil.exists(childDirPath) ? await this._getGenNgRoutingModuleDefChildrenAsync(childDirPath) : undefined
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return result;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
private async _getGenNgRoutingModuleDefChildrenAsync(rootPath: string): Promise<TTsGenNgRoutingModuleDefChild[]> {
|
|
469
|
-
const result: TTsGenNgRoutingModuleDefChild[] = [];
|
|
470
|
-
|
|
471
|
-
const childNames = await FsUtil.readdirAsync(rootPath);
|
|
472
|
-
for (const childName of childNames) {
|
|
473
|
-
if (!FsUtil.stat(path.resolve(rootPath, childName)).isDirectory()) { // 파일
|
|
474
|
-
const sourceFilePath = path.resolve(rootPath, childName);
|
|
475
|
-
const sourceClassName = path.basename(sourceFilePath, path.extname(childName));
|
|
476
|
-
const moduleClassName = sourceClassName + "Module";
|
|
477
|
-
const moduleFilePath = path.resolve(this._modulesPath, path.relative(this._srcPath, path.dirname(sourceFilePath)), moduleClassName);
|
|
478
|
-
|
|
479
|
-
result.push({
|
|
480
|
-
path: StringUtil.toKebabCase(childName.substring(0, childName.length - 7)),
|
|
481
|
-
target: { filePath: moduleFilePath, name: moduleClassName }
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
else if (!FsUtil.exists(path.resolve(rootPath, StringUtil.toPascalCase(childName) + this._routeOpts!.fileEndsWith + ".ts"))) { // 파일없는 디렉토리
|
|
485
|
-
result.push({
|
|
486
|
-
path: childName,
|
|
487
|
-
children: await this._getGenNgRoutingModuleDefChildrenAsync(path.resolve(rootPath, childName))
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return result;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
private _getGenNgRoutingModuleFiles(defs: TTsGenNgRoutingModuleDef[]): { filePath: string; content: string }[] {
|
|
496
|
-
const result: { filePath: string; content: string }[] = [];
|
|
497
|
-
|
|
498
|
-
for (const def of defs) {
|
|
499
|
-
const fn = (children: TTsGenNgRoutingModuleDefChild[]): string => {
|
|
500
|
-
let fnResult = "[\n";
|
|
501
|
-
for (const child of children) {
|
|
502
|
-
fnResult += " {\n";
|
|
503
|
-
fnResult += ` path: "${child.path}",\n`;
|
|
504
|
-
if ("target" in child) {
|
|
505
|
-
fnResult += ` loadChildren: () => import("${this._getFileImportModuleName(def.filePath, child.target.filePath)}").then((m) => m.${child.target.name})\n`;
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
fnResult += ` children: ${fn(child.children).replace(/\n/g, "\n ")}\n`;
|
|
509
|
-
}
|
|
510
|
-
fnResult += " },\n";
|
|
511
|
-
}
|
|
512
|
-
fnResult = fnResult.slice(0, -2) + "\n";
|
|
513
|
-
fnResult += "]";
|
|
514
|
-
|
|
515
|
-
return fnResult;
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
const content = "component" in def ? `
|
|
519
|
-
import { NgModule } from "@angular/core";
|
|
520
|
-
import { RouterModule } from "@angular/router";
|
|
521
|
-
import { SdCanDeactivateGuard } from "@simplysm/sd-angular";
|
|
522
|
-
import { ${def.component.name} } from "${this._getFileImportModuleName(def.filePath, def.component.filePath)}";
|
|
523
|
-
|
|
524
|
-
@NgModule({
|
|
525
|
-
imports: [
|
|
526
|
-
RouterModule.forChild([
|
|
527
|
-
{
|
|
528
|
-
path: "",
|
|
529
|
-
component: ${def.component.name},
|
|
530
|
-
canDeactivate: [SdCanDeactivateGuard]${def.children ? `,
|
|
531
|
-
children: ${fn(def.children).replace(/\n/g, "\n ")}` : ""}
|
|
532
|
-
}
|
|
533
|
-
])
|
|
534
|
-
],
|
|
535
|
-
exports: [RouterModule]
|
|
536
|
-
})
|
|
537
|
-
export class ${def.name} {
|
|
538
|
-
}`.trim() : `
|
|
539
|
-
import { Routes } from "@angular/router";
|
|
540
|
-
|
|
541
|
-
export const routes: Routes = ${fn(def.children)};
|
|
542
|
-
`.trim();
|
|
543
|
-
|
|
544
|
-
result.push({ filePath: def.filePath + ".ts", content });
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
return result;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
private _getGenNgModuleFiles(mods: ITsGenNgModuleDef[]): { filePath: string; content: string }[] {
|
|
551
|
-
const result: { filePath: string; content: string }[] = [];
|
|
552
|
-
|
|
553
|
-
for (const mod of mods) {
|
|
554
|
-
const importMap = [...mod.imports, ...mod.exports, ...mod.providers]
|
|
555
|
-
.map((item) => ({
|
|
556
|
-
moduleName: "moduleName" in item ? item.moduleName : this._getFileImportModuleName(mod.filePath, item.filePath),
|
|
557
|
-
name: item.name
|
|
558
|
-
}))
|
|
559
|
-
.groupBy((item) => item.moduleName)
|
|
560
|
-
.toMap((item) => item.key, (item) => item.values.map((v) => v.name));
|
|
561
|
-
importMap.getOrCreate("@angular/core", []).push("NgModule");
|
|
562
|
-
|
|
563
|
-
const importTexts: string[] = [];
|
|
564
|
-
for (const moduleName of Array.from(importMap.keys()).orderBy()) {
|
|
565
|
-
const targetNames = importMap.get(moduleName)!.distinct();
|
|
566
|
-
if (targetNames.length === 0) continue;
|
|
567
|
-
importTexts.push(`import { ${targetNames.join(", ")} } from "${moduleName}";`);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const moduleImportNames = mod.imports.map((item) => item.name);
|
|
571
|
-
if (
|
|
572
|
-
this._routeOpts !== undefined
|
|
573
|
-
&& mod.filePath.endsWith(this._routeOpts.fileEndsWith + "Module")
|
|
574
|
-
&& mod.name !== this._routeOpts.rootClassName + "Module"
|
|
575
|
-
) {
|
|
576
|
-
const routingModuleName = mod.name.replace(/Module$/, "RoutingModule");
|
|
577
|
-
importTexts.push(`import { ${routingModuleName} } from "./${routingModuleName}";`);
|
|
578
|
-
moduleImportNames.push(routingModuleName);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
const content = `
|
|
582
|
-
${importTexts.join("\n")}
|
|
583
|
-
|
|
584
|
-
@NgModule({
|
|
585
|
-
imports: [${moduleImportNames.orderBy().join(", ")}],
|
|
586
|
-
declarations: [${mod.exports.map((item) => item.name).distinct().orderBy().join(", ")}],
|
|
587
|
-
exports: [${mod.exports.map((item) => item.name).distinct().orderBy().join(", ")}],
|
|
588
|
-
providers: [${mod.providers.map((item) => item.name).distinct().orderBy().join(", ")}]
|
|
589
|
-
})
|
|
590
|
-
export class ${mod.name} {
|
|
591
|
-
}`.trim();
|
|
592
|
-
|
|
593
|
-
result.push({ filePath: mod.filePath + ".ts", content });
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return result;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
private async _writeFilesAsync(files: { filePath: string; content: string }[]): Promise<void> {
|
|
600
|
-
for (const file of files) {
|
|
601
|
-
if (this._fileWriterCache.get(file.filePath) !== file.content) {
|
|
602
|
-
await FsUtil.writeFileAsync(file.filePath, file.content);
|
|
603
|
-
this._fileWriterCache.set(file.filePath, file.content);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
const glob = await FsUtil.globAsync(path.resolve(this._modulesPath, "**", "*"));
|
|
608
|
-
for (const currFilePath of glob) {
|
|
609
|
-
if (!files.some((item) => item.filePath.startsWith(currFilePath))) {
|
|
610
|
-
await FsUtil.removeAsync(currFilePath);
|
|
611
|
-
this._fileWriterCache.delete(currFilePath);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
private _getFileImportModuleName(mainFilePath: string, importFilePath: string): string {
|
|
617
|
-
const filePath = PathUtil.posix(path.relative(path.dirname(mainFilePath), importFilePath).replace(/\.ts$/, ""));
|
|
618
|
-
return filePath.startsWith(".") ? filePath : "./" + filePath;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
interface IBbNgModuleDef {
|
|
623
|
-
moduleName: string;
|
|
624
|
-
name: string;
|
|
625
|
-
providers: { moduleName: string; name: string }[];
|
|
626
|
-
exports: { moduleName: string; name: string }[];
|
|
627
|
-
selectors: string[];
|
|
628
|
-
pipeNames: string[];
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
interface ITsNgPresetModuleDef {
|
|
632
|
-
filePath: string;
|
|
633
|
-
name: string;
|
|
634
|
-
source?: { filePath: string; name: string };
|
|
635
|
-
selector?: string;
|
|
636
|
-
pipeName?: string;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
interface ITsNgPresetSourceDef {
|
|
640
|
-
filePath: string;
|
|
641
|
-
name: string;
|
|
642
|
-
module: { filePath: string; name: string };
|
|
643
|
-
imports: TSdCliMetaRef[];
|
|
644
|
-
template?: string;
|
|
645
|
-
isProvider: boolean;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
interface ITsGenNgModuleDef {
|
|
649
|
-
filePath: string;
|
|
650
|
-
name: string;
|
|
651
|
-
imports: TSdCliMetaRef[];
|
|
652
|
-
exports: { filePath: string; name: string }[];
|
|
653
|
-
providers: { filePath: string; name: string }[];
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
type TTsGenNgRoutingModuleDef = {
|
|
657
|
-
filePath: string;
|
|
658
|
-
name: string;
|
|
659
|
-
component: { filePath: string; name: string };
|
|
660
|
-
children?: TTsGenNgRoutingModuleDefChild[];
|
|
661
|
-
} | {
|
|
662
|
-
filePath: string;
|
|
663
|
-
children: TTsGenNgRoutingModuleDefChild[];
|
|
664
|
-
};
|
|
665
|
-
|
|
666
|
-
type TTsGenNgRoutingModuleDefChild = {
|
|
667
|
-
path: string;
|
|
668
|
-
target: { filePath: string; name: string };
|
|
669
|
-
} | {
|
|
670
|
-
path: string;
|
|
671
|
-
children: TTsGenNgRoutingModuleDefChild[];
|
|
672
|
-
};
|