@nestia/sdk 2.4.7 → 2.5.0-dev.20240129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/generates/internal/E2eFileProgrammer.js +44 -46
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkDtoGenerator.js +2 -1
- package/lib/generates/internal/SdkDtoGenerator.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +16 -10
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +6 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +73 -323
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js +175 -0
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
- package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
- package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +7 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +98 -88
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/utils/FormatUtil.d.ts +6 -0
- package/lib/utils/FormatUtil.js +36 -0
- package/lib/utils/FormatUtil.js.map +1 -0
- package/lib/utils/ImportDictionary.d.ts +2 -0
- package/lib/utils/ImportDictionary.js +45 -0
- package/lib/utils/ImportDictionary.js.map +1 -1
- package/package.json +6 -3
- package/src/analyses/ConfigAnalyzer.ts +147 -147
- package/src/analyses/ControllerAnalyzer.ts +390 -390
- package/src/analyses/PathAnalyzer.ts +110 -110
- package/src/analyses/ReflectAnalyzer.ts +464 -464
- package/src/generates/SwaggerGenerator.ts +376 -376
- package/src/generates/internal/E2eFileProgrammer.ts +148 -73
- package/src/generates/internal/SdkDtoGenerator.ts +6 -1
- package/src/generates/internal/SdkFileProgrammer.ts +40 -13
- package/src/generates/internal/SdkFunctionProgrammer.ts +176 -475
- package/src/generates/internal/SdkNamespaceProgrammer.ts +495 -0
- package/src/generates/internal/SdkRouteProgrammer.ts +82 -0
- package/src/generates/internal/SdkSimulationProgrammer.ts +359 -133
- package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
- package/src/utils/FormatUtil.ts +30 -0
- package/src/utils/ImportDictionary.ts +72 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
1
2
|
export declare class ImportDictionary {
|
|
2
3
|
readonly file: string;
|
|
3
4
|
private readonly components_;
|
|
@@ -5,6 +6,7 @@ export declare class ImportDictionary {
|
|
|
5
6
|
empty(): boolean;
|
|
6
7
|
external(props: ImportDictionary.IExternalProps): string;
|
|
7
8
|
internal(props: ImportDictionary.IInternalProps): string;
|
|
9
|
+
toStatements(outDir: string): ts.Statement[];
|
|
8
10
|
toScript(outDir: string): string;
|
|
9
11
|
}
|
|
10
12
|
export declare namespace ImportDictionary {
|
|
@@ -8,6 +8,8 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const HashMap_1 = require("tstl/container/HashMap");
|
|
9
9
|
const HashSet_1 = require("tstl/container/HashSet");
|
|
10
10
|
const Pair_1 = require("tstl/utility/Pair");
|
|
11
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
12
|
+
const FormatUtil_1 = require("./FormatUtil");
|
|
11
13
|
class ImportDictionary {
|
|
12
14
|
constructor(file) {
|
|
13
15
|
this.file = file;
|
|
@@ -54,6 +56,49 @@ class ImportDictionary {
|
|
|
54
56
|
composition.elements.insert(props.instance);
|
|
55
57
|
return (_a = props.instance) !== null && _a !== void 0 ? _a : file;
|
|
56
58
|
}
|
|
59
|
+
toStatements(outDir) {
|
|
60
|
+
const external = [];
|
|
61
|
+
const internal = [];
|
|
62
|
+
const locator = (str) => {
|
|
63
|
+
const location = path_1.default.relative(outDir, str).split("\\").join("/");
|
|
64
|
+
const index = location.lastIndexOf(NODE_MODULES);
|
|
65
|
+
return index === -1
|
|
66
|
+
? location.startsWith("..")
|
|
67
|
+
? location
|
|
68
|
+
: `./${location}`
|
|
69
|
+
: location.substring(index + NODE_MODULES.length);
|
|
70
|
+
};
|
|
71
|
+
const enroll = (filter) => (container) => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const compositions = this.components_
|
|
74
|
+
.toJSON()
|
|
75
|
+
.filter((c) => filter(c.second.location))
|
|
76
|
+
.map((e) => (Object.assign(Object.assign({}, e.second), { location: locator(e.second.location) })))
|
|
77
|
+
.sort((a, b) => a.location.localeCompare(b.location));
|
|
78
|
+
for (const c of compositions) {
|
|
79
|
+
const brackets = [];
|
|
80
|
+
if (c.default)
|
|
81
|
+
brackets.push((_a = c.name) !== null && _a !== void 0 ? _a : c.location);
|
|
82
|
+
if (c.elements.empty() === false)
|
|
83
|
+
brackets.push(`{ ${c.elements
|
|
84
|
+
.toJSON()
|
|
85
|
+
.sort((a, b) => a.localeCompare(b))
|
|
86
|
+
.join(", ")} }`);
|
|
87
|
+
container.push(typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(c.type, c.default
|
|
88
|
+
? typescript_1.default.factory.createIdentifier((_b = c.name) !== null && _b !== void 0 ? _b : c.location)
|
|
89
|
+
: undefined, c.elements.empty() === false
|
|
90
|
+
? typescript_1.default.factory.createNamedImports([...c.elements].map((elem) => typescript_1.default.factory.createImportSpecifier(false, undefined, typescript_1.default.factory.createIdentifier(elem))))
|
|
91
|
+
: undefined), typescript_1.default.factory.createStringLiteral(c.location)));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
|
|
95
|
+
enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
|
|
96
|
+
return [
|
|
97
|
+
...external,
|
|
98
|
+
...(external.length && internal.length ? [FormatUtil_1.FormatUtil.enter()] : []),
|
|
99
|
+
...internal,
|
|
100
|
+
];
|
|
101
|
+
}
|
|
57
102
|
toScript(outDir) {
|
|
58
103
|
const external = [];
|
|
59
104
|
const internal = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportDictionary.js","sourceRoot":"","sources":["../../src/utils/ImportDictionary.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAAiD;AACjD,oDAAiD;AACjD,4CAAyC;
|
|
1
|
+
{"version":3,"file":"ImportDictionary.js","sourceRoot":"","sources":["../../src/utils/ImportDictionary.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAAiD;AACjD,oDAAiD;AACjD,4CAAyC;AACzC,4DAA4B;AAE5B,6CAA0C;AAE1C,MAAa,gBAAgB;IAI3B,YAAmC,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAH9B,gBAAW,GAC1B,IAAI,iBAAO,EAAE,CAAC;IAEkC,CAAC;IAE5C,KAAK;QACV,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAClC,CAAC;IAEM,QAAQ,CAAC,KAAsC;;QACpD,MAAM,WAAW,GAAiB,IAAI,CAAC,WAAW,CAAC,IAAI,CACrD,IAAI,WAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,EACnC,GAAG,EAAE,CAAC,CAAC;YACL,QAAQ,EAAE,gBAAgB,KAAK,CAAC,OAAO,EAAE;YACzC,QAAQ,EAAE,IAAI,iBAAO,EAAE;YACvB,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC,CACH,CAAC;QACF,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;YAAE,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;;YACnD,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACjD,OAAO,MAAA,K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AAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAE5D,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;CACF;AArKD,4CAqKC;AAuBD,MAAM,YAAY,GAAG,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-dev.20240129",
|
|
4
4
|
"description": "Nestia SDK and Swagger generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://nestia.io",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nestia/fetcher": "^2.
|
|
37
|
+
"@nestia/fetcher": "^2.5.0-dev.20240129",
|
|
38
38
|
"cli": "^1.0.1",
|
|
39
39
|
"get-function-location": "^2.0.0",
|
|
40
40
|
"glob": "^7.2.0",
|
|
@@ -46,9 +46,10 @@
|
|
|
46
46
|
"typia": "^5.4.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@nestia/fetcher": ">=2.
|
|
49
|
+
"@nestia/fetcher": ">=2.5.0-dev.20240129",
|
|
50
50
|
"@nestjs/common": ">=7.0.1",
|
|
51
51
|
"@nestjs/core": ">=7.0.1",
|
|
52
|
+
"prettier": ">=2.0.0",
|
|
52
53
|
"reflect-metadata": ">=0.1.12",
|
|
53
54
|
"ts-node": ">=10.6.0",
|
|
54
55
|
"typia": ">=5.4.1 <6.0.0"
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
"@nestia/e2e": "^0.3.7",
|
|
58
59
|
"@nestjs/common": ">= 7.0.1",
|
|
59
60
|
"@nestjs/core": ">= 7.0.1",
|
|
61
|
+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
60
62
|
"@types/cli": "^0.11.21",
|
|
61
63
|
"@types/express": "^4.17.15",
|
|
62
64
|
"@types/glob": "^7.2.0",
|
|
@@ -67,6 +69,7 @@
|
|
|
67
69
|
"@typescript-eslint/parser": "^5.46.1",
|
|
68
70
|
"eslint": "^8.29.0",
|
|
69
71
|
"eslint-plugin-deprecation": "^1.4.1",
|
|
72
|
+
"prettier": "^3.2.4",
|
|
70
73
|
"rimraf": "^3.0.2",
|
|
71
74
|
"ts-node": "^10.9.1",
|
|
72
75
|
"ts-patch": "v3.0.2",
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { INestApplication, VersioningType } from "@nestjs/common";
|
|
2
|
-
import { MODULE_PATH } from "@nestjs/common/constants";
|
|
3
|
-
import { NestContainer } from "@nestjs/core";
|
|
4
|
-
import { Module } from "@nestjs/core/injector/module";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { HashMap, Pair, Singleton } from "tstl";
|
|
8
|
-
|
|
9
|
-
import { INestiaConfig } from "../INestiaConfig";
|
|
10
|
-
import { SdkGenerator } from "../generates/SdkGenerator";
|
|
11
|
-
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
12
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
-
import { MapUtil } from "../utils/MapUtil";
|
|
14
|
-
import { SourceFinder } from "../utils/SourceFinder";
|
|
15
|
-
|
|
16
|
-
export namespace ConfigAnalyzer {
|
|
17
|
-
export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
|
|
18
|
-
MapUtil.take(memory, config, async () => {
|
|
19
|
-
const input = config.input;
|
|
20
|
-
if (Array.isArray(input)) return transform_input(config)(input);
|
|
21
|
-
else if (typeof input === "function")
|
|
22
|
-
return analyze_application(await input());
|
|
23
|
-
else if (typeof input === "object")
|
|
24
|
-
if (input === null)
|
|
25
|
-
throw new Error("Invalid input config. It can't be null.");
|
|
26
|
-
else return transform_input(config)(input.include, input.exclude);
|
|
27
|
-
else if (typeof input === "string")
|
|
28
|
-
return transform_input(config)([input]);
|
|
29
|
-
else throw new Error("Invalid input config.");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const analyze_application = async (
|
|
33
|
-
app: INestApplication,
|
|
34
|
-
): Promise<INormalizedInput> => {
|
|
35
|
-
const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
|
|
36
|
-
const container: NestContainer = (app as any).container as NestContainer;
|
|
37
|
-
const modules: Module[] = [...container.getModules().values()].filter(
|
|
38
|
-
(m) => !!m.controllers.size,
|
|
39
|
-
);
|
|
40
|
-
for (const m of modules) {
|
|
41
|
-
const path: string =
|
|
42
|
-
Reflect.getMetadata(
|
|
43
|
-
MODULE_PATH + container.getModules().applicationId,
|
|
44
|
-
m.metatype,
|
|
45
|
-
) ??
|
|
46
|
-
Reflect.getMetadata(MODULE_PATH, m.metatype) ??
|
|
47
|
-
"";
|
|
48
|
-
for (const controller of [...m.controllers.keys()]) {
|
|
49
|
-
const file: string | null =
|
|
50
|
-
(await require("get-function-location")(controller))?.source ?? null;
|
|
51
|
-
if (file === null) continue;
|
|
52
|
-
|
|
53
|
-
const location: string = normalize_file(file);
|
|
54
|
-
if (location.length === 0) continue;
|
|
55
|
-
|
|
56
|
-
const key: Pair<Function, string> = new Pair(
|
|
57
|
-
controller as Function,
|
|
58
|
-
location,
|
|
59
|
-
);
|
|
60
|
-
files.take(key, () => new Set([])).add(path);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const versioning = (app as any).config?.versioningOptions;
|
|
65
|
-
return {
|
|
66
|
-
include: files.toJSON().map((pair) => ({
|
|
67
|
-
controller: pair.first.first,
|
|
68
|
-
file: decodeURIComponent(pair.first.second),
|
|
69
|
-
paths: [...pair.second.values()],
|
|
70
|
-
})),
|
|
71
|
-
globalPrefix:
|
|
72
|
-
typeof (app as any).config?.globalPrefix === "string"
|
|
73
|
-
? {
|
|
74
|
-
prefix: (app as any).config.globalPrefix,
|
|
75
|
-
exclude: (app as any).config.globalPrefixOptions?.exclude ?? {},
|
|
76
|
-
}
|
|
77
|
-
: undefined,
|
|
78
|
-
versioning:
|
|
79
|
-
versioning === undefined || versioning.type !== VersioningType.URI
|
|
80
|
-
? undefined
|
|
81
|
-
: {
|
|
82
|
-
prefix:
|
|
83
|
-
versioning.prefix === undefined || versioning.prefix === false
|
|
84
|
-
? "v"
|
|
85
|
-
: versioning.prefix,
|
|
86
|
-
defaultVersion: versioning.defaultVersion,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const normalize_file = (str: string) =>
|
|
92
|
-
str.substring(
|
|
93
|
-
str.startsWith("file:///")
|
|
94
|
-
? process.cwd()[0] === "/"
|
|
95
|
-
? 7
|
|
96
|
-
: 8
|
|
97
|
-
: str.startsWith("file://")
|
|
98
|
-
? 7
|
|
99
|
-
: 0,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const transform_input =
|
|
103
|
-
(config: INestiaConfig) =>
|
|
104
|
-
async (include: string[], exclude?: string[]) => ({
|
|
105
|
-
include: (
|
|
106
|
-
await SourceFinder.find({
|
|
107
|
-
include,
|
|
108
|
-
exclude,
|
|
109
|
-
filter: filter(config),
|
|
110
|
-
})
|
|
111
|
-
).map((file) => ({
|
|
112
|
-
paths: [""],
|
|
113
|
-
file,
|
|
114
|
-
})),
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const filter =
|
|
118
|
-
(config: INestiaConfig) =>
|
|
119
|
-
async (location: string): Promise<boolean> =>
|
|
120
|
-
location.endsWith(".ts") &&
|
|
121
|
-
!location.endsWith(".d.ts") &&
|
|
122
|
-
(config.output === undefined ||
|
|
123
|
-
(location.indexOf(path.join(config.output, "functional")) === -1 &&
|
|
124
|
-
(await (
|
|
125
|
-
await bundler.get(config.output)
|
|
126
|
-
)(location))) === false);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
|
|
130
|
-
const bundler = new Singleton(async (output: string) => {
|
|
131
|
-
const assets: string[] = await fs.promises.readdir(SdkGenerator.BUNDLE_PATH);
|
|
132
|
-
const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
|
|
133
|
-
assets,
|
|
134
|
-
async (file) => {
|
|
135
|
-
const relative: string = path.join(output, file);
|
|
136
|
-
const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
|
|
137
|
-
const stats: fs.Stats = await fs.promises.stat(location);
|
|
138
|
-
return new Pair(relative, stats.isDirectory());
|
|
139
|
-
},
|
|
140
|
-
);
|
|
141
|
-
return async (file: string): Promise<boolean> => {
|
|
142
|
-
for (const it of tuples)
|
|
143
|
-
if (it.second === false && file === it.first) return true;
|
|
144
|
-
else if (it.second === true && file.indexOf(it.first) === 0) return true;
|
|
145
|
-
return false;
|
|
146
|
-
};
|
|
147
|
-
});
|
|
1
|
+
import { INestApplication, VersioningType } from "@nestjs/common";
|
|
2
|
+
import { MODULE_PATH } from "@nestjs/common/constants";
|
|
3
|
+
import { NestContainer } from "@nestjs/core";
|
|
4
|
+
import { Module } from "@nestjs/core/injector/module";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { HashMap, Pair, Singleton } from "tstl";
|
|
8
|
+
|
|
9
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
10
|
+
import { SdkGenerator } from "../generates/SdkGenerator";
|
|
11
|
+
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
12
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
+
import { MapUtil } from "../utils/MapUtil";
|
|
14
|
+
import { SourceFinder } from "../utils/SourceFinder";
|
|
15
|
+
|
|
16
|
+
export namespace ConfigAnalyzer {
|
|
17
|
+
export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
|
|
18
|
+
MapUtil.take(memory, config, async () => {
|
|
19
|
+
const input = config.input;
|
|
20
|
+
if (Array.isArray(input)) return transform_input(config)(input);
|
|
21
|
+
else if (typeof input === "function")
|
|
22
|
+
return analyze_application(await input());
|
|
23
|
+
else if (typeof input === "object")
|
|
24
|
+
if (input === null)
|
|
25
|
+
throw new Error("Invalid input config. It can't be null.");
|
|
26
|
+
else return transform_input(config)(input.include, input.exclude);
|
|
27
|
+
else if (typeof input === "string")
|
|
28
|
+
return transform_input(config)([input]);
|
|
29
|
+
else throw new Error("Invalid input config.");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const analyze_application = async (
|
|
33
|
+
app: INestApplication,
|
|
34
|
+
): Promise<INormalizedInput> => {
|
|
35
|
+
const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
|
|
36
|
+
const container: NestContainer = (app as any).container as NestContainer;
|
|
37
|
+
const modules: Module[] = [...container.getModules().values()].filter(
|
|
38
|
+
(m) => !!m.controllers.size,
|
|
39
|
+
);
|
|
40
|
+
for (const m of modules) {
|
|
41
|
+
const path: string =
|
|
42
|
+
Reflect.getMetadata(
|
|
43
|
+
MODULE_PATH + container.getModules().applicationId,
|
|
44
|
+
m.metatype,
|
|
45
|
+
) ??
|
|
46
|
+
Reflect.getMetadata(MODULE_PATH, m.metatype) ??
|
|
47
|
+
"";
|
|
48
|
+
for (const controller of [...m.controllers.keys()]) {
|
|
49
|
+
const file: string | null =
|
|
50
|
+
(await require("get-function-location")(controller))?.source ?? null;
|
|
51
|
+
if (file === null) continue;
|
|
52
|
+
|
|
53
|
+
const location: string = normalize_file(file);
|
|
54
|
+
if (location.length === 0) continue;
|
|
55
|
+
|
|
56
|
+
const key: Pair<Function, string> = new Pair(
|
|
57
|
+
controller as Function,
|
|
58
|
+
location,
|
|
59
|
+
);
|
|
60
|
+
files.take(key, () => new Set([])).add(path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const versioning = (app as any).config?.versioningOptions;
|
|
65
|
+
return {
|
|
66
|
+
include: files.toJSON().map((pair) => ({
|
|
67
|
+
controller: pair.first.first,
|
|
68
|
+
file: decodeURIComponent(pair.first.second),
|
|
69
|
+
paths: [...pair.second.values()],
|
|
70
|
+
})),
|
|
71
|
+
globalPrefix:
|
|
72
|
+
typeof (app as any).config?.globalPrefix === "string"
|
|
73
|
+
? {
|
|
74
|
+
prefix: (app as any).config.globalPrefix,
|
|
75
|
+
exclude: (app as any).config.globalPrefixOptions?.exclude ?? {},
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
versioning:
|
|
79
|
+
versioning === undefined || versioning.type !== VersioningType.URI
|
|
80
|
+
? undefined
|
|
81
|
+
: {
|
|
82
|
+
prefix:
|
|
83
|
+
versioning.prefix === undefined || versioning.prefix === false
|
|
84
|
+
? "v"
|
|
85
|
+
: versioning.prefix,
|
|
86
|
+
defaultVersion: versioning.defaultVersion,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const normalize_file = (str: string) =>
|
|
92
|
+
str.substring(
|
|
93
|
+
str.startsWith("file:///")
|
|
94
|
+
? process.cwd()[0] === "/"
|
|
95
|
+
? 7
|
|
96
|
+
: 8
|
|
97
|
+
: str.startsWith("file://")
|
|
98
|
+
? 7
|
|
99
|
+
: 0,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const transform_input =
|
|
103
|
+
(config: INestiaConfig) =>
|
|
104
|
+
async (include: string[], exclude?: string[]) => ({
|
|
105
|
+
include: (
|
|
106
|
+
await SourceFinder.find({
|
|
107
|
+
include,
|
|
108
|
+
exclude,
|
|
109
|
+
filter: filter(config),
|
|
110
|
+
})
|
|
111
|
+
).map((file) => ({
|
|
112
|
+
paths: [""],
|
|
113
|
+
file,
|
|
114
|
+
})),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const filter =
|
|
118
|
+
(config: INestiaConfig) =>
|
|
119
|
+
async (location: string): Promise<boolean> =>
|
|
120
|
+
location.endsWith(".ts") &&
|
|
121
|
+
!location.endsWith(".d.ts") &&
|
|
122
|
+
(config.output === undefined ||
|
|
123
|
+
(location.indexOf(path.join(config.output, "functional")) === -1 &&
|
|
124
|
+
(await (
|
|
125
|
+
await bundler.get(config.output)
|
|
126
|
+
)(location))) === false);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
|
|
130
|
+
const bundler = new Singleton(async (output: string) => {
|
|
131
|
+
const assets: string[] = await fs.promises.readdir(SdkGenerator.BUNDLE_PATH);
|
|
132
|
+
const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
|
|
133
|
+
assets,
|
|
134
|
+
async (file) => {
|
|
135
|
+
const relative: string = path.join(output, file);
|
|
136
|
+
const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
|
|
137
|
+
const stats: fs.Stats = await fs.promises.stat(location);
|
|
138
|
+
return new Pair(relative, stats.isDirectory());
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
return async (file: string): Promise<boolean> => {
|
|
142
|
+
for (const it of tuples)
|
|
143
|
+
if (it.second === false && file === it.first) return true;
|
|
144
|
+
else if (it.second === true && file.indexOf(it.first) === 0) return true;
|
|
145
|
+
return false;
|
|
146
|
+
};
|
|
147
|
+
});
|