@nestia/sdk 2.5.0-dev.20240130 → 2.5.0-dev.20240130-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,135 +1,135 @@
1
- import fs from "fs";
2
- import ts from "typescript";
3
-
4
- import { INestiaConfig } from "../../INestiaConfig";
5
- import { IRoute } from "../../structures/IRoute";
6
- import { FormatUtil } from "../../utils/FormatUtil";
7
- import { ImportDictionary } from "../../utils/ImportDictionary";
8
- import { MapUtil } from "../../utils/MapUtil";
9
- import { SdkRouteDirectory } from "./SdkRouteDirectory";
10
- import { SdkRouteProgrammer } from "./SdkRouteProgrammer";
11
-
12
- export namespace SdkFileProgrammer {
13
- /* ---------------------------------------------------------
14
- CONSTRUCTOR
15
- --------------------------------------------------------- */
16
- export const generate =
17
- (checker: ts.TypeChecker) =>
18
- (config: INestiaConfig) =>
19
- async (routeList: IRoute[]): Promise<void> => {
20
- // CONSTRUCT FOLDER TREE
21
- const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
22
- for (const route of routeList) emplace(root)(route);
23
-
24
- // ITERATE FILES
25
- await iterate(checker)(config)(root)(config.output + "/functional");
26
- };
27
-
28
- const emplace =
29
- (directory: SdkRouteDirectory) =>
30
- (route: IRoute): void => {
31
- // OPEN DIRECTORIES
32
- for (const key of route.accessors.slice(0, -1)) {
33
- directory = MapUtil.take(
34
- directory.children,
35
- key,
36
- () => new SdkRouteDirectory(directory, key),
37
- );
38
- }
39
-
40
- // ADD ROUTE
41
- directory.routes.push(route);
42
- };
43
-
44
- /* ---------------------------------------------------------
45
- FILE ITERATOR
46
- --------------------------------------------------------- */
47
- const iterate =
48
- (checker: ts.TypeChecker) =>
49
- (config: INestiaConfig) =>
50
- (directory: SdkRouteDirectory) =>
51
- async (outDir: string): Promise<void> => {
52
- // CREATE A NEW DIRECTORY
53
- try {
54
- await fs.promises.mkdir(outDir);
55
- } catch {}
56
-
57
- // ITERATE CHILDREN
58
- const statements: ts.Statement[] = [];
59
- for (const [key, value] of directory.children) {
60
- await iterate(checker)(config)(value)(`${outDir}/${key}`);
61
- statements.push(
62
- ts.factory.createExportDeclaration(
63
- undefined,
64
- false,
65
- ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
66
- ts.factory.createStringLiteral(`./${key}`),
67
- undefined,
68
- ),
69
- );
70
- }
71
- if (statements.length && directory.routes.length)
72
- statements.push(FormatUtil.enter());
73
-
74
- // ITERATE ROUTES
75
- const importer: ImportDictionary = new ImportDictionary(
76
- `${outDir}/index.ts`,
77
- );
78
- if (
79
- config.simulate === true &&
80
- directory.routes.some((r) => !!r.parameters.length)
81
- )
82
- importer.internal({
83
- file: `${config.output}/utils/NestiaSimulator.ts`,
84
- instance: "NestiaSimulator",
85
- type: false,
86
- });
87
- directory.routes.forEach((route, i) => {
88
- if (config.clone !== true)
89
- for (const tuple of route.imports)
90
- for (const instance of tuple[1])
91
- importer.internal({
92
- file: tuple[0],
93
- instance,
94
- type: true,
95
- });
96
- statements.push(
97
- ...SdkRouteProgrammer.generate(checker)(config)(importer)(route),
98
- );
99
- if (i !== directory.routes.length - 1)
100
- statements.push(FormatUtil.enter());
101
- });
102
-
103
- // FINALIZE THE CONTENT
104
- if (directory.routes.length !== 0)
105
- statements.push(
106
- ...importer.toStatements(outDir),
107
- ...(!importer.empty() && statements.length
108
- ? [FormatUtil.enter()]
109
- : []),
110
- ...statements.splice(0, statements.length),
111
- );
112
-
113
- const script: string =
114
- "/**\n" +
115
- " * @packageDocumentation\n" +
116
- ` * @module ${directory.module}\n` +
117
- " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
118
- " */\n" +
119
- "//================================================================\n" +
120
- ts
121
- .createPrinter()
122
- .printFile(
123
- ts.factory.createSourceFile(
124
- statements,
125
- ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
126
- ts.NodeFlags.None,
127
- ),
128
- );
129
- await fs.promises.writeFile(
130
- importer.file,
131
- await FormatUtil.beautify(script),
132
- "utf8",
133
- );
134
- };
135
- }
1
+ import fs from "fs";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaConfig } from "../../INestiaConfig";
5
+ import { IRoute } from "../../structures/IRoute";
6
+ import { FormatUtil } from "../../utils/FormatUtil";
7
+ import { ImportDictionary } from "../../utils/ImportDictionary";
8
+ import { MapUtil } from "../../utils/MapUtil";
9
+ import { SdkRouteDirectory } from "./SdkRouteDirectory";
10
+ import { SdkRouteProgrammer } from "./SdkRouteProgrammer";
11
+
12
+ export namespace SdkFileProgrammer {
13
+ /* ---------------------------------------------------------
14
+ CONSTRUCTOR
15
+ --------------------------------------------------------- */
16
+ export const generate =
17
+ (checker: ts.TypeChecker) =>
18
+ (config: INestiaConfig) =>
19
+ async (routeList: IRoute[]): Promise<void> => {
20
+ // CONSTRUCT FOLDER TREE
21
+ const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
22
+ for (const route of routeList) emplace(root)(route);
23
+
24
+ // ITERATE FILES
25
+ await iterate(checker)(config)(root)(config.output + "/functional");
26
+ };
27
+
28
+ const emplace =
29
+ (directory: SdkRouteDirectory) =>
30
+ (route: IRoute): void => {
31
+ // OPEN DIRECTORIES
32
+ for (const key of route.accessors.slice(0, -1)) {
33
+ directory = MapUtil.take(
34
+ directory.children,
35
+ key,
36
+ () => new SdkRouteDirectory(directory, key),
37
+ );
38
+ }
39
+
40
+ // ADD ROUTE
41
+ directory.routes.push(route);
42
+ };
43
+
44
+ /* ---------------------------------------------------------
45
+ FILE ITERATOR
46
+ --------------------------------------------------------- */
47
+ const iterate =
48
+ (checker: ts.TypeChecker) =>
49
+ (config: INestiaConfig) =>
50
+ (directory: SdkRouteDirectory) =>
51
+ async (outDir: string): Promise<void> => {
52
+ // CREATE A NEW DIRECTORY
53
+ try {
54
+ await fs.promises.mkdir(outDir);
55
+ } catch {}
56
+
57
+ // ITERATE CHILDREN
58
+ const statements: ts.Statement[] = [];
59
+ for (const [key, value] of directory.children) {
60
+ await iterate(checker)(config)(value)(`${outDir}/${key}`);
61
+ statements.push(
62
+ ts.factory.createExportDeclaration(
63
+ undefined,
64
+ false,
65
+ ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
66
+ ts.factory.createStringLiteral(`./${key}`),
67
+ undefined,
68
+ ),
69
+ );
70
+ }
71
+ if (statements.length && directory.routes.length)
72
+ statements.push(FormatUtil.enter());
73
+
74
+ // ITERATE ROUTES
75
+ const importer: ImportDictionary = new ImportDictionary(
76
+ `${outDir}/index.ts`,
77
+ );
78
+ if (
79
+ config.simulate === true &&
80
+ directory.routes.some((r) => !!r.parameters.length)
81
+ )
82
+ importer.internal({
83
+ file: `${config.output}/utils/NestiaSimulator.ts`,
84
+ instance: "NestiaSimulator",
85
+ type: false,
86
+ });
87
+ directory.routes.forEach((route, i) => {
88
+ if (config.clone !== true)
89
+ for (const tuple of route.imports)
90
+ for (const instance of tuple[1])
91
+ importer.internal({
92
+ file: tuple[0],
93
+ instance,
94
+ type: true,
95
+ });
96
+ statements.push(
97
+ ...SdkRouteProgrammer.generate(checker)(config)(importer)(route),
98
+ );
99
+ if (i !== directory.routes.length - 1)
100
+ statements.push(FormatUtil.enter());
101
+ });
102
+
103
+ // FINALIZE THE CONTENT
104
+ if (directory.routes.length !== 0)
105
+ statements.push(
106
+ ...importer.toStatements(outDir),
107
+ ...(!importer.empty() && statements.length
108
+ ? [FormatUtil.enter()]
109
+ : []),
110
+ ...statements.splice(0, statements.length),
111
+ );
112
+
113
+ const script: string =
114
+ "/**\n" +
115
+ " * @packageDocumentation\n" +
116
+ ` * @module ${directory.module}\n` +
117
+ " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
118
+ " */\n" +
119
+ "//================================================================\n" +
120
+ ts
121
+ .createPrinter()
122
+ .printFile(
123
+ ts.factory.createSourceFile(
124
+ statements,
125
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
126
+ ts.NodeFlags.None,
127
+ ),
128
+ );
129
+ await fs.promises.writeFile(
130
+ importer.file,
131
+ await FormatUtil.beautify(script),
132
+ "utf8",
133
+ );
134
+ };
135
+ }