@nestia/migrate 10.0.2 → 11.0.0-dev.20260305

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -93
  3. package/package.json +32 -46
  4. package/src/NestiaMigrateApplication.ts +161 -159
  5. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
  6. package/src/archivers/NestiaMigrateFileArchiver.ts +28 -28
  7. package/src/bundles/NEST_TEMPLATE.ts +48 -48
  8. package/src/bundles/SDK_TEMPLATE.ts +21 -21
  9. package/src/executable/NestiaMigrateCommander.ts +98 -98
  10. package/src/executable/NestiaMigrateInquirer.ts +106 -106
  11. package/src/executable/bundle.js +125 -125
  12. package/src/executable/migrate.ts +7 -7
  13. package/src/factories/TypeLiteralFactory.ts +57 -57
  14. package/src/index.ts +4 -4
  15. package/src/module.ts +6 -2
  16. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -55
  17. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +347 -344
  18. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +517 -514
  19. package/src/programmers/NestiaMigrateApiProgrammer.ts +107 -107
  20. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +308 -309
  21. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +197 -198
  22. package/src/programmers/NestiaMigrateDtoProgrammer.ts +98 -98
  23. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +153 -153
  24. package/src/programmers/NestiaMigrateE2eProgrammer.ts +48 -48
  25. package/src/programmers/NestiaMigrateImportProgrammer.ts +118 -118
  26. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +69 -69
  27. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +409 -406
  28. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +65 -65
  29. package/src/programmers/NestiaMigrateNestProgrammer.ts +88 -88
  30. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +465 -467
  31. package/src/structures/INestiaMigrateConfig.ts +19 -19
  32. package/src/structures/INestiaMigrateContext.ts +9 -9
  33. package/src/structures/INestiaMigrateController.ts +8 -8
  34. package/src/structures/INestiaMigrateDto.ts +8 -8
  35. package/src/structures/INestiaMigrateFile.ts +5 -5
  36. package/src/structures/INestiaMigrateProgram.ts +11 -11
  37. package/src/structures/INestiaMigrateSchema.ts +4 -4
  38. package/src/utils/FilePrinter.ts +49 -49
  39. package/src/utils/MapUtil.ts +13 -13
  40. package/src/utils/SetupWizard.ts +12 -12
  41. package/src/utils/StringUtil.ts +114 -113
  42. package/src/utils/openapi-down-convert/RefVisitor.ts +134 -134
  43. package/src/utils/openapi-down-convert/converter.ts +536 -536
  44. package/lib/NestiaMigrateApplication.d.ts +0 -24
  45. package/lib/NestiaMigrateApplication.js +0 -18757
  46. package/lib/NestiaMigrateApplication.js.map +0 -1
  47. package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +0 -5
  48. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +0 -46
  49. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +0 -1
  50. package/lib/archivers/NestiaMigrateFileArchiver.d.ts +0 -8
  51. package/lib/archivers/NestiaMigrateFileArchiver.js +0 -36
  52. package/lib/archivers/NestiaMigrateFileArchiver.js.map +0 -1
  53. package/lib/bundles/NEST_TEMPLATE.d.ts +0 -1
  54. package/lib/bundles/NEST_TEMPLATE.js +0 -55
  55. package/lib/bundles/NEST_TEMPLATE.js.map +0 -1
  56. package/lib/bundles/SDK_TEMPLATE.d.ts +0 -1
  57. package/lib/bundles/SDK_TEMPLATE.js +0 -27
  58. package/lib/bundles/SDK_TEMPLATE.js.map +0 -1
  59. package/lib/executable/NestiaMigrateCommander.d.ts +0 -4
  60. package/lib/executable/NestiaMigrateCommander.js +0 -125
  61. package/lib/executable/NestiaMigrateCommander.js.map +0 -1
  62. package/lib/executable/NestiaMigrateInquirer.d.ts +0 -12
  63. package/lib/executable/NestiaMigrateInquirer.js +0 -94
  64. package/lib/executable/NestiaMigrateInquirer.js.map +0 -1
  65. package/lib/executable/migrate.d.ts +0 -2
  66. package/lib/executable/migrate.js +0 -9
  67. package/lib/executable/migrate.js.map +0 -1
  68. package/lib/factories/TypeLiteralFactory.d.ts +0 -4
  69. package/lib/factories/TypeLiteralFactory.js +0 -35
  70. package/lib/factories/TypeLiteralFactory.js.map +0 -1
  71. package/lib/index.d.ts +0 -3
  72. package/lib/index.js +0 -42
  73. package/lib/index.js.map +0 -1
  74. package/lib/index.mjs +0 -19359
  75. package/lib/index.mjs.map +0 -1
  76. package/lib/module.d.ts +0 -2
  77. package/lib/module.js +0 -19
  78. package/lib/module.js.map +0 -1
  79. package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +0 -13
  80. package/lib/programmers/NestiaMigrateApiFileProgrammer.js +0 -40
  81. package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +0 -1
  82. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +0 -14
  83. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +0 -179
  84. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +0 -1
  85. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +0 -14
  86. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +0 -226
  87. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +0 -1
  88. package/lib/programmers/NestiaMigrateApiProgrammer.d.ts +0 -4
  89. package/lib/programmers/NestiaMigrateApiProgrammer.js +0 -82
  90. package/lib/programmers/NestiaMigrateApiProgrammer.js.map +0 -1
  91. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +0 -14
  92. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +0 -142
  93. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +0 -1
  94. package/lib/programmers/NestiaMigrateApiStartProgrammer.d.ts +0 -4
  95. package/lib/programmers/NestiaMigrateApiStartProgrammer.js +0 -80
  96. package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +0 -1
  97. package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +0 -15
  98. package/lib/programmers/NestiaMigrateDtoProgrammer.js +0 -65
  99. package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +0 -1
  100. package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +0 -14
  101. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +0 -81
  102. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +0 -1
  103. package/lib/programmers/NestiaMigrateE2eProgrammer.d.ts +0 -4
  104. package/lib/programmers/NestiaMigrateE2eProgrammer.js +0 -32
  105. package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +0 -1
  106. package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +0 -18
  107. package/lib/programmers/NestiaMigrateImportProgrammer.js +0 -65
  108. package/lib/programmers/NestiaMigrateImportProgrammer.js.map +0 -1
  109. package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +0 -12
  110. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +0 -46
  111. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +0 -1
  112. package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +0 -15
  113. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +0 -224
  114. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +0 -1
  115. package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +0 -5
  116. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +0 -29
  117. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +0 -1
  118. package/lib/programmers/NestiaMigrateNestProgrammer.d.ts +0 -4
  119. package/lib/programmers/NestiaMigrateNestProgrammer.js +0 -65
  120. package/lib/programmers/NestiaMigrateNestProgrammer.js.map +0 -1
  121. package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +0 -10
  122. package/lib/programmers/NestiaMigrateSchemaProgrammer.js +0 -341
  123. package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +0 -1
  124. package/lib/structures/INestiaMigrateConfig.d.ts +0 -15
  125. package/lib/structures/INestiaMigrateConfig.js +0 -3
  126. package/lib/structures/INestiaMigrateConfig.js.map +0 -1
  127. package/lib/structures/INestiaMigrateContext.d.ts +0 -7
  128. package/lib/structures/INestiaMigrateContext.js +0 -3
  129. package/lib/structures/INestiaMigrateContext.js.map +0 -1
  130. package/lib/structures/INestiaMigrateController.d.ts +0 -7
  131. package/lib/structures/INestiaMigrateController.js +0 -3
  132. package/lib/structures/INestiaMigrateController.js.map +0 -1
  133. package/lib/structures/INestiaMigrateDto.d.ts +0 -7
  134. package/lib/structures/INestiaMigrateDto.js +0 -3
  135. package/lib/structures/INestiaMigrateDto.js.map +0 -1
  136. package/lib/structures/INestiaMigrateFile.d.ts +0 -5
  137. package/lib/structures/INestiaMigrateFile.js +0 -3
  138. package/lib/structures/INestiaMigrateFile.js.map +0 -1
  139. package/lib/structures/INestiaMigrateProgram.d.ts +0 -9
  140. package/lib/structures/INestiaMigrateProgram.js +0 -3
  141. package/lib/structures/INestiaMigrateProgram.js.map +0 -1
  142. package/lib/structures/INestiaMigrateSchema.d.ts +0 -4
  143. package/lib/structures/INestiaMigrateSchema.js +0 -3
  144. package/lib/structures/INestiaMigrateSchema.js.map +0 -1
  145. package/lib/utils/FilePrinter.d.ts +0 -9
  146. package/lib/utils/FilePrinter.js +0 -35
  147. package/lib/utils/FilePrinter.js.map +0 -1
  148. package/lib/utils/MapUtil.d.ts +0 -3
  149. package/lib/utils/MapUtil.js +0 -15
  150. package/lib/utils/MapUtil.js.map +0 -1
  151. package/lib/utils/SetupWizard.d.ts +0 -3
  152. package/lib/utils/SetupWizard.js +0 -18
  153. package/lib/utils/SetupWizard.js.map +0 -1
  154. package/lib/utils/StringUtil.d.ts +0 -6
  155. package/lib/utils/StringUtil.js +0 -108
  156. package/lib/utils/StringUtil.js.map +0 -1
  157. package/lib/utils/openapi-down-convert/RefVisitor.d.ts +0 -52
  158. package/lib/utils/openapi-down-convert/RefVisitor.js +0 -102
  159. package/lib/utils/openapi-down-convert/RefVisitor.js.map +0 -1
  160. package/lib/utils/openapi-down-convert/converter.d.ts +0 -146
  161. package/lib/utils/openapi-down-convert/converter.js +0 -441
  162. package/lib/utils/openapi-down-convert/converter.js.map +0 -1
