@nestia/migrate 0.11.4 → 0.11.6

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 (53) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +29 -4
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/utils/openapi-down-convert/converter.js +2 -2
  6. package/package.json +2 -2
  7. package/src/MigrateApplication.ts +81 -81
  8. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  9. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  10. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
  11. package/src/archivers/MigrateFileArchiver.ts +38 -38
  12. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  13. package/src/bundles/SDK_TEMPLATE.ts +29 -4
  14. package/src/executable/bundle.ts +110 -110
  15. package/src/internal/MigrateCommander.ts +70 -70
  16. package/src/internal/MigrateInquirer.ts +86 -86
  17. package/src/module.ts +14 -14
  18. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  19. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  20. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  21. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  22. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  23. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  24. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  25. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  26. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  27. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  28. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  29. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  30. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  31. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  32. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  33. package/src/structures/IMigrateDto.ts +8 -8
  34. package/src/structures/IMigrateProgram.ts +27 -27
  35. package/src/structures/IMigrateRoute.ts +51 -51
  36. package/src/structures/ISwagger.ts +23 -23
  37. package/src/structures/ISwaggerComponents.ts +14 -14
  38. package/src/structures/ISwaggerRoute.ts +20 -20
  39. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  40. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  41. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  42. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  43. package/src/structures/ISwaggerSchema.ts +90 -90
  44. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  45. package/src/structures/ISwaggerV20.ts +10 -10
  46. package/src/structures/ISwaggerV31.ts +10 -10
  47. package/src/utils/FilePrinter.ts +36 -36
  48. package/src/utils/OpenApiConverter.ts +19 -19
  49. package/src/utils/StringUtil.ts +60 -60
  50. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  51. package/src/utils/SwaggerTypeChecker.ts +67 -67
  52. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  53. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,110 +1,110 @@
