@simplysm/sd-cli 7.0.59 → 7.0.66
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/dist/SdCliBuildResultError.d.ts +5 -0
- package/dist/SdCliBuildResultError.mjs +8 -0
- package/dist/bin/sd-cli.d.ts +2 -0
- package/dist/bin/sd-cli.mjs +3 -3
- package/dist/build-tool/SdCliCacheCompilerHost.d.ts +10 -0
- package/dist/build-tool/SdCliCordova.d.ts +16 -0
- package/dist/build-tool/SdCliCordova.mjs +171 -0
- package/dist/build-tool/SdCliIndexFileGenerator.d.ts +13 -0
- package/dist/{entry-points → build-tool}/SdCliIndexFileGenerator.mjs +4 -3
- package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +11 -0
- package/dist/build-tool/SdCliPackageLinter.d.ts +8 -0
- package/dist/build-tool/SdCliPackageLinter.mjs +19 -2
- package/dist/builder/SdCliClientBuilder.d.ts +23 -0
- package/dist/builder/SdCliClientBuilder.mjs +68 -6
- package/dist/builder/SdCliJsLibBuilder.d.ts +14 -0
- package/dist/builder/SdCliServerBuilder.d.ts +25 -0
- package/dist/builder/SdCliServerBuilder.mjs +11 -13
- package/dist/builder/SdCliTsLibBuilder.d.ts +34 -0
- package/dist/builder/SdCliTsLibBuilder.mjs +90 -20
- package/dist/commons.d.ts +85 -0
- package/dist/entry-points/SdCliLocalUpdate.d.ts +13 -0
- package/dist/entry-points/SdCliNpm.d.ts +6 -0
- package/dist/entry-points/SdCliPrepare.d.ts +5 -0
- package/dist/entry-points/SdCliWorkspace.d.ts +28 -0
- package/dist/entry-points/SdCliWorkspace.mjs +12 -16
- package/dist/index.d.ts +29 -0
- package/dist/index.mjs +30 -0
- package/dist/ng-tools/SdCliNgModuleGenerator.d.ts +26 -0
- package/dist/ng-tools/SdCliNgModuleGenerator.mjs +404 -0
- package/dist/ng-tools/babel/SdCliBbFileMetadata.d.ts +23 -0
- package/dist/ng-tools/babel/SdCliBbFileMetadata.mjs +482 -0
- package/dist/ng-tools/babel/SdCliBbRootMetadata.d.ts +22 -0
- package/dist/ng-tools/babel/SdCliBbRootMetadata.mjs +174 -0
- package/dist/ng-tools/babel/SdCliBbUtil.d.ts +5 -0
- package/dist/ng-tools/babel/SdCliBbUtil.mjs +14 -0
- package/dist/ng-tools/babel/TSdCliBbNgMetadata.d.ts +42 -0
- package/dist/ng-tools/babel/TSdCliBbNgMetadata.mjs +200 -0
- package/dist/ng-tools/babel/TSdCliBbTypeMetadata.d.ts +44 -0
- package/dist/ng-tools/babel/TSdCliBbTypeMetadata.mjs +127 -0
- package/dist/ng-tools/commons.d.ts +9 -0
- package/dist/ng-tools/commons.mjs +2 -0
- package/dist/ng-tools/typescript/SdCliTsFileMetadata.d.ts +61 -0
- package/dist/ng-tools/typescript/SdCliTsFileMetadata.mjs +326 -0
- package/dist/ng-tools/typescript/SdCliTsRootMetadata.d.ts +8 -0
- package/dist/ng-tools/typescript/SdCliTsRootMetadata.mjs +28 -0
- package/dist/ng-tools/typescript/SdCliTsUtil.d.ts +5 -0
- package/dist/ng-tools/typescript/SdCliTsUtil.mjs +28 -0
- package/dist/packages/SdCliPackage.d.ts +23 -0
- package/dist/packages/SdCliPackage.mjs +2 -3
- package/dist/utils/SdCliBuildResultUtil.d.ts +9 -0
- package/dist/utils/SdCliConfigUtil.d.ts +7 -0
- package/dist/utils/SdCliNpmConfigUtil.d.ts +7 -0
- package/dist/utils/SdCliNpmConfigUtil.mjs +3 -3
- package/package.json +16 -7
- package/src/SdCliBuildResultError.ts +9 -0
- package/src/bin/sd-cli.ts +2 -2
- package/src/build-tool/SdCliCordova.ts +219 -0
- package/src/{entry-points → build-tool}/SdCliIndexFileGenerator.ts +3 -2
- package/src/build-tool/SdCliPackageLinter.ts +18 -2
- package/src/builder/SdCliClientBuilder.ts +83 -5
- package/src/builder/SdCliServerBuilder.ts +10 -12
- package/src/builder/SdCliTsLibBuilder.ts +105 -21
- package/src/commons.ts +24 -0
- package/src/entry-points/SdCliWorkspace.ts +14 -17
- package/src/index.ts +29 -0
- package/src/ng-tools/SdCliNgModuleGenerator.ts +538 -0
- package/src/ng-tools/babel/SdCliBbFileMetadata.ts +568 -0
- package/src/ng-tools/babel/SdCliBbRootMetadata.ts +211 -0
- package/src/ng-tools/babel/SdCliBbUtil.ts +15 -0
- package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +234 -0
- package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +177 -0
- package/src/ng-tools/commons.ts +3 -0
- package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +385 -0
- package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +32 -0
- package/src/ng-tools/typescript/SdCliTsUtil.ts +29 -0
- package/src/packages/SdCliPackage.ts +1 -2
- package/src/utils/SdCliNpmConfigUtil.ts +2 -2
- package/tsconfig-build.json +6 -2
- package/tsconfig.json +5 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { SdCliBbFileMetadata } from "./SdCliBbFileMetadata";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { INpmConfig } from "../../commons";
|
|
4
|
+
import { SdCliNpmConfigUtil } from "../../utils/SdCliNpmConfigUtil";
|
|
5
|
+
import { NeverEntryError, StringUtil } from "@simplysm/sd-core-common";
|
|
6
|
+
import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
7
|
+
import { TSdCliBbTypeMetadata } from "./TSdCliBbTypeMetadata";
|
|
8
|
+
import { TSdCliMetaRef } from "../commons";
|
|
9
|
+
|
|
10
|
+
export class SdCliBbRootMetadata {
|
|
11
|
+
private readonly _entryMap: Map<string, string>;
|
|
12
|
+
private readonly _fileMetaCache = new Map<string, SdCliBbFileMetadata>();
|
|
13
|
+
|
|
14
|
+
public constructor(packagePath: string) {
|
|
15
|
+
const allDepPaths = this._getAllDepPaths(packagePath);
|
|
16
|
+
this._entryMap = this._getEntryMap(allDepPaths);
|
|
17
|
+
// const ngDepPaths = this._getNgDepPaths(allDepPaths);
|
|
18
|
+
// this._entryMap = this._getEntryMap(ngDepPaths);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public removeCaches(filePaths: string[]): void {
|
|
22
|
+
for (const filePath of filePaths) {
|
|
23
|
+
this._fileMetaCache.delete(filePath);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public getEntryFileMetaRecord(): Record<string, SdCliBbFileMetadata> {
|
|
28
|
+
const result: Record<string, SdCliBbFileMetadata> = {};
|
|
29
|
+
for (const moduleName of this._entryMap.keys()) {
|
|
30
|
+
const entryFilePath = this._entryMap.get(moduleName)!;
|
|
31
|
+
result[moduleName] = this._fileMetaCache.getOrCreate(entryFilePath, () => new SdCliBbFileMetadata(entryFilePath))!;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public findMeta(ref: TSdCliMetaRef): TSdCliBbMetadata | TSdCliBbMetadata[] {
|
|
37
|
+
const filePath = "moduleName" in ref ? this._entryMap.get(ref.moduleName) : ref.filePath;
|
|
38
|
+
if (filePath === undefined) {
|
|
39
|
+
throw new NeverEntryError();
|
|
40
|
+
}
|
|
41
|
+
const fileMeta = this._fileMetaCache.getOrCreate(filePath, () => new SdCliBbFileMetadata(filePath));
|
|
42
|
+
if (ref.name === "*") {
|
|
43
|
+
const result: TSdCliBbMetadata[] = [];
|
|
44
|
+
for (const exp of fileMeta.exports) {
|
|
45
|
+
const meta = exp.target;
|
|
46
|
+
if (typeof meta !== "string" && "__TSdCliMetaRef__" in meta) {
|
|
47
|
+
const resultMeta = this.findMeta(meta);
|
|
48
|
+
if (resultMeta instanceof Array) {
|
|
49
|
+
result.push(...resultMeta);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
result.push(resultMeta);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result.push(meta);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const meta = fileMeta.findMetaFromOutside(ref.name);
|
|
63
|
+
if (meta === undefined) {
|
|
64
|
+
throw new NeverEntryError();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof meta !== "string" && "__TSdCliMetaRef__" in meta) {
|
|
68
|
+
return this.findMeta(meta);
|
|
69
|
+
}
|
|
70
|
+
return meta;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public findExportRef(localRef: { filePath: string; name: string }): { moduleName: string; name: string } | undefined {
|
|
75
|
+
const record = this.getEntryFileMetaRecord();
|
|
76
|
+
for (const moduleName of Object.keys(record)) {
|
|
77
|
+
const entryFileMeta = record[moduleName];
|
|
78
|
+
for (const exp of entryFileMeta.exports) {
|
|
79
|
+
if (
|
|
80
|
+
typeof exp.target !== "string" &&
|
|
81
|
+
"filePath" in exp.target &&
|
|
82
|
+
exp.target.filePath === localRef.filePath
|
|
83
|
+
) {
|
|
84
|
+
if (exp.target.name === "*") {
|
|
85
|
+
return { moduleName, name: localRef.name };
|
|
86
|
+
}
|
|
87
|
+
else if (exp.target.name === localRef.name) {
|
|
88
|
+
return { moduleName, name: exp.exportedName };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private _getAllDepPaths(packagePath: string): string[] {
|
|
98
|
+
const loadedModuleNames: string[] = [];
|
|
99
|
+
const results: string[] = [];
|
|
100
|
+
|
|
101
|
+
const fn = (currPath: string): void => {
|
|
102
|
+
const npmConfig = FsUtil.readJson(path.resolve(currPath, "package.json")) as INpmConfig;
|
|
103
|
+
|
|
104
|
+
const deps = SdCliNpmConfigUtil.getDependencies(npmConfig);
|
|
105
|
+
|
|
106
|
+
for (const moduleName of deps.defaults) {
|
|
107
|
+
if (loadedModuleNames.includes(moduleName)) continue;
|
|
108
|
+
loadedModuleNames.push(moduleName);
|
|
109
|
+
|
|
110
|
+
const modulePath = FsUtil.findAllParentChildDirPaths("node_modules/" + moduleName, currPath, process.cwd()).first();
|
|
111
|
+
if (StringUtil.isNullOrEmpty(modulePath)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
results.push(modulePath);
|
|
116
|
+
|
|
117
|
+
fn(modulePath);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
fn(packagePath);
|
|
122
|
+
|
|
123
|
+
return results;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// private _getNgDepPaths(allDepPaths: string[]): string[] {
|
|
127
|
+
// const results: string[] = [];
|
|
128
|
+
//
|
|
129
|
+
// for (const depPath of allDepPaths) {
|
|
130
|
+
// const npmConfig = FsUtil.readJson(path.resolve(depPath, "package.json")) as INpmConfig;
|
|
131
|
+
// const defaultDeps = SdCliNpmConfigUtil.getDependencies(npmConfig).defaults;
|
|
132
|
+
// if (npmConfig.name === "@angular/core" || defaultDeps.includes("@angular/core")) {
|
|
133
|
+
// results.push(depPath);
|
|
134
|
+
// }
|
|
135
|
+
// }
|
|
136
|
+
//
|
|
137
|
+
// return results;
|
|
138
|
+
// }
|
|
139
|
+
|
|
140
|
+
private _getEntryMap(ngDepPaths: string[]): Map<string, string> {
|
|
141
|
+
const entryMap = new Map<string, string>();
|
|
142
|
+
for (const ngDepPath of ngDepPaths) {
|
|
143
|
+
const npmConfig = FsUtil.readJson(path.resolve(ngDepPath, "package.json")) as INpmConfig;
|
|
144
|
+
|
|
145
|
+
const entryFilePath = npmConfig["es2015"] ?? npmConfig["browser"] ?? npmConfig["module"] ?? npmConfig["main"] ?? npmConfig["default"];
|
|
146
|
+
if (typeof entryFilePath === "string") {
|
|
147
|
+
entryMap.set(npmConfig.name, path.resolve(ngDepPath, entryFilePath));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (npmConfig.exports) {
|
|
151
|
+
const exportKeys = Object.keys(npmConfig.exports);
|
|
152
|
+
for (const exportKey of exportKeys) {
|
|
153
|
+
if (
|
|
154
|
+
exportKey.includes("/locales") ||
|
|
155
|
+
exportKey.endsWith(".json") ||
|
|
156
|
+
exportKey.endsWith("/testing") ||
|
|
157
|
+
exportKey.endsWith("/upgrade")
|
|
158
|
+
) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const expEntryFilePath = npmConfig.exports[exportKey]["es2015"] ??
|
|
163
|
+
npmConfig.exports[exportKey]["browser"] ??
|
|
164
|
+
npmConfig.exports[exportKey]["module"] ??
|
|
165
|
+
npmConfig.exports[exportKey]["main"] ??
|
|
166
|
+
npmConfig.exports[exportKey]["default"];
|
|
167
|
+
if (typeof expEntryFilePath === "string") {
|
|
168
|
+
const exportPath = path.resolve(ngDepPath, expEntryFilePath);
|
|
169
|
+
const exportResult = this._getGlobExportResult(PathUtil.posix(npmConfig.name, exportKey), exportPath);
|
|
170
|
+
for (const exportResultItem of exportResult) {
|
|
171
|
+
entryMap.set(exportResultItem.name, exportResultItem.target);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return entryMap;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private _getGlobExportResult(globName: string, globTarget: string): { name: string; target: string }[] {
|
|
182
|
+
if (globName.includes("*") && globTarget.includes("*")) {
|
|
183
|
+
const result: { name: string; target: string }[] = [];
|
|
184
|
+
|
|
185
|
+
const regexpText = globTarget.replace(/[\\/.*]/g, (item) => (
|
|
186
|
+
item === "/" || item === "\\" ? "[\\\\/]"
|
|
187
|
+
: item === "." ? "\\."
|
|
188
|
+
: item === "*" ? "(.*)"
|
|
189
|
+
: item
|
|
190
|
+
));
|
|
191
|
+
|
|
192
|
+
const targets = FsUtil.glob(globTarget);
|
|
193
|
+
for (const target of targets) {
|
|
194
|
+
const targetNameMatch = new RegExp(regexpText).exec(target);
|
|
195
|
+
if (!targetNameMatch || typeof targetNameMatch[1] === "undefined") {
|
|
196
|
+
throw new NeverEntryError();
|
|
197
|
+
}
|
|
198
|
+
const targetName = targetNameMatch[1];
|
|
199
|
+
const name = globName.replace("*", targetName);
|
|
200
|
+
result.push({ name, target });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
return [{ name: globName, target: globTarget }];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export type TSdCliBbMetadata = TSdCliBbTypeMetadata | TSdCliMetaRef | string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Node } from "@babel/types";
|
|
2
|
+
import { SdCliBuildResultError } from "../../SdCliBuildResultError";
|
|
3
|
+
|
|
4
|
+
export class SdCliBbUtil {
|
|
5
|
+
public static error(message: string, filePath?: string, meta?: Node): SdCliBuildResultError {
|
|
6
|
+
return new SdCliBuildResultError({
|
|
7
|
+
filePath,
|
|
8
|
+
line: meta?.loc?.start.line,
|
|
9
|
+
char: meta?.loc?.start.column,
|
|
10
|
+
code: undefined,
|
|
11
|
+
severity: "error",
|
|
12
|
+
message: message
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { NeverEntryError } from "@simplysm/sd-core-common";
|
|
2
|
+
import { SdCliBbFileMetadata } from "./SdCliBbFileMetadata";
|
|
3
|
+
import { SdCliBbArrayMetadata, SdCliBbVariableMetadata } from "./TSdCliBbTypeMetadata";
|
|
4
|
+
import { TSdCliBbMetadata } from "./SdCliBbRootMetadata";
|
|
5
|
+
|
|
6
|
+
export type TSdCliBbNgMetadata =
|
|
7
|
+
SdCliBbNgModuleMetadata
|
|
8
|
+
| SdCliBbNgInjectableMetadata
|
|
9
|
+
| SdCliBbNgDirectiveMetadata
|
|
10
|
+
| SdCliBbNgComponentMetadata
|
|
11
|
+
| SdCliBbNgPipeMetadata;
|
|
12
|
+
|
|
13
|
+
export class SdCliBbNgModuleMetadata {
|
|
14
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
15
|
+
private readonly _className: string) {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private _defCache?: ISdCliBbNgModuleDef;
|
|
19
|
+
|
|
20
|
+
public get def(): ISdCliBbNgModuleDef {
|
|
21
|
+
if (this._defCache) return this._defCache;
|
|
22
|
+
|
|
23
|
+
const result: ISdCliBbNgModuleDef = {
|
|
24
|
+
exports: [],
|
|
25
|
+
providers: []
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const argObjMeta = this._fileMeta.getNgDecoArg(this._className);
|
|
29
|
+
|
|
30
|
+
const expVal = argObjMeta.getPropValue("exports") ?? this._fileMeta.getNgDecoPropValue(this._className, "ɵmod", "exports");
|
|
31
|
+
if (expVal !== undefined) {
|
|
32
|
+
const expMetas = this._getExportAndProviderMetas(expVal);
|
|
33
|
+
result.exports.push(...expMetas);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const provVal = argObjMeta.getPropValue("providers") ?? this._fileMeta.getNgDecoPropValue(this._className, "ɵmod", "providers");
|
|
37
|
+
if (provVal !== undefined) {
|
|
38
|
+
const provMetas = this._getExportAndProviderMetas(provVal);
|
|
39
|
+
result.providers.push(...provMetas);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*for (const meta of this._fileMeta.rawMetas) {
|
|
43
|
+
if (
|
|
44
|
+
isExpressionStatement(meta) &&
|
|
45
|
+
isAssignmentExpression(meta.expression) &&
|
|
46
|
+
isMemberExpression(meta.expression.left) &&
|
|
47
|
+
isIdentifier(meta.expression.left.object) &&
|
|
48
|
+
meta.expression.left.object.name === this._className &&
|
|
49
|
+
isIdentifier(meta.expression.left.property)
|
|
50
|
+
) {
|
|
51
|
+
if (meta.expression.left.property.name === "ɵmod") {
|
|
52
|
+
if (
|
|
53
|
+
isCallExpression(meta.expression.right) &&
|
|
54
|
+
meta.expression.right.arguments.length > 0 &&
|
|
55
|
+
isObjectExpression(meta.expression.right.arguments[0])
|
|
56
|
+
) {
|
|
57
|
+
const expObjMeta = new SdCliBbObjectMetadata(this._fileMeta, meta.expression.right.arguments[0]);
|
|
58
|
+
const expVal = expObjMeta.getPropValue("exports");
|
|
59
|
+
if (expVal !== undefined) {
|
|
60
|
+
if (expVal instanceof SdCliBbArrayMetadata) {
|
|
61
|
+
for (const expMeta of expVal.value.filterExists()) {
|
|
62
|
+
result.exports.push(expMeta);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new NeverEntryError();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new NeverEntryError();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (meta.expression.left.property.name === "ɵinj") {
|
|
76
|
+
if (
|
|
77
|
+
isCallExpression(meta.expression.right) &&
|
|
78
|
+
meta.expression.right.arguments.length > 0 &&
|
|
79
|
+
isObjectExpression(meta.expression.right.arguments[0])
|
|
80
|
+
) {
|
|
81
|
+
const provObjMeta = new SdCliBbObjectMetadata(this._fileMeta, meta.expression.right.arguments[0]);
|
|
82
|
+
const provVal = provObjMeta.getPropValue("providers");
|
|
83
|
+
if (provVal !== undefined) {
|
|
84
|
+
const provMetas = this._getProviderMetas(provVal);
|
|
85
|
+
for (const provMeta of provMetas) {
|
|
86
|
+
result.providers.push(provMeta);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new NeverEntryError();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}*/
|
|
96
|
+
|
|
97
|
+
this._defCache = result;
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private _getExportAndProviderMetas(meta: TSdCliBbMetadata): TSdCliBbMetadata[] {
|
|
102
|
+
const result: TSdCliBbMetadata[] = [];
|
|
103
|
+
|
|
104
|
+
if (meta instanceof SdCliBbArrayMetadata) {
|
|
105
|
+
for (const metaItem of meta.value.filterExists()) {
|
|
106
|
+
result.push(...this._getExportAndProviderMetas(metaItem));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (meta instanceof SdCliBbVariableMetadata) {
|
|
110
|
+
if (meta.value !== undefined) {
|
|
111
|
+
result.push(...this._getExportAndProviderMetas(meta.value));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
result.push(meta);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export class SdCliBbNgInjectableMetadata {
|
|
123
|
+
|
|
124
|
+
public constructor(
|
|
125
|
+
// @ts-expect-error
|
|
126
|
+
private readonly _fileMeta: SdCliBbFileMetadata,
|
|
127
|
+
// @ts-expect-error
|
|
128
|
+
private readonly _className: string) {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export class SdCliBbNgDirectiveMetadata {
|
|
133
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
134
|
+
private readonly _className: string) {
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private _selectorCache?: string;
|
|
138
|
+
|
|
139
|
+
public get selector(): string {
|
|
140
|
+
if (this._selectorCache !== undefined) return this._selectorCache;
|
|
141
|
+
|
|
142
|
+
const argObjMeta = this._fileMeta.getNgDecoArg(this._className);
|
|
143
|
+
const val = argObjMeta.getPropValue("selector") ?? this._fileMeta.getNgDecoPropValue(this._className, "ɵdir", "selector");
|
|
144
|
+
if (typeof val === "string") {
|
|
145
|
+
this._selectorCache = val;
|
|
146
|
+
return this._selectorCache;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new NeverEntryError();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class SdCliBbNgComponentMetadata {
|
|
155
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
156
|
+
private readonly _className: string) {
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private _selectorCache?: string;
|
|
160
|
+
|
|
161
|
+
public get selector(): string {
|
|
162
|
+
if (this._selectorCache !== undefined) return this._selectorCache;
|
|
163
|
+
|
|
164
|
+
const argObjMeta = this._fileMeta.getNgDecoArg(this._className);
|
|
165
|
+
const val = argObjMeta.getPropValue("selector") ?? this._fileMeta.getNgDecoPropValue(this._className, "ɵcmp", "selector");
|
|
166
|
+
if (typeof val === "string") {
|
|
167
|
+
this._selectorCache = val;
|
|
168
|
+
return this._selectorCache;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new NeverEntryError();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class SdCliBbNgPipeMetadata {
|
|
177
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
178
|
+
private readonly _className: string) {
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private _pipeNameCache?: string;
|
|
182
|
+
|
|
183
|
+
public get pipeName(): string {
|
|
184
|
+
if (this._pipeNameCache !== undefined) return this._pipeNameCache;
|
|
185
|
+
|
|
186
|
+
const argObjMeta = this._fileMeta.getNgDecoArg(this._className);
|
|
187
|
+
const val = argObjMeta.getPropValue("name") ?? this._fileMeta.getNgDecoPropValue(this._className, "ɵpipe", "name");
|
|
188
|
+
if (typeof val === "string") {
|
|
189
|
+
this._pipeNameCache = val;
|
|
190
|
+
return val;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
throw new NeverEntryError();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface ISdCliBbNgModuleDef {
|
|
199
|
+
exports: TSdCliBbMetadata[];
|
|
200
|
+
providers: TSdCliBbMetadata[];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/*
|
|
204
|
+
class SdCliNgMetadataUtil {
|
|
205
|
+
public static getDecoPropValue(fileMeta: SdCliBbFileMetadata, className: string, decoName: string, propName: string): TSdCliBbMetadata | undefined {
|
|
206
|
+
for (const meta of fileMeta.rawMetas) {
|
|
207
|
+
if (
|
|
208
|
+
isExpressionStatement(meta) &&
|
|
209
|
+
isAssignmentExpression(meta.expression) &&
|
|
210
|
+
isMemberExpression(meta.expression.left) &&
|
|
211
|
+
isIdentifier(meta.expression.left.object) &&
|
|
212
|
+
meta.expression.left.object.name === className &&
|
|
213
|
+
isIdentifier(meta.expression.left.property)
|
|
214
|
+
) {
|
|
215
|
+
if (meta.expression.left.property.name === decoName) {
|
|
216
|
+
if (
|
|
217
|
+
isCallExpression(meta.expression.right) &&
|
|
218
|
+
meta.expression.right.arguments.length > 0 &&
|
|
219
|
+
isObjectExpression(meta.expression.right.arguments[0])
|
|
220
|
+
) {
|
|
221
|
+
const dirObjMeta = new SdCliBbObjectMetadata(fileMeta, meta.expression.right.arguments[0]);
|
|
222
|
+
return dirObjMeta.getPropValue(propName);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
throw new NeverEntryError();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
throw new NeverEntryError();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
*/
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrayExpression,
|
|
3
|
+
ClassDeclaration,
|
|
4
|
+
FunctionDeclaration,
|
|
5
|
+
isAssignmentExpression,
|
|
6
|
+
isExpressionStatement,
|
|
7
|
+
isIdentifier,
|
|
8
|
+
isMemberExpression,
|
|
9
|
+
isObjectProperty,
|
|
10
|
+
ObjectExpression,
|
|
11
|
+
VariableDeclarator
|
|
12
|
+
} from "@babel/types";
|
|
13
|
+
import { NeverEntryError } from "@simplysm/sd-core-common";
|
|
14
|
+
import { SdCliBbFileMetadata } from "./SdCliBbFileMetadata";
|
|
15
|
+
import {
|
|
16
|
+
SdCliBbNgComponentMetadata,
|
|
17
|
+
SdCliBbNgDirectiveMetadata,
|
|
18
|
+
SdCliBbNgInjectableMetadata,
|
|
19
|
+
SdCliBbNgModuleMetadata,
|
|
20
|
+
SdCliBbNgPipeMetadata,
|
|
21
|
+
TSdCliBbNgMetadata
|
|
22
|
+
} from "./TSdCliBbNgMetadata";
|
|
23
|
+
import { TSdCliBbMetadata } from "./SdCliBbRootMetadata";
|
|
24
|
+
|
|
25
|
+
export type TSdCliBbTypeMetadata = SdCliBbClassMetadata |
|
|
26
|
+
SdCliBbVariableMetadata |
|
|
27
|
+
SdCliBbFunctionMetadata |
|
|
28
|
+
SdCliBbObjectMetadata |
|
|
29
|
+
SdCliBbArrayMetadata;
|
|
30
|
+
|
|
31
|
+
export class SdCliBbClassMetadata {
|
|
32
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
33
|
+
private readonly _rawMeta: ClassDeclaration) {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public get filePath(): string {
|
|
37
|
+
return this._fileMeta.filePath;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public get name(): string {
|
|
41
|
+
return this._rawMeta.id.name;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private _ngDeclCache?: TSdCliBbNgMetadata | "none";
|
|
45
|
+
|
|
46
|
+
public get ngDecl(): TSdCliBbNgMetadata | undefined {
|
|
47
|
+
if (this._ngDeclCache !== undefined) {
|
|
48
|
+
return this._ngDeclCache === "none" ? undefined : this._ngDeclCache;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const meta of this._fileMeta.rawMetas) {
|
|
52
|
+
if (
|
|
53
|
+
isExpressionStatement(meta) &&
|
|
54
|
+
isAssignmentExpression(meta.expression) &&
|
|
55
|
+
isMemberExpression(meta.expression.left) &&
|
|
56
|
+
isIdentifier(meta.expression.left.object) &&
|
|
57
|
+
meta.expression.left.object.name === this._rawMeta.id.name &&
|
|
58
|
+
isIdentifier(meta.expression.left.property)
|
|
59
|
+
) {
|
|
60
|
+
if (meta.expression.left.property.name === "ɵmod") {
|
|
61
|
+
this._ngDeclCache = new SdCliBbNgModuleMetadata(this._fileMeta, this._rawMeta.id.name);
|
|
62
|
+
return this._ngDeclCache;
|
|
63
|
+
}
|
|
64
|
+
else if (meta.expression.left.property.name === "ɵprov") {
|
|
65
|
+
this._ngDeclCache = new SdCliBbNgInjectableMetadata(this._fileMeta, this._rawMeta.id.name);
|
|
66
|
+
return this._ngDeclCache;
|
|
67
|
+
}
|
|
68
|
+
else if (meta.expression.left.property.name === "ɵdir") {
|
|
69
|
+
this._ngDeclCache = new SdCliBbNgDirectiveMetadata(this._fileMeta, this._rawMeta.id.name);
|
|
70
|
+
return this._ngDeclCache;
|
|
71
|
+
}
|
|
72
|
+
else if (meta.expression.left.property.name === "ɵcmp") {
|
|
73
|
+
this._ngDeclCache = new SdCliBbNgComponentMetadata(this._fileMeta, this._rawMeta.id.name);
|
|
74
|
+
return this._ngDeclCache;
|
|
75
|
+
}
|
|
76
|
+
else if (meta.expression.left.property.name === "ɵpipe") {
|
|
77
|
+
this._ngDeclCache = new SdCliBbNgPipeMetadata(this._fileMeta, this._rawMeta.id.name);
|
|
78
|
+
return this._ngDeclCache;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this._ngDeclCache = "none";
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class SdCliBbVariableMetadata {
|
|
89
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
90
|
+
private readonly _rawMeta: VariableDeclarator) {
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public get filePath(): string {
|
|
94
|
+
return this._fileMeta.filePath;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public get name(): string {
|
|
98
|
+
if (!isIdentifier(this._rawMeta.id)) throw new NeverEntryError();
|
|
99
|
+
return this._rawMeta.id.name;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private _valueCache?: TSdCliBbMetadata;
|
|
103
|
+
|
|
104
|
+
public get value(): TSdCliBbMetadata | undefined {
|
|
105
|
+
if (this._valueCache === undefined) {
|
|
106
|
+
this._valueCache = this._rawMeta.init == null ? undefined : this._fileMeta.getMetaFromRaw(this._rawMeta.init);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this._valueCache;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class SdCliBbFunctionMetadata {
|
|
114
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
115
|
+
private readonly _rawMeta: FunctionDeclaration) {
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public get filePath(): string {
|
|
119
|
+
return this._fileMeta.filePath;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public get name(): string {
|
|
123
|
+
if (!isIdentifier(this._rawMeta.id)) throw new NeverEntryError();
|
|
124
|
+
return this._rawMeta.id.name;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export class SdCliBbObjectMetadata {
|
|
129
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
130
|
+
private readonly _metadata: ObjectExpression) {
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private readonly _getPropValueCache = new Map<string, TSdCliBbMetadata | undefined>();
|
|
134
|
+
|
|
135
|
+
public getPropValue(propName: string): TSdCliBbMetadata | undefined {
|
|
136
|
+
if (this._getPropValueCache.has(propName)) {
|
|
137
|
+
return this._getPropValueCache.get(propName);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const prop = this._metadata.properties
|
|
141
|
+
.single((item) => (
|
|
142
|
+
isObjectProperty(item) &&
|
|
143
|
+
isIdentifier(item.key) &&
|
|
144
|
+
item.key.name === propName
|
|
145
|
+
));
|
|
146
|
+
if (prop && !isObjectProperty(prop)) {
|
|
147
|
+
throw new NeverEntryError();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!prop) {
|
|
151
|
+
this._getPropValueCache.set(propName, undefined);
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const result = this._fileMeta.getMetaFromRaw(prop.value);
|
|
156
|
+
this._getPropValueCache.set(propName, result);
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export class SdCliBbArrayMetadata {
|
|
162
|
+
public constructor(private readonly _fileMeta: SdCliBbFileMetadata,
|
|
163
|
+
private readonly _metadata: ArrayExpression) {
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private _valueCache?: (TSdCliBbMetadata | undefined)[];
|
|
167
|
+
|
|
168
|
+
public get value(): (TSdCliBbMetadata | undefined)[] {
|
|
169
|
+
if (this._valueCache === undefined) {
|
|
170
|
+
this._valueCache = [];
|
|
171
|
+
for (const el of this._metadata.elements) {
|
|
172
|
+
this._valueCache.push(el ? this._fileMeta.getMetaFromRaw(el) : undefined);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return this._valueCache;
|
|
176
|
+
}
|
|
177
|
+
}
|