@@ -1,98 +1,98 @@
1
- import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
- import sortImport from "@trivago/prettier-plugin-sort-imports";
3
- import fs from "fs";
4
- import path from "path";
5
- import { format } from "prettier";
6
- import jsDoc from "prettier-plugin-jsdoc";
7
- import typia, { IValidation, tags } from "typia";
8
-
9
- import { NestiaMigrateApplication } from "../NestiaMigrateApplication";
10
- import { NestiaMigrateFileArchiver } from "../archivers/NestiaMigrateFileArchiver";
11
- import { NestiaMigrateInquirer } from "./NestiaMigrateInquirer";
12
-
13
- export namespace NestiaMigrateCommander {
14
- export const main = async (): Promise<void> => {
15
- const resolve = (str: string | undefined) =>
16
- str ? path.resolve(str).split("\\").join("/") : undefined;
17
- const options: NestiaMigrateInquirer.IOutput =
18
- await NestiaMigrateInquirer.parse();
19
-
20
- // VALIDATE OUTPUT DIRECTORY
21
- const parent: string = resolve(options.output + "/..")!;
22
- if (fs.existsSync(options.output))
23
- halt("Response directory already exists.");
24
- else if (fs.existsSync(parent) === false)
25
- halt("Response directory's parent directory does not exist.");
26
- else if (fs.statSync(parent).isDirectory() === false)
27
- halt("Response directory's parent is not a directory.");
28
-
29
- // READ SWAGGER
30
- const document:
31
- | SwaggerV2.IDocument
32
- | OpenApiV3.IDocument
33
- | OpenApiV3_1.IDocument = await (async () => {
34
- if (typia.is<string & tags.Format<"uri">>(options.input)) {
35
- const response: Response = await fetch(options.input);
36
- const content: string = await response.text();
37
- return JSON.parse(content);
38
- }
39
- if (fs.existsSync(options.input) === false)
40
- halt("Unable to find the input swagger.json file.");
41
- const stats: fs.Stats = fs.statSync(options.input);
42
- if (stats.isFile() === false)
43
- halt("The input swagger.json is not a file.");
44
- const content: string = await fs.promises.readFile(
45
- options.input,
46
- "utf-8",
47
- );
48
- return JSON.parse(content);
49
- })();
50
-
51
- const result: IValidation<NestiaMigrateApplication> =
52
- NestiaMigrateApplication.validate(document);
53
- if (result.success === false) {
54
- console.log(result.errors);
55
- throw new Error(
56
- `Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
57
- );
58
- }
59
-
60
- const app: NestiaMigrateApplication = result.data;
61
- const files: Record<string, string> =
62
- options.mode === "nest" ? app.nest(options) : app.sdk(options);
63
- if (app.getData().errors)
64
- for (const error of app.getData().errors)
65
- console.error(
66
- `Failed to migrate ${error.method} ${error.path}`,
67
- ...error.messages.map((msg) => ` - ${msg}`),
68
- );
69
- await NestiaMigrateFileArchiver.archive({
70
- mkdir: fs.promises.mkdir,
71
- writeFile: async (file, content) =>
72
- fs.promises.writeFile(file, await beautify(content), "utf-8"),
73
- root: options.output,
74
- files,
75
- });
76
- };
77
-
78
- export const beautify = async (script: string): Promise<string> => {
79
- try {
80
- return await format(script, {
81
- parser: "typescript",
82
- plugins: [sortImport, jsDoc],
83
- importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
84
- importOrderSeparation: true,
85
- importOrderSortSpecifiers: true,
86
- importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
87
- bracketSpacing: true,
88
- });
89
- } catch {
90
- return script;
91
- }
92
- };
93
-
94
- const halt = (desc: string): never => {
95
- console.error(desc);
96
- process.exit(-1);
97
- };
98
- }
1
+ import * as prettierPluginSortImport from "@trivago/prettier-plugin-sort-imports";
2
+ import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { format } from "prettier";
6
+ import * as prettierPluginJsDoc from "prettier-plugin-jsdoc";
7
+ import typia, { IValidation, tags } from "typia";
8
+
9
+ import { NestiaMigrateApplication } from "../NestiaMigrateApplication";
10
+ import { NestiaMigrateFileArchiver } from "../archivers/NestiaMigrateFileArchiver";
11
+ import { NestiaMigrateInquirer } from "./NestiaMigrateInquirer";
12
+
13
+ export namespace NestiaMigrateCommander {
14
+ export const main = async (): Promise<void> => {
15
+ const resolve = (str: string | undefined) =>
16
+ str ? path.resolve(str).split("\\").join("/") : undefined;
17
+ const options: NestiaMigrateInquirer.IOutput =
18
+ await NestiaMigrateInquirer.parse();
19
+
20
+ // VALIDATE OUTPUT DIRECTORY
21
+ const parent: string = resolve(options.output + "/..")!;
22
+ if (fs.existsSync(options.output))
23
+ halt("Response directory already exists.");
24
+ else if (fs.existsSync(parent) === false)
25
+ halt("Response directory's parent directory does not exist.");
26
+ else if (fs.statSync(parent).isDirectory() === false)
27
+ halt("Response directory's parent is not a directory.");
28
+
29
+ // READ SWAGGER
30
+ const document:
31
+ | SwaggerV2.IDocument
32
+ | OpenApiV3.IDocument
33
+ | OpenApiV3_1.IDocument = await (async () => {
34
+ if (typia.is<string & tags.Format<"uri">>(options.input)) {
35
+ const response: Response = await fetch(options.input);
36
+ const content: string = await response.text();
37
+ return JSON.parse(content);
38
+ }
39
+ if (fs.existsSync(options.input) === false)
40
+ halt("Unable to find the input swagger.json file.");
41
+ const stats: fs.Stats = fs.statSync(options.input);
42
+ if (stats.isFile() === false)
43
+ halt("The input swagger.json is not a file.");
44
+ const content: string = await fs.promises.readFile(
45
+ options.input,
46
+ "utf-8",
47
+ );
48
+ return JSON.parse(content);
49
+ })();
50
+
51
+ const result: IValidation<NestiaMigrateApplication> =
52
+ NestiaMigrateApplication.validate(document);
53
+ if (result.success === false) {
54
+ console.log(result.errors);
55
+ throw new Error(
56
+ `Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
57
+ );
58
+ }
59
+
60
+ const app: NestiaMigrateApplication = result.data;
61
+ const files: Record<string, string> =
62
+ options.mode === "nest" ? app.nest(options) : app.sdk(options);
63
+ if (app.getData().errors)
64
+ for (const error of app.getData().errors)
65
+ console.error(
66
+ `Failed to migrate ${error.method} ${error.path}`,
67
+ ...error.messages.map((msg) => ` - ${msg}`),
68
+ );
69
+ await NestiaMigrateFileArchiver.archive({
70
+ mkdir: fs.promises.mkdir,
71
+ writeFile: async (file, content) =>
72
+ fs.promises.writeFile(file, await beautify(content), "utf-8"),
73
+ root: options.output,
74
+ files,
75
+ });
76
+ };
77
+
78
+ export const beautify = async (script: string): Promise<string> => {
79
+ try {
80
+ return await format(script, {
81
+ parser: "typescript",
82
+ plugins: [prettierPluginSortImport, prettierPluginJsDoc],
83
+ importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
84
+ importOrderSeparation: true,
85
+ importOrderSortSpecifiers: true,
86
+ importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
87
+ bracketSpacing: true,
88
+ });
89
+ } catch {
90
+ return script;
91
+ }
92
+ };
93
+
94
+ const halt = (desc: string): never => {
95
+ console.error(desc);
96
+ process.exit(-1);
97
+ };
98
+ }
@@ -1,106 +1,106 @@
1
- import commander from "commander";
2
- import inquirer from "inquirer";
3
-
4
- export namespace NestiaMigrateInquirer {
5
- export interface IOutput {
6
- mode: "nest" | "sdk";
7
- input: string;
8
- output: string;
9
- keyword: boolean;
10
- simulate: boolean;
11
- e2e: boolean;
12
- package: string;
13
- }
14
-
15
- export const parse = async (): Promise<IOutput> => {
16
- // PREPARE ASSETS
17
- commander.program.option("--mode [nest/sdk]", "migration mode");
18
- commander.program.option(
19
- "--input [swagger.json]",
20
- "location of target swagger.json file",
21
- );
22
- commander.program.option("--output [directory]", "output directory path");
23
- commander.program.option("--keyword [boolean]", "Keyword parameter mode");
24
- commander.program.option("--simulate [boolean]", "Mockup simulator");
25
- commander.program.option("--e2e [boolean]", "Generate E2E tests");
26
- commander.program.option("--package [name]", "Package name");
27
-
28
- // INTERNAL PROCEDURES
29
- const questioned = { value: false };
30
- const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
31
- new Promise<IOutput>((resolve, reject) => {
32
- commander.program.action(async (options) => {
33
- try {
34
- resolve(await closure(options));
35
- } catch (exp) {
36
- reject(exp);
37
- }
38
- });
39
- commander.program.parseAsync().catch(reject);
40
- });
41
- const select =
42
- (name: string) =>
43
- (message: string) =>
44
- async <Choice extends string>(
45
- choices: Choice[],
46
- filter?: (value: string) => Choice,
47
- ): Promise<Choice> => {
48
- questioned.value = true;
49
- return (
50
- await inquirer.createPromptModule()({
51
- type: "list",
52
- name: name,
53
- message: message,
54
- choices: choices,
55
- filter,
56
- })
57
- )[name];
58
- };
59
- const input = (name: string) => async (message: string) =>
60
- (
61
- await inquirer.createPromptModule()({
62
- type: "input",
63
- name,
64
- message,
65
- })
66
- )[name];
67
-
68
- // DO CONSTRUCT
69
- return action(async (partial) => {
70
- partial.mode ??= await select("mode")("Migration mode")(
71
- ["NestJS" as "nest", "SDK" as "sdk"],
72
- (value) => (value === "NestJS" ? "nest" : "sdk"),
73
- );
74
- partial.input ??= await input("input")("Swagger file location");
75
- partial.output ??= await input("output")("Response directory path");
76
- partial.package ??= await input("package")("Package name");
77
- partial.keyword ??=
78
- (await select("keyword")("Keyword parameter mode")([
79
- "true",
80
- "false",
81
- ])) === "true";
82
-
83
- if (partial.keyword)
84
- partial.keyword = (partial.keyword as any) === "true";
85
- else
86
- partial.keyword =
87
- (await select("keyword")("Keyword parameter mode")([
88
- "true",
89
- "false",
90
- ])) === "true";
91
- if (partial.simulate)
92
- partial.simulate = (partial.simulate as any) === "true";
93
- else
94
- partial.simulate =
95
- (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
96
- "true";
97
-
98
- if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
99
- else
100
- partial.e2e =
101
- (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
102
- "true";
103
- return partial as IOutput;
104
- });
105
- };
106
- }
1
+ import { program } from "commander";
2
+ import { createPromptModule } from "inquirer";
3
+
4
+ export namespace NestiaMigrateInquirer {
5
+ export interface IOutput {
6
+ mode: "nest" | "sdk";
7
+ input: string;
8
+ output: string;
9
+ keyword: boolean;
10
+ simulate: boolean;
11
+ e2e: boolean;
12
+ package: string;
13
+ }
14
+
15
+ export const parse = async (): Promise<IOutput> => {
16
+ // PREPARE ASSETS
17
+ program.option("--mode [nest/sdk]", "migration mode");
18
+ program.option(
19
+ "--input [swagger.json]",
20
+ "location of target swagger.json file",
21
+ );
22
+ program.option("--output [directory]", "output directory path");
23
+ program.option("--keyword [boolean]", "Keyword parameter mode");
24
+ program.option("--simulate [boolean]", "Mockup simulator");
25
+ program.option("--e2e [boolean]", "Generate E2E tests");
26
+ program.option("--package [name]", "Package name");
27
+
28
+ // INTERNAL PROCEDURES
29
+ const questioned = { value: false };
30
+ const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
31
+ new Promise<IOutput>((resolve, reject) => {
32
+ program.action(async (options) => {
33
+ try {
34
+ resolve(await closure(options));
35
+ } catch (exp) {
36
+ reject(exp);
37
+ }
38
+ });
39
+ program.parseAsync().catch(reject);
40
+ });
41
+ const select =
42
+ (name: string) =>
43
+ (message: string) =>
44
+ async <Choice extends string>(
45
+ choices: Choice[],
46
+ filter?: (value: string) => Choice,
47
+ ): Promise<Choice> => {
48
+ questioned.value = true;
49
+ return (
50
+ await createPromptModule()({
51
+ type: "list",
52
+ name: name,
53
+ message: message,
54
+ choices: choices,
55
+ filter,
56
+ })
57
+ )[name];
58
+ };
59
+ const input = (name: string) => async (message: string) =>
60
+ (
61
+ await createPromptModule()({
62
+ type: "input",
63
+ name,
64
+ message,
65
+ })
66
+ )[name];
67
+
68
+ // DO CONSTRUCT
69
+ return action(async (partial) => {
70
+ partial.mode ??= await select("mode")("Migration mode")(
71
+ ["NestJS" as "nest", "SDK" as "sdk"],
72
+ (value) => (value === "NestJS" ? "nest" : "sdk"),
73
+ );
74
+ partial.input ??= await input("input")("Swagger file location");
75
+ partial.output ??= await input("output")("Response directory path");
76
+ partial.package ??= await input("package")("Package name");
77
+ partial.keyword ??=
78
+ (await select("keyword")("Keyword parameter mode")([
79
+ "true",
80
+ "false",
81
+ ])) === "true";
82
+
83
+ if (partial.keyword)
84
+ partial.keyword = (partial.keyword as any) === "true";
85
+ else
86
+ partial.keyword =
87
+ (await select("keyword")("Keyword parameter mode")([
88
+ "true",
89
+ "false",
90
+ ])) === "true";
91
+ if (partial.simulate)
92
+ partial.simulate = (partial.simulate as any) === "true";
93
+ else
94
+ partial.simulate =
95
+ (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
96
+ "true";
97
+
98
+ if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
99
+ else
100
+ partial.e2e =
101
+ (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
102
+ "true";
103
+ return partial as IOutput;
104
+ });
105
+ };
106
+ }
@@ -1,125 +1,125 @@
1
- const { version } = require("../../../../package.json");
2
- const cp = require("child_process");
3
- const fs = require("fs");
4
-
5
- const ROOT = `${__dirname}/../..`;
6
- const ASSETS = `${ROOT}/assets`;
7
-
8
- const update = (content) => {
9
- const parsed = JSON.parse(content);
10
- for (const record of [
11
- parsed.dependencies ?? {},
12
- parsed.devDependencies ?? {},
13
- ])
14
- for (const key of Object.keys(record))
15
- if (key.startsWith("@nestia/") || key === "nestia")
16
- record[key] = `^${version}`;
17
- return JSON.stringify(parsed, null, 2);
18
- };
19
-
20
- const bundle = async ({ mode, repository, exceptions, transform }) => {
21
- const root = `${__dirname}/../..`;
22
- const assets = `${root}/assets`;
23
- const template = `${assets}/${mode}`;
24
-
25
- const clone = async () => {
26
- // CLONE REPOSITORY
27
- if (fs.existsSync(template))
28
- await fs.promises.rm(template, { recursive: true });
29
- else
30
- try {
31
- await fs.promises.mkdir(ASSETS);
32
- } catch {}
33
-
34
- cp.execSync(`git clone https://github.com/samchon/${repository} ${mode}`, {
35
- cwd: ASSETS,
36
- });
37
-
38
- // REMOVE VULNERABLE FILES
39
- for (const location of exceptions ?? [])
40
- await fs.promises.rm(`${template}/${location}`, { recursive: true });
41
- };
42
-
43
- const iterate = (collection) => async (location) => {
44
- const directory = await fs.promises.readdir(location);
45
- for (const file of directory) {
46
- const absolute = location + "/" + file;
47
- const stats = await fs.promises.stat(absolute);
48
- if (stats.isDirectory()) await iterate(collection)(absolute);
49
- else {
50
- const content = await fs.promises.readFile(absolute, "utf-8");
51
- collection[
52
- (() => {
53
- const str = absolute.replace(template, "");
54
- return str[0] === "/" ? str.substring(1) : str;
55
- })()
56
- ] = content;
57
- }
58
- }
59
- };
60
-
61
- const archive = async (collection) => {
62
- const name = `${mode.toUpperCase()}_TEMPLATE`;
63
- const body = JSON.stringify(collection, null, 2);
64
- const content = `export const ${name}: Record<string, string> = ${body}`;
65
-
66
- try {
67
- await fs.promises.mkdir(`${ROOT}/src/bundles`);
68
- } catch {}
69
- await fs.promises.writeFile(
70
- `${ROOT}/src/bundles/${name}.ts`,
71
- content,
72
- "utf8",
73
- );
74
- };
75
-
76
- const collection = {};
77
- await clone();
78
- await iterate(collection)(template);
79
- if (transform)
80
- for (const [key, value] of Object.entries(collection))
81
- collection[key] = transform(key, value);
82
- await archive(collection);
83
- };
84
-
85
- const main = async () => {
86
- await bundle({
87
- mode: "nest",
88
- repository: "nestia-start",
89
- exceptions: [
90
- ".git",
91
- ".github/dependabot.yml",
92
- ".github/workflows/dependabot-automerge.yml",
93
- "src/api/functional",
94
- "src/controllers",
95
- "src/MyModule.ts",
96
- "src/providers",
97
- "test/features",
98
- ],
99
- transform: (key, value) => {
100
- if (key === "package.json") return update(value);
101
- return value;
102
- },
103
- });
104
- await bundle({
105
- mode: "sdk",
106
- repository: "nestia-sdk-template",
107
- exceptions: [
108
- ".git",
109
- ".github/dependabot.yml",
110
- ".github/workflows/build.yml",
111
- ".github/workflows/dependabot-automerge.yml",
112
- "src/functional",
113
- "src/structures",
114
- "test/features",
115
- ],
116
- transform: (key, value) => {
117
- if (key === "package.json") return update(value);
118
- return value;
119
- },
120
- });
121
- };
122
- main().catch((exp) => {
123
- console.error(exp);
124
- process.exit(-1);
125
- });
1
+ const { version } = require("../../../../package.json");
2
+ const cp = require("child_process");
3
+ const fs = require("fs");
4
+
5
+ const ROOT = `${__dirname}/../..`;
6
+ const ASSETS = `${ROOT}/assets`;
7
+
8
+ const update = (content) => {
9
+ const parsed = JSON.parse(content);
10
+ for (const record of [
11
+ parsed.dependencies ?? {},
12
+ parsed.devDependencies ?? {},
13
+ ])
14
+ for (const key of Object.keys(record))
15
+ if (key.startsWith("@nestia/") || key === "nestia")
16
+ record[key] = `^${version}`;
17
+ return JSON.stringify(parsed, null, 2);
18
+ };
19
+
20
+ const bundle = async ({ mode, repository, exceptions, transform }) => {
21
+ const root = `${__dirname}/../..`;
22
+ const assets = `${root}/assets`;
23
+ const template = `${assets}/${mode}`;
24
+
25
+ const clone = async () => {
26
+ // CLONE REPOSITORY
27
+ if (fs.existsSync(template))
28
+ await fs.promises.rm(template, { recursive: true });
29
+ else
30
+ try {
31
+ await fs.promises.mkdir(ASSETS);
32
+ } catch {}
33
+
34
+ cp.execSync(`git clone https://github.com/samchon/${repository} ${mode}`, {
35
+ cwd: ASSETS,
36
+ });
37
+
38
+ // REMOVE VULNERABLE FILES
39
+ for (const location of exceptions ?? [])
40
+ await fs.promises.rm(`${template}/${location}`, { recursive: true });
41
+ };
42
+
43
+ const iterate = (collection) => async (location) => {
44
+ const directory = await fs.promises.readdir(location);
45
+ for (const file of directory) {
46
+ const absolute = location + "/" + file;
47
+ const stats = await fs.promises.stat(absolute);
48
+ if (stats.isDirectory()) await iterate(collection)(absolute);
49
+ else {
50
+ const content = await fs.promises.readFile(absolute, "utf-8");
51
+ collection[
52
+ (() => {
53
+ const str = absolute.replace(template, "");
54
+ return str[0] === "/" ? str.substring(1) : str;
55
+ })()
56
+ ] = content;
57
+ }
58
+ }
59
+ };
60
+
61
+ const archive = async (collection) => {
62
+ const name = `${mode.toUpperCase()}_TEMPLATE`;
63
+ const body = JSON.stringify(collection, null, 2);
64
+ const content = `export const ${name}: Record<string, string> = ${body}`;
65
+
66
+ try {
67
+ await fs.promises.mkdir(`${ROOT}/src/bundles`);
68
+ } catch {}
69
+ await fs.promises.writeFile(
70
+ `${ROOT}/src/bundles/${name}.ts`,
71
+ content,
72
+ "utf8",
73
+ );
74
+ };
75
+
76
+ const collection = {};
77
+ await clone();
78
+ await iterate(collection)(template);
79
+ if (transform)
80
+ for (const [key, value] of Object.entries(collection))
81
+ collection[key] = transform(key, value);
82
+ await archive(collection);
83
+ };
84
+
85
+ const main = async () => {
86
+ await bundle({
87
+ mode: "nest",
88
+ repository: "nestia-start",
89
+ exceptions: [
90
+ ".git",
91
+ ".github/dependabot.yml",
92
+ ".github/workflows/dependabot-automerge.yml",
93
+ "src/api/functional",
94
+ "src/controllers",
95
+ "src/MyModule.ts",
96
+ "src/providers",
97
+ "test/features",
98
+ ],
99
+ transform: (key, value) => {
100
+ if (key === "package.json") return update(value);
101
+ return value;
102
+ },
103
+ });
104
+ await bundle({
105
+ mode: "sdk",
106
+ repository: "nestia-sdk-template",
107
+ exceptions: [
108
+ ".git",
109
+ ".github/dependabot.yml",
110
+ ".github/workflows/build.yml",
111
+ ".github/workflows/dependabot-automerge.yml",
112
+ "src/functional",
113
+ "src/structures",
114
+ "test/features",
115
+ ],
116
+ transform: (key, value) => {
117
+ if (key === "package.json") return update(value);
118
+ return value;
119
+ },
120
+ });
121
+ };
122
+ main().catch((exp) => {
123
+ console.error(exp);
124
+ process.exit(-1);
125
+ });