1
- import cp from "child_process";
2
- import fs from "fs";
3
-
4
- import { IMigrateFile } from "../structures/IMigrateFile";
5
-
6
- const ROOT: string = `${__dirname}/../..`;
7
- const ASSETS: string = `${ROOT}/assets`;
8
-
9
- const bundle = async (props: {
10
- mode: "nest" | "sdk";
11
- repository: string;
12
- exceptions?: string[];
13
- }): Promise<void> => {
14
- const root: string = `${__dirname}/../..`;
15
- const assets: string = `${root}/assets`;
16
- const template: string = `${assets}/${props.mode}`;
17
-
18
- const clone = async () => {
19
- // CLONE REPOSITORY
20
- if (fs.existsSync(template))
21
- await fs.promises.rm(template, { recursive: true });
22
- else
23
- try {
24
- await fs.promises.mkdir(ASSETS);
25
- } catch {}
26
-
27
- cp.execSync(
28
- `git clone https://github.com/samchon/${props.repository} ${props.mode}`,
29
- {
30
- cwd: ASSETS,
31
- },
32
- );
33
-
34
- // REMOVE VUNLERABLE FILES
35
- for (const location of props.exceptions ?? [])
36
- await fs.promises.rm(`${template}/${location}`, { recursive: true });
37
- };
38
-
39
- const iterate = (collection: IMigrateFile[]) => async (location: string) => {
40
- const directory: string[] = await fs.promises.readdir(location);
41
- for (const file of directory) {
42
- const absolute: string = location + "/" + file;
43
- const stats: fs.Stats = await fs.promises.stat(absolute);
44
- if (stats.isDirectory()) await iterate(collection)(absolute);
45
- else {
46
- const content: string = await fs.promises.readFile(absolute, "utf-8");
47
- collection.push({
48
- location: (() => {
49
- const str: string = location.replace(template, "");
50
- return str[0] === "/" ? str.substring(1) : str;
51
- })(),
52
- file,
53
- content,
54
- });
55
- }
56
- }
57
- };
58
-
59
- const archive = async (collection: IMigrateFile[]): Promise<void> => {
60
- const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
61
- const body: string = JSON.stringify(collection, null, 2);
62
- const content: string = `export const ${name} = ${body}`;
63
-
64
- try {
65
- await fs.promises.mkdir(`${ROOT}/src/bundles`);
66
- } catch {}
67
- await fs.promises.writeFile(
68
- `${ROOT}/src/bundles/${name}.ts`,
69
- content,
70
- "utf8",
71
- );
72
- };
73
-
74
- const collection: IMigrateFile[] = [];
75
- await clone();
76
- await iterate(collection)(template);
77
- await archive(collection);
78
- };
79
-
80
- const main = async (): Promise<void> => {
81
- await bundle({
82
- mode: "nest",
83
- repository: "nestia-start",
84
- exceptions: [
85
- ".git",
86
- ".github/dependabot.yml",
87
- "src/api/functional",
88
- "src/controllers",
89
- "src/MyModule.ts",
90
- "src/providers",
91
- "test/features",
92
- ],
93
- });
94
- await bundle({
95
- mode: "sdk",
96
- repository: "nestia-sdk-template",
97
- exceptions: [
98
- ".git",
99
- ".github/dependabot.yml",
100
- ".github/workflows/build.yml",
101
- "src/functional",
102
- "src/structures",
103
- "test/features",
104
- ],
105
- });
106
- };
107
- main().catch((exp) => {
108
- console.error(exp);
109
- process.exit(-1);
110
- });
1
+ import cp from "child_process";
2
+ import fs from "fs";
3
+
4
+ import { IMigrateFile } from "../structures/IMigrateFile";
5
+
6
+ const ROOT: string = `${__dirname}/../..`;
7
+ const ASSETS: string = `${ROOT}/assets`;
8
+
9
+ const bundle = async (props: {
10
+ mode: "nest" | "sdk";
11
+ repository: string;
12
+ exceptions?: string[];
13
+ }): Promise<void> => {
14
+ const root: string = `${__dirname}/../..`;
15
+ const assets: string = `${root}/assets`;
16
+ const template: string = `${assets}/${props.mode}`;
17
+
18
+ const clone = async () => {
19
+ // CLONE REPOSITORY
20
+ if (fs.existsSync(template))
21
+ await fs.promises.rm(template, { recursive: true });
22
+ else
23
+ try {
24
+ await fs.promises.mkdir(ASSETS);
25
+ } catch {}
26
+
27
+ cp.execSync(
28
+ `git clone https://github.com/samchon/${props.repository} ${props.mode}`,
29
+ {
30
+ cwd: ASSETS,
31
+ },
32
+ );
33
+
34
+ // REMOVE VUNLERABLE FILES
35
+ for (const location of props.exceptions ?? [])
36
+ await fs.promises.rm(`${template}/${location}`, { recursive: true });
37
+ };
38
+
39
+ const iterate = (collection: IMigrateFile[]) => async (location: string) => {
40
+ const directory: string[] = await fs.promises.readdir(location);
41
+ for (const file of directory) {
42
+ const absolute: string = location + "/" + file;
43
+ const stats: fs.Stats = await fs.promises.stat(absolute);
44
+ if (stats.isDirectory()) await iterate(collection)(absolute);
45
+ else {
46
+ const content: string = await fs.promises.readFile(absolute, "utf-8");
47
+ collection.push({
48
+ location: (() => {
49
+ const str: string = location.replace(template, "");
50
+ return str[0] === "/" ? str.substring(1) : str;
51
+ })(),
52
+ file,
53
+ content,
54
+ });
55
+ }
56
+ }
57
+ };
58
+
59
+ const archive = async (collection: IMigrateFile[]): Promise<void> => {
60
+ const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
61
+ const body: string = JSON.stringify(collection, null, 2);
62
+ const content: string = `export const ${name} = ${body}`;
63
+
64
+ try {
65
+ await fs.promises.mkdir(`${ROOT}/src/bundles`);
66
+ } catch {}
67
+ await fs.promises.writeFile(
68
+ `${ROOT}/src/bundles/${name}.ts`,
69
+ content,
70
+ "utf8",
71
+ );
72
+ };
73
+
74
+ const collection: IMigrateFile[] = [];
75
+ await clone();
76
+ await iterate(collection)(template);
77
+ await archive(collection);
78
+ };
79
+
80
+ const main = async (): Promise<void> => {
81
+ await bundle({
82
+ mode: "nest",
83
+ repository: "nestia-start",
84
+ exceptions: [
85
+ ".git",
86
+ ".github/dependabot.yml",
87
+ "src/api/functional",
88
+ "src/controllers",
89
+ "src/MyModule.ts",
90
+ "src/providers",
91
+ "test/features",
92
+ ],
93
+ });
94
+ await bundle({
95
+ mode: "sdk",
96
+ repository: "nestia-sdk-template",
97
+ exceptions: [
98
+ ".git",
99
+ ".github/dependabot.yml",
100
+ ".github/workflows/build.yml",
101
+ "src/functional",
102
+ "src/structures",
103
+ "test/features",
104
+ ],
105
+ });
106
+ };
107
+ main().catch((exp) => {
108
+ console.error(exp);
109
+ process.exit(-1);
110
+ });
@@ -1,70 +1,70 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { format } from "prettier";
4
- import { IValidation } from "typia";
5
-
6
- import { MigrateApplication } from "../MigrateApplication";
7
- import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
8
- import { ISwagger } from "../structures/ISwagger";
9
- import { MigrateInquirer } from "./MigrateInquirer";
10
-
11
- export namespace MigrateCommander {
12
- export const main = async (): Promise<void> => {
13
- const resolve = (str: string | undefined) =>
14
- str ? path.resolve(str).split("\\").join("/") : undefined;
15
- const options: MigrateInquirer.IOutput = await MigrateInquirer.parse();
16
-
17
- // VALIDATE OUTPUT DIRECTORY
18
- const parent: string = resolve(options.output + "/..")!;
19
- if (fs.existsSync(options.output)) halt("Output directory alreay exists.");
20
- else if (fs.existsSync(parent) === false)
21
- halt("Output directory's parent directory does not exist.");
22
- else if (fs.statSync(parent).isDirectory() === false)
23
- halt("Output directory's parent is not a directory.");
24
-
25
- // READ SWAGGER
26
- const swagger: ISwagger = (() => {
27
- if (fs.existsSync(options.input) === false)
28
- halt("Unable to find the input swagger.json file.");
29
- const stats: fs.Stats = fs.statSync(options.input);
30
- if (stats.isFile() === false)
31
- halt("The input swagger.json is not a file.");
32
- const content: string = fs.readFileSync(options.input, "utf-8");
33
- const swagger: ISwagger = JSON.parse(content);
34
- return swagger;
35
- })();
36
-
37
- const result: IValidation<MigrateApplication> =
38
- await MigrateApplication.create(swagger);
39
- if (result.success === false) {
40
- console.log(result.errors);
41
- throw new Error(
42
- `Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
43
- );
44
- }
45
-
46
- const app: MigrateApplication = result.data;
47
- const { files } =
48
- options.mode === "nest" ? app.nest(options) : app.sdk(options);
49
- await MigrateFileArchiver.archive({
50
- mkdir: fs.promises.mkdir,
51
- writeFile: async (file, content) =>
52
- fs.promises.writeFile(file, await beautify(content), "utf-8"),
53
- })(options.output)(files);
54
- };
55
-
56
- const beautify = async (script: string): Promise<string> => {
57
- try {
58
- return await format(script, {
59
- parser: "typescript",
60
- });
61
- } catch {
62
- return script;
63
- }
64
- };
65
-
66
- const halt = (desc: string): never => {
67
- console.error(desc);
68
- process.exit(-1);
69
- };
70
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { format } from "prettier";
4
+ import { IValidation } from "typia";
5
+
6
+ import { MigrateApplication } from "../MigrateApplication";
7
+ import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
8
+ import { ISwagger } from "../structures/ISwagger";
9
+ import { MigrateInquirer } from "./MigrateInquirer";
10
+
11
+ export namespace MigrateCommander {
12
+ export const main = async (): Promise<void> => {
13
+ const resolve = (str: string | undefined) =>
14
+ str ? path.resolve(str).split("\\").join("/") : undefined;
15
+ const options: MigrateInquirer.IOutput = await MigrateInquirer.parse();
16
+
17
+ // VALIDATE OUTPUT DIRECTORY
18
+ const parent: string = resolve(options.output + "/..")!;
19
+ if (fs.existsSync(options.output)) halt("Output directory alreay exists.");
20
+ else if (fs.existsSync(parent) === false)
21
+ halt("Output directory's parent directory does not exist.");
22
+ else if (fs.statSync(parent).isDirectory() === false)
23
+ halt("Output directory's parent is not a directory.");
24
+
25
+ // READ SWAGGER
26
+ const swagger: ISwagger = (() => {
27
+ if (fs.existsSync(options.input) === false)
28
+ halt("Unable to find the input swagger.json file.");
29
+ const stats: fs.Stats = fs.statSync(options.input);
30
+ if (stats.isFile() === false)
31
+ halt("The input swagger.json is not a file.");
32
+ const content: string = fs.readFileSync(options.input, "utf-8");
33
+ const swagger: ISwagger = JSON.parse(content);
34
+ return swagger;
35
+ })();
36
+
37
+ const result: IValidation<MigrateApplication> =
38
+ await MigrateApplication.create(swagger);
39
+ if (result.success === false) {
40
+ console.log(result.errors);
41
+ throw new Error(
42
+ `Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
43
+ );
44
+ }
45
+
46
+ const app: MigrateApplication = result.data;
47
+ const { files } =
48
+ options.mode === "nest" ? app.nest(options) : app.sdk(options);
49
+ await MigrateFileArchiver.archive({
50
+ mkdir: fs.promises.mkdir,
51
+ writeFile: async (file, content) =>
52
+ fs.promises.writeFile(file, await beautify(content), "utf-8"),
53
+ })(options.output)(files);
54
+ };
55
+
56
+ const beautify = async (script: string): Promise<string> => {
57
+ try {
58
+ return await format(script, {
59
+ parser: "typescript",
60
+ });
61
+ } catch {
62
+ return script;
63
+ }
64
+ };
65
+
66
+ const halt = (desc: string): never => {
67
+ console.error(desc);
68
+ process.exit(-1);
69
+ };
70
+ }
@@ -1,86 +1,86 @@
1
- import commander from "commander";
2
- import inquirer from "inquirer";
3
-
4
- export namespace MigrateInquirer {
5
- export interface IOutput {
6
- mode: "nest" | "sdk";
7
- input: string;
8
- output: string;
9
- simulate: boolean;
10
- e2e: boolean;
11
- }
12
-
13
- export const parse = async (): Promise<IOutput> => {
14
- // PREPARE ASSETS
15
- commander.program.option("--mode [nest/sdk]", "migration mode");
16
- commander.program.option(
17
- "--input [swagger.json]",
18
- "location of target swagger.json file",
19
- );
20
- commander.program.option("--output [directory]", "output directory path");
21
- commander.program.option("--simulate", "Mockup simulator");
22
- commander.program.option("--e2e [boolean]", "Generate E2E tests");
23
-
24
- // INTERNAL PROCEDURES
25
- const questioned = { value: false };
26
- const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
27
- new Promise<IOutput>((resolve, reject) => {
28
- commander.program.action(async (options) => {
29
- try {
30
- resolve(await closure(options));
31
- } catch (exp) {
32
- reject(exp);
33
- }
34
- });
35
- commander.program.parseAsync().catch(reject);
36
- });
37
- const select =
38
- (name: string) =>
39
- (message: string) =>
40
- async <Choice extends string>(
41
- choices: Choice[],
42
- filter?: (value: string) => Choice,
43
- ): Promise<Choice> => {
44
- questioned.value = true;
45
- return (
46
- await inquirer.createPromptModule()({
47
- type: "list",
48
- name: name,
49
- message: message,
50
- choices: choices,
51
- filter,
52
- })
53
- )[name];
54
- };
55
- const input = (name: string) => async (message: string) =>
56
- (
57
- await inquirer.createPromptModule()({
58
- type: "input",
59
- name,
60
- message,
61
- })
62
- )[name];
63
-
64
- // DO CONSTRUCT
65
- return action(async (partial) => {
66
- partial.mode ??= await select("mode")("Migration mode")(
67
- ["NestJS" as "nest", "SDK" as "sdk"],
68
- (value) => (value === "NestJS" ? "nest" : "sdk"),
69
- );
70
- partial.input ??= await input("input")("Swagger file location");
71
- partial.output ??= await input("output")("Output directory path");
72
- if (partial.simulate)
73
- partial.simulate = (partial.simulate as any) === "true";
74
- else
75
- partial.simulate =
76
- (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
77
- "true";
78
- if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
79
- else
80
- partial.e2e =
81
- (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
82
- "true";
83
- return partial as IOutput;
84
- });
85
- };
86
- }
1
+ import commander from "commander";
2
+ import inquirer from "inquirer";
3
+
4
+ export namespace MigrateInquirer {
5
+ export interface IOutput {
6
+ mode: "nest" | "sdk";
7
+ input: string;
8
+ output: string;
9
+ simulate: boolean;
10
+ e2e: boolean;
11
+ }
12
+
13
+ export const parse = async (): Promise<IOutput> => {
14
+ // PREPARE ASSETS
15
+ commander.program.option("--mode [nest/sdk]", "migration mode");
16
+ commander.program.option(
17
+ "--input [swagger.json]",
18
+ "location of target swagger.json file",
19
+ );
20
+ commander.program.option("--output [directory]", "output directory path");
21
+ commander.program.option("--simulate", "Mockup simulator");
22
+ commander.program.option("--e2e [boolean]", "Generate E2E tests");
23
+
24
+ // INTERNAL PROCEDURES
25
+ const questioned = { value: false };
26
+ const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
27
+ new Promise<IOutput>((resolve, reject) => {
28
+ commander.program.action(async (options) => {
29
+ try {
30
+ resolve(await closure(options));
31
+ } catch (exp) {
32
+ reject(exp);
33
+ }
34
+ });
35
+ commander.program.parseAsync().catch(reject);
36
+ });
37
+ const select =
38
+ (name: string) =>
39
+ (message: string) =>
40
+ async <Choice extends string>(
41
+ choices: Choice[],
42
+ filter?: (value: string) => Choice,
43
+ ): Promise<Choice> => {
44
+ questioned.value = true;
45
+ return (
46
+ await inquirer.createPromptModule()({
47
+ type: "list",
48
+ name: name,
49
+ message: message,
50
+ choices: choices,
51
+ filter,
52
+ })
53
+ )[name];
54
+ };
55
+ const input = (name: string) => async (message: string) =>
56
+ (
57
+ await inquirer.createPromptModule()({
58
+ type: "input",
59
+ name,
60
+ message,
61
+ })
62
+ )[name];
63
+
64
+ // DO CONSTRUCT
65
+ return action(async (partial) => {
66
+ partial.mode ??= await select("mode")("Migration mode")(
67
+ ["NestJS" as "nest", "SDK" as "sdk"],
68
+ (value) => (value === "NestJS" ? "nest" : "sdk"),
69
+ );
70
+ partial.input ??= await input("input")("Swagger file location");
71
+ partial.output ??= await input("output")("Output directory path");
72
+ if (partial.simulate)
73
+ partial.simulate = (partial.simulate as any) === "true";
74
+ else
75
+ partial.simulate =
76
+ (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
77
+ "true";
78
+ if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
79
+ else
80
+ partial.e2e =
81
+ (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
82
+ "true";
83
+ return partial as IOutput;
84
+ });
85
+ };
86
+ }
package/src/module.ts CHANGED
@@ -1,14 +1,14 @@
1
- export * from "./MigrateApplication";
2
-
3
- export * from "./analyzers/MigrateAnalyzer";
4
-
5
- export * from "./archivers/MigrateFileArchiver";
6
-
7
- export * from "./structures/ISwagger";
8
- export * from "./structures/ISwaggerComponents";
9
- export * from "./structures/ISwaggerInfo";
10
- export * from "./structures/ISwaggerRoute";
11
- export * from "./structures/ISwaggerSecurityScheme";
12
- export * from "./structures/ISwaggerSchema";
13
- export * from "./structures/IMigrateProgram";
14
- export * from "./structures/IMigrateSchema";
1
+ export * from "./MigrateApplication";
2
+
3
+ export * from "./analyzers/MigrateAnalyzer";
4
+
5
+ export * from "./archivers/MigrateFileArchiver";
6
+
7
+ export * from "./structures/ISwagger";
8
+ export * from "./structures/ISwaggerComponents";
9
+ export * from "./structures/ISwaggerInfo";
10
+ export * from "./structures/ISwaggerRoute";
11
+ export * from "./structures/ISwaggerSecurityScheme";
12
+ export * from "./structures/ISwaggerSchema";
13
+ export * from "./structures/IMigrateProgram";
14
+ export * from "./structures/IMigrateSchema";
@@ -1,53 +1,53 @@
1
- import ts from "typescript";
2
-
3
- import { IMigrateController } from "../structures/IMigrateController";
4
- import { IMigrateProgram } from "../structures/IMigrateProgram";
5
- import { IMigrateRoute } from "../structures/IMigrateRoute";
6
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
7
- import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
8
- import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
9
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
-
11
- export namespace MigrateApiFileProgrammer {
12
- export interface IProps {
13
- namespace: string[];
14
- entries: IEntry[];
15
- children: Set<string>;
16
- }
17
- export interface IEntry {
18
- controller: IMigrateController;
19
- route: IMigrateRoute;
20
- alias: string;
21
- }
22
-
23
- export const write =
24
- (config: IMigrateProgram.IConfig) =>
25
- (components: ISwaggerComponents) =>
26
- (props: IProps): ts.Statement[] => {
27
- const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
28
- const statements: ts.Statement[] = props.entries
29
- .map((p) => [
30
- MigrateApiFunctionProgrammer.write(config)(components)(importer)(p),
31
- MigrateApiNamespaceProgrammer.write(config)(components)(importer)(p),
32
- ])
33
- .flat();
34
- return [
35
- ...importer.toStatements(
36
- (ref) =>
37
- `../${"../".repeat(props.namespace.length)}structures/${ref}`,
38
- ),
39
- ...[...props.children].map((child) =>
40
- ts.factory.createExportDeclaration(
41
- undefined,
42
- false,
43
- ts.factory.createNamespaceExport(
44
- ts.factory.createIdentifier(child),
45
- ),
46
- ts.factory.createStringLiteral(`./${child}`),
47
- undefined,
48
- ),
49
- ),
50
- ...statements,
51
- ];
52
- };
53
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMigrateController } from "../structures/IMigrateController";
4
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
5
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
6
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
7
+ import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
8
+ import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
9
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
10
+
11
+ export namespace MigrateApiFileProgrammer {
12
+ export interface IProps {
13
+ namespace: string[];
14
+ entries: IEntry[];
15
+ children: Set<string>;
16
+ }
17
+ export interface IEntry {
18
+ controller: IMigrateController;
19
+ route: IMigrateRoute;
20
+ alias: string;
21
+ }
22
+
23
+ export const write =
24
+ (config: IMigrateProgram.IConfig) =>
25
+ (components: ISwaggerComponents) =>
26
+ (props: IProps): ts.Statement[] => {
27
+ const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
28
+ const statements: ts.Statement[] = props.entries
29
+ .map((p) => [
30
+ MigrateApiFunctionProgrammer.write(config)(components)(importer)(p),
31
+ MigrateApiNamespaceProgrammer.write(config)(components)(importer)(p),
32
+ ])
33
+ .flat();
34
+ return [
35
+ ...importer.toStatements(
36
+ (ref) =>
37
+ `../${"../".repeat(props.namespace.length)}structures/${ref}`,
38
+ ),
39
+ ...[...props.children].map((child) =>
40
+ ts.factory.createExportDeclaration(
41
+ undefined,
42
+ false,
43
+ ts.factory.createNamespaceExport(
44
+ ts.factory.createIdentifier(child),
45
+ ),
46
+ ts.factory.createStringLiteral(`./${child}`),
47
+ undefined,
48
+ ),
49
+ ),
50
+ ...statements,
51
+ ];
52
+ };
53
+ }