@nestia/sdk 6.0.6 → 7.0.0-dev.20250605

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.
Files changed (137) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +92 -92
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/INestiaConfig.d.ts +66 -69
  15. package/lib/executable/internal/NestiaConfigLoader.js +10 -5
  16. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  17. package/lib/executable/sdk.js +12 -12
  18. package/lib/generates/internal/E2eFileProgrammer.js +30 -14
  19. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  20. package/lib/generates/internal/ImportDictionary.js +13 -4
  21. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  22. package/lib/generates/internal/SdkAliasCollection.d.ts +3 -2
  23. package/lib/generates/internal/SdkAliasCollection.js +8 -3
  24. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  25. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +1 -1
  26. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +47 -35
  27. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  28. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +1 -1
  29. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +50 -37
  30. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  31. package/lib/generates/internal/SdkHttpRouteProgrammer.js +5 -4
  32. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  33. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +1 -1
  34. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +28 -16
  35. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  36. package/lib/generates/internal/SdkTypeProgrammer.js +3 -3
  37. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  38. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +1 -1
  39. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  40. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +1 -1
  41. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  42. package/lib/utils/ArrayUtil.d.ts +2 -2
  43. package/lib/utils/ArrayUtil.js.map +1 -1
  44. package/package.json +6 -6
  45. package/src/INestiaConfig.ts +269 -271
  46. package/src/NestiaSdkApplication.ts +307 -307
  47. package/src/NestiaSwaggerComposer.ts +138 -138
  48. package/src/analyses/AccessorAnalyzer.ts +67 -67
  49. package/src/analyses/ConfigAnalyzer.ts +155 -155
  50. package/src/analyses/ExceptionAnalyzer.ts +154 -154
  51. package/src/analyses/GenericAnalyzer.ts +49 -49
  52. package/src/analyses/ImportAnalyzer.ts +171 -171
  53. package/src/analyses/PathAnalyzer.ts +69 -69
  54. package/src/analyses/ReflectControllerAnalyzer.ts +105 -105
  55. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  56. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -71
  57. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +348 -348
  58. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +127 -127
  59. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  60. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +172 -172
  61. package/src/analyses/SecurityAnalyzer.ts +25 -25
  62. package/src/analyses/TypedHttpRouteAnalyzer.ts +186 -186
  63. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -18
  64. package/src/decorators/OperationMetadata.ts +15 -15
  65. package/src/executable/internal/CommandParser.ts +15 -15
  66. package/src/executable/internal/NestiaConfigLoader.ts +78 -78
  67. package/src/executable/internal/NestiaSdkCommand.ts +103 -103
  68. package/src/executable/sdk.ts +75 -75
  69. package/src/generates/CloneGenerator.ts +66 -66
  70. package/src/generates/E2eGenerator.ts +32 -32
  71. package/src/generates/SdkGenerator.ts +159 -159
  72. package/src/generates/SwaggerGenerator.ts +292 -292
  73. package/src/generates/internal/E2eFileProgrammer.ts +214 -183
  74. package/src/generates/internal/FilePrinter.ts +53 -53
  75. package/src/generates/internal/ImportDictionary.ts +159 -147
  76. package/src/generates/internal/SdkAliasCollection.ts +204 -185
  77. package/src/generates/internal/SdkDistributionComposer.ts +103 -103
  78. package/src/generates/internal/SdkFileProgrammer.ts +116 -116
  79. package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
  80. package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -71
  81. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +325 -301
  82. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +563 -529
  83. package/src/generates/internal/SdkHttpRouteProgrammer.ts +119 -117
  84. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +386 -362
  85. package/src/generates/internal/SdkImportWizard.ts +55 -55
  86. package/src/generates/internal/SdkRouteDirectory.ts +18 -18
  87. package/src/generates/internal/SdkTypeProgrammer.ts +377 -377
  88. package/src/generates/internal/SdkTypeTagProgrammer.ts +102 -102
  89. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +362 -362
  90. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +265 -265
  91. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  92. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  93. package/src/generates/internal/SwaggerOperationParameterComposer.ts +177 -177
  94. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  95. package/src/index.ts +4 -4
  96. package/src/module.ts +3 -3
  97. package/src/structures/INestiaProject.ts +13 -13
  98. package/src/structures/INestiaSdkInput.ts +20 -20
  99. package/src/structures/IReflectApplication.ts +8 -8
  100. package/src/structures/IReflectController.ts +15 -15
  101. package/src/structures/IReflectHttpOperation.ts +26 -26
  102. package/src/structures/IReflectHttpOperationException.ts +19 -19
  103. package/src/structures/IReflectHttpOperationParameter.ts +81 -81
  104. package/src/structures/IReflectHttpOperationSuccess.ts +22 -22
  105. package/src/structures/IReflectOperationError.ts +26 -26
  106. package/src/structures/IReflectType.ts +4 -4
  107. package/src/structures/IReflectTypeImport.ts +4 -4
  108. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  109. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -38
  110. package/src/structures/ITypedApplication.ts +11 -11
  111. package/src/structures/ITypedHttpRoute.ts +30 -30
  112. package/src/structures/ITypedHttpRouteException.ts +15 -15
  113. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  114. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  115. package/src/structures/ITypedWebSocketRoute.ts +20 -20
  116. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  117. package/src/structures/MethodType.ts +5 -5
  118. package/src/structures/ParamCategory.ts +1 -1
  119. package/src/structures/TypeEntry.ts +22 -22
  120. package/src/transform.ts +9 -9
  121. package/src/transformers/IOperationMetadata.ts +44 -44
  122. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  123. package/src/transformers/SdkOperationProgrammer.ts +209 -209
  124. package/src/transformers/SdkOperationTransformer.ts +253 -253
  125. package/src/transformers/TextPlainValidator.ts +17 -17
  126. package/src/typings/get-function-location.d.ts +7 -7
  127. package/src/utils/ArrayUtil.ts +26 -26
  128. package/src/utils/FileRetriever.ts +22 -22
  129. package/src/utils/MapUtil.ts +14 -14
  130. package/src/utils/MetadataUtil.ts +26 -26
  131. package/src/utils/PathUtil.ts +10 -10
  132. package/src/utils/SourceFinder.ts +66 -66
  133. package/src/utils/StringUtil.ts +17 -17
  134. package/src/utils/StripEnums.ts +5 -5
  135. package/src/utils/VersioningStrategy.ts +28 -28
  136. package/src/validators/HttpHeadersValidator.ts +34 -34
  137. package/src/validators/HttpQueryValidator.ts +34 -34
@@ -1,185 +1,204 @@
1
- import ts from "typescript";
2
- import typia from "typia";
3
- import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
5
-
6
- import { INestiaProject } from "../../structures/INestiaProject";
7
- import { IReflectHttpOperationParameter } from "../../structures/IReflectHttpOperationParameter";
8
- import { IReflectType } from "../../structures/IReflectType";
9
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
10
- import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
11
- import { ImportDictionary } from "./ImportDictionary";
12
- import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
13
-
14
- export namespace SdkAliasCollection {
15
- export const name = ({ type }: { type: IReflectType }): ts.TypeNode =>
16
- ts.factory.createTypeReferenceNode(
17
- type.name,
18
- type.typeArguments
19
- ? type.typeArguments.map((a) => name({ type: a }))
20
- : undefined,
21
- );
22
-
23
- export const from =
24
- (project: INestiaProject) =>
25
- (importer: ImportDictionary) =>
26
- (metadata: Metadata) =>
27
- SdkTypeProgrammer.write(project)(importer)(metadata);
28
-
29
- export const headers =
30
- (project: INestiaProject) =>
31
- (importer: ImportDictionary) =>
32
- (param: ITypedHttpRouteParameter.IHeaders): ts.TypeNode => {
33
- if (project.config.clone === true)
34
- return from(project)(importer)(param.metadata);
35
- const type: ts.TypeNode = name(param);
36
- if (project.config.primitive === false) return type;
37
- return ts.factory.createTypeReferenceNode(
38
- importer.external({
39
- type: true,
40
- library: "typia",
41
- instance: "Resolved",
42
- }),
43
- [type],
44
- );
45
- };
46
-
47
- export const query =
48
- (project: INestiaProject) =>
49
- (importer: ImportDictionary) =>
50
- (param: ITypedHttpRouteParameter.IQuery): ts.TypeNode => {
51
- if (project.config.clone === true)
52
- return from(project)(importer)(param.metadata);
53
- const type: ts.TypeNode = name(param);
54
- if (project.config.primitive === false) return type;
55
- return ts.factory.createTypeReferenceNode(
56
- importer.external({
57
- type: true,
58
- library: "typia",
59
- instance: "Resolved",
60
- }),
61
- [type],
62
- );
63
- };
64
-
65
- export const input =
66
- (project: INestiaProject) =>
67
- (importer: ImportDictionary) =>
68
- (param: ITypedHttpRouteParameter.IBody): ts.TypeNode => {
69
- if (project.config.clone === true) {
70
- const type: ts.TypeNode = from(project)(importer)(param.metadata);
71
- return param.contentType === "multipart/form-data"
72
- ? formDataInput(importer)(type)
73
- : type;
74
- }
75
- const type: ts.TypeNode = name(param);
76
- if (param.contentType === "multipart/form-data")
77
- return formDataInput(importer)(type);
78
- else if (project.config.primitive === false) return type;
79
- return ts.factory.createTypeReferenceNode(
80
- importer.external({
81
- type: true,
82
- library: "typia",
83
- instance:
84
- typia.is<IReflectHttpOperationParameter.IBody>(param) &&
85
- (param.contentType === "application/json" ||
86
- param.encrypted === true)
87
- ? "Primitive"
88
- : "Resolved",
89
- }),
90
- [type],
91
- );
92
- };
93
-
94
- export const output =
95
- (project: INestiaProject) =>
96
- (importer: ImportDictionary) =>
97
- (route: ITypedHttpRoute): ts.TypeNode => {
98
- const schema = (p: { metadata: Metadata; type: IReflectType }) =>
99
- p.metadata.size() === 0
100
- ? TypeFactory.keyword("void")
101
- : project.config.clone === true
102
- ? from(project)(importer)(p.metadata)
103
- : project.config.primitive !== false
104
- ? ts.factory.createTypeReferenceNode(
105
- importer.external({
106
- type: true,
107
- library: "typia",
108
- instance:
109
- route.success.contentType === "application/json" ||
110
- route.success.encrypted === true
111
- ? "Primitive"
112
- : "Resolved",
113
- }),
114
- [name(p)],
115
- )
116
- : name(p);
117
- if (project.config.propagate !== true) return schema(route.success);
118
-
119
- const branches: IBranch[] = [
120
- {
121
- status: String(
122
- route.success.status ?? (route.method === "POST" ? 201 : 200),
123
- ),
124
- type: schema(route.success),
125
- },
126
- ...Object.entries(route.exceptions).map(([status, value]) => ({
127
- status,
128
- type: schema(value),
129
- })),
130
- ];
131
- return ts.factory.createTypeReferenceNode(
132
- importer.external({
133
- type: true,
134
- library: "@nestia/fetcher",
135
- instance: "IPropagation",
136
- }),
137
- [
138
- ts.factory.createTypeLiteralNode(
139
- branches.map((b) =>
140
- ts.factory.createPropertySignature(
141
- undefined,
142
- ts.factory.createNumericLiteral(b.status),
143
- undefined,
144
- b.type,
145
- ),
146
- ),
147
- ),
148
- ...(route.success.status
149
- ? [
150
- ts.factory.createLiteralTypeNode(
151
- ts.factory.createNumericLiteral(route.success.status),
152
- ),
153
- ]
154
- : []),
155
- ],
156
- );
157
- };
158
-
159
- export const responseBody =
160
- (project: INestiaProject) =>
161
- (importer: ImportDictionary) =>
162
- (route: ITypedHttpRoute): ts.TypeNode =>
163
- output({
164
- ...project,
165
- config: {
166
- ...project.config,
167
- propagate: false,
168
- },
169
- })(importer)(route);
170
-
171
- const formDataInput = (importer: ImportDictionary) => (type: ts.TypeNode) =>
172
- ts.factory.createTypeReferenceNode(
173
- importer.external({
174
- type: true,
175
- library: "@nestia/fetcher",
176
- instance: "FormDataInput",
177
- }),
178
- [type],
179
- );
180
- }
181
-
182
- interface IBranch {
183
- status: string;
184
- type: ts.TypeNode;
185
- }
1
+ import ts from "typescript";
2
+ import typia from "typia";
3
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
5
+
6
+ import { INestiaProject } from "../../structures/INestiaProject";
7
+ import { IReflectHttpOperationParameter } from "../../structures/IReflectHttpOperationParameter";
8
+ import { IReflectType } from "../../structures/IReflectType";
9
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
10
+ import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
11
+ import { ImportDictionary } from "./ImportDictionary";
12
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
13
+
14
+ export namespace SdkAliasCollection {
15
+ export const name = ({ type }: { type: IReflectType }): ts.TypeNode =>
16
+ ts.factory.createTypeReferenceNode(
17
+ type.name,
18
+ type.typeArguments
19
+ ? type.typeArguments.map((a) => name({ type: a }))
20
+ : undefined,
21
+ );
22
+
23
+ export const from =
24
+ (project: INestiaProject) =>
25
+ (importer: ImportDictionary) =>
26
+ (metadata: Metadata) =>
27
+ SdkTypeProgrammer.write(project)(importer)(metadata);
28
+
29
+ export const props =
30
+ (project: INestiaProject) =>
31
+ (importer: ImportDictionary) =>
32
+ (route: ITypedHttpRoute): ts.TypeNode =>
33
+ ts.factory.createTypeLiteralNode(
34
+ route.parameters
35
+ .filter((p) => p.category !== "headers")
36
+ .map((param) =>
37
+ ts.factory.createPropertySignature(
38
+ undefined,
39
+ param.name,
40
+ param.metadata.isRequired() === false
41
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
42
+ : undefined,
43
+ SdkTypeProgrammer.write(project)(importer)(param.metadata),
44
+ ),
45
+ ),
46
+ );
47
+
48
+ export const headers =
49
+ (project: INestiaProject) =>
50
+ (importer: ImportDictionary) =>
51
+ (param: ITypedHttpRouteParameter.IHeaders): ts.TypeNode => {
52
+ if (project.config.clone === true)
53
+ return from(project)(importer)(param.metadata);
54
+ const type: ts.TypeNode = name(param);
55
+ if (project.config.primitive === false) return type;
56
+ return ts.factory.createTypeReferenceNode(
57
+ importer.external({
58
+ type: true,
59
+ library: "typia",
60
+ instance: "Resolved",
61
+ }),
62
+ [type],
63
+ );
64
+ };
65
+
66
+ export const query =
67
+ (project: INestiaProject) =>
68
+ (importer: ImportDictionary) =>
69
+ (param: ITypedHttpRouteParameter.IQuery): ts.TypeNode => {
70
+ if (project.config.clone === true)
71
+ return from(project)(importer)(param.metadata);
72
+ const type: ts.TypeNode = name(param);
73
+ if (project.config.primitive === false) return type;
74
+ return ts.factory.createTypeReferenceNode(
75
+ importer.external({
76
+ type: true,
77
+ library: "typia",
78
+ instance: "Resolved",
79
+ }),
80
+ [type],
81
+ );
82
+ };
83
+
84
+ export const body =
85
+ (project: INestiaProject) =>
86
+ (importer: ImportDictionary) =>
87
+ (param: ITypedHttpRouteParameter.IBody): ts.TypeNode => {
88
+ if (project.config.clone === true) {
89
+ const type: ts.TypeNode = from(project)(importer)(param.metadata);
90
+ return param.contentType === "multipart/form-data"
91
+ ? formDataInput(importer)(type)
92
+ : type;
93
+ }
94
+ const type: ts.TypeNode = name(param);
95
+ if (param.contentType === "multipart/form-data")
96
+ return formDataInput(importer)(type);
97
+ else if (project.config.primitive === false) return type;
98
+ return ts.factory.createTypeReferenceNode(
99
+ importer.external({
100
+ type: true,
101
+ library: "typia",
102
+ instance:
103
+ typia.is<IReflectHttpOperationParameter.IBody>(param) &&
104
+ (param.contentType === "application/json" ||
105
+ param.encrypted === true)
106
+ ? "Primitive"
107
+ : "Resolved",
108
+ }),
109
+ [type],
110
+ );
111
+ };
112
+
113
+ export const response =
114
+ (project: INestiaProject) =>
115
+ (importer: ImportDictionary) =>
116
+ (route: ITypedHttpRoute): ts.TypeNode => {
117
+ const schema = (p: { metadata: Metadata; type: IReflectType }) =>
118
+ p.metadata.size() === 0
119
+ ? TypeFactory.keyword("void")
120
+ : project.config.clone === true
121
+ ? from(project)(importer)(p.metadata)
122
+ : project.config.primitive !== false
123
+ ? ts.factory.createTypeReferenceNode(
124
+ importer.external({
125
+ type: true,
126
+ library: "typia",
127
+ instance:
128
+ route.success.contentType === "application/json" ||
129
+ route.success.encrypted === true
130
+ ? "Primitive"
131
+ : "Resolved",
132
+ }),
133
+ [name(p)],
134
+ )
135
+ : name(p);
136
+ if (project.config.propagate !== true) return schema(route.success);
137
+
138
+ const branches: IBranch[] = [
139
+ {
140
+ status: String(
141
+ route.success.status ?? (route.method === "POST" ? 201 : 200),
142
+ ),
143
+ type: schema(route.success),
144
+ },
145
+ ...Object.entries(route.exceptions).map(([status, value]) => ({
146
+ status,
147
+ type: schema(value),
148
+ })),
149
+ ];
150
+ return ts.factory.createTypeReferenceNode(
151
+ importer.external({
152
+ type: true,
153
+ library: "@nestia/fetcher",
154
+ instance: "IPropagation",
155
+ }),
156
+ [
157
+ ts.factory.createTypeLiteralNode(
158
+ branches.map((b) =>
159
+ ts.factory.createPropertySignature(
160
+ undefined,
161
+ ts.factory.createNumericLiteral(b.status),
162
+ undefined,
163
+ b.type,
164
+ ),
165
+ ),
166
+ ),
167
+ ...(route.success.status
168
+ ? [
169
+ ts.factory.createLiteralTypeNode(
170
+ ts.factory.createNumericLiteral(route.success.status),
171
+ ),
172
+ ]
173
+ : []),
174
+ ],
175
+ );
176
+ };
177
+
178
+ export const responseBody =
179
+ (project: INestiaProject) =>
180
+ (importer: ImportDictionary) =>
181
+ (route: ITypedHttpRoute): ts.TypeNode =>
182
+ response({
183
+ ...project,
184
+ config: {
185
+ ...project.config,
186
+ propagate: false,
187
+ },
188
+ })(importer)(route);
189
+
190
+ const formDataInput = (importer: ImportDictionary) => (type: ts.TypeNode) =>
191
+ ts.factory.createTypeReferenceNode(
192
+ importer.external({
193
+ type: true,
194
+ library: "@nestia/fetcher",
195
+ instance: "FormDataInput",
196
+ }),
197
+ [type],
198
+ );
199
+ }
200
+
201
+ interface IBranch {
202
+ status: string;
203
+ type: ts.TypeNode;
204
+ }
@@ -1,103 +1,103 @@
1
- import cp from "child_process";
2
- import fs from "fs";
3
- import path from "path";
4
- import typia from "typia";
5
-
6
- import { INestiaConfig } from "../../INestiaConfig";
7
-
8
- export namespace SdkDistributionComposer {
9
- export const compose = async (props: {
10
- config: INestiaConfig;
11
- websocket: boolean;
12
- }) => {
13
- if (!fs.existsSync(props.config.distribute!))
14
- await fs.promises.mkdir(props.config.distribute!);
15
-
16
- const root: string = process.cwd();
17
- const output: string = path.resolve(props.config.output!);
18
- process.chdir(props.config.distribute!);
19
-
20
- const exit = () => process.chdir(root);
21
- if (await configured()) return exit();
22
-
23
- // COPY FILES
24
- console.log("Composing SDK distribution environments...");
25
- for (const file of await fs.promises.readdir(BUNDLE))
26
- await fs.promises.copyFile(`${BUNDLE}/${file}`, file);
27
-
28
- // CONFIGURE PATHS
29
- for (const file of ["package.json", "tsconfig.json"])
30
- await replace({ root, output })(file);
31
-
32
- // INSTALL PACKAGES
33
- const v: IDependencies = await dependencies();
34
- execute("npm install --save-dev rimraf");
35
- execute(`npm install --save @nestia/fetcher@${v.version}`);
36
- execute(`npm install --save typia@${v.typia}`);
37
- if (props.websocket) execute(`npm install --save tgrid@${v.tgrid}`);
38
- execute("npx typia setup --manager npm");
39
-
40
- exit();
41
- };
42
-
43
- const configured = async (): Promise<boolean> =>
44
- ["package.json", "tsconfig.json"].every(fs.existsSync) &&
45
- (await (async () => {
46
- const content = JSON.parse(
47
- await fs.promises.readFile("package.json", "utf8"),
48
- );
49
- return !!content.dependencies?.["@nestia/fetcher"];
50
- })());
51
-
52
- const execute = (command: string) => {
53
- console.log(` - ${command}`);
54
- cp.execSync(command, { stdio: "ignore" });
55
- };
56
-
57
- const replace =
58
- (props: { root: string; output: string }) =>
59
- async (file: string): Promise<void> => {
60
- const relative = (from: string) => (to: string) =>
61
- path.relative(from, to).split("\\").join("/");
62
- const root: string = relative(process.cwd())(props.root);
63
- const output: string = relative(process.cwd())(props.output);
64
- const current: string = relative(props.root)(process.cwd());
65
-
66
- const content: string = await fs.promises.readFile(file, "utf8");
67
- await fs.promises.writeFile(
68
- file,
69
- content
70
- .split("${root}")
71
- .join(root)
72
- .split("${output}")
73
- .join(output)
74
- .split("${current}")
75
- .join(current),
76
- "utf8",
77
- );
78
- };
79
-
80
- const dependencies = async (): Promise<IDependencies> => {
81
- const content: string = await fs.promises.readFile(
82
- __dirname + "/../../../package.json",
83
- "utf8",
84
- );
85
- const json: {
86
- version: string;
87
- dependencies: Record<string, string>;
88
- devDependencies: Record<string, string>;
89
- } = JSON.parse(content);
90
- return typia.assert<IDependencies>({
91
- ...json.devDependencies,
92
- ...json.dependencies,
93
- version: json.version,
94
- });
95
- };
96
- }
97
-
98
- interface IDependencies {
99
- version: string;
100
- typia: string;
101
- tgrid: string;
102
- }
103
- const BUNDLE = __dirname + "/../../../assets/bundle/distribute";
1
+ import cp from "child_process";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import typia from "typia";
5
+
6
+ import { INestiaConfig } from "../../INestiaConfig";
7
+
8
+ export namespace SdkDistributionComposer {
9
+ export const compose = async (props: {
10
+ config: INestiaConfig;
11
+ websocket: boolean;
12
+ }) => {
13
+ if (!fs.existsSync(props.config.distribute!))
14
+ await fs.promises.mkdir(props.config.distribute!);
15
+
16
+ const root: string = process.cwd();
17
+ const output: string = path.resolve(props.config.output!);
18
+ process.chdir(props.config.distribute!);
19
+
20
+ const exit = () => process.chdir(root);
21
+ if (await configured()) return exit();
22
+
23
+ // COPY FILES
24
+ console.log("Composing SDK distribution environments...");
25
+ for (const file of await fs.promises.readdir(BUNDLE))
26
+ await fs.promises.copyFile(`${BUNDLE}/${file}`, file);
27
+
28
+ // CONFIGURE PATHS
29
+ for (const file of ["package.json", "tsconfig.json"])
30
+ await replace({ root, output })(file);
31
+
32
+ // INSTALL PACKAGES
33
+ const v: IDependencies = await dependencies();
34
+ execute("npm install --save-dev rimraf");
35
+ execute(`npm install --save @nestia/fetcher@${v.version}`);
36
+ execute(`npm install --save typia@${v.typia}`);
37
+ if (props.websocket) execute(`npm install --save tgrid@${v.tgrid}`);
38
+ execute("npx typia setup --manager npm");
39
+
40
+ exit();
41
+ };
42
+
43
+ const configured = async (): Promise<boolean> =>
44
+ ["package.json", "tsconfig.json"].every(fs.existsSync) &&
45
+ (await (async () => {
46
+ const content = JSON.parse(
47
+ await fs.promises.readFile("package.json", "utf8"),
48
+ );
49
+ return !!content.dependencies?.["@nestia/fetcher"];
50
+ })());
51
+
52
+ const execute = (command: string) => {
53
+ console.log(` - ${command}`);
54
+ cp.execSync(command, { stdio: "ignore" });
55
+ };
56
+
57
+ const replace =
58
+ (props: { root: string; output: string }) =>
59
+ async (file: string): Promise<void> => {
60
+ const relative = (from: string) => (to: string) =>
61
+ path.relative(from, to).split("\\").join("/");
62
+ const root: string = relative(process.cwd())(props.root);
63
+ const output: string = relative(process.cwd())(props.output);
64
+ const current: string = relative(props.root)(process.cwd());
65
+
66
+ const content: string = await fs.promises.readFile(file, "utf8");
67
+ await fs.promises.writeFile(
68
+ file,
69
+ content
70
+ .split("${root}")
71
+ .join(root)
72
+ .split("${output}")
73
+ .join(output)
74
+ .split("${current}")
75
+ .join(current),
76
+ "utf8",
77
+ );
78
+ };
79
+
80
+ const dependencies = async (): Promise<IDependencies> => {
81
+ const content: string = await fs.promises.readFile(
82
+ __dirname + "/../../../package.json",
83
+ "utf8",
84
+ );
85
+ const json: {
86
+ version: string;
87
+ dependencies: Record<string, string>;
88
+ devDependencies: Record<string, string>;
89
+ } = JSON.parse(content);
90
+ return typia.assert<IDependencies>({
91
+ ...json.devDependencies,
92
+ ...json.dependencies,
93
+ version: json.version,
94
+ });
95
+ };
96
+ }
97
+
98
+ interface IDependencies {
99
+ version: string;
100
+ typia: string;
101
+ tgrid: string;
102
+ }
103
+ const BUNDLE = __dirname + "/../../../assets/bundle/distribute";