@nestia/migrate 0.11.6 → 0.11.7

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.
@@ -1634,6 +1634,11 @@ class MigrateApplication {
1634
1634
  ...MigrateApiProgrammer_1.MigrateApiProgrammer.write(program),
1635
1635
  MigrateApiStartProgrammer_1.MigrateApiStartProgrammer.write(program),
1636
1636
  ...(config.e2e ? MigrateE2eProgrammer_1.MigrateE2eProgrammer.write(program) : []),
1637
+ {
1638
+ location: "",
1639
+ file: "swagger.json",
1640
+ content: JSON.stringify(this.swagger, null, 2),
1641
+ },
1637
1642
  ],
1638
1643
  };
1639
1644
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MigrateApplication.js","sourceRoot":"","sources":["../src/MigrateApplication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA2C;AAE3C,iEAA8D;AAC9D,2DAAwD;AACxD,yDAAsD;AACtD,6EAA0E;AAC1E,uFAAoF;AACpF,6EAA0E;AAC1E,+EAA4E;AAK5E,+DAA4D;AAE5D,MAAa,kBAAkB;IAC7B,YAAoC,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;IAAG,CAAC;IAElD,MAAM,CAAO,MAAM,CACxB,OAA+B;;YAE/B,OAAO,GAAG;;;eAA+B,OAAO,EAC9C,CAAC,CAAC,mCAAgB,CAAC,IAAI,CAAC,OAAO,CAAC;gBAChC,CAAC,CAAC,OAAO,CAAC;YACZ,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAAG,eAAK,CAAC,QAAQ;;sCAAd,eAAK,CAAC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,2CAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3D;SACF,CAAC;IACJ,CAAC;IAEM,GAAG,CAAC,MAAkC;QAC3C,MAAM,OAAO,GAAoB,iCAAe,CAAC,OAAO,CAAC;YACvD,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,GAAG,EAAE;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,GAAG;SAChB,CAAC,CAAC;QACH,OAAO;YACL,OAAO;YACP,KAAK,EAAE;gBACL,GAAG,2BAAY;gBACf,GAAG,2CAAoB,CAAC,KAAK,CAAC,OAAO,CAAC;gBACtC,qDAAyB,CAAC,KAAK,CAAC,OAAO,CAAC;gBACxC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,2CAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1D;oBACE,QAAQ,EAAE,EAAE;oBACZ,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;iBAC/C;aACF;SACF,CAAC;IACJ,CAAC;CACF;AA5DD,gDA4DC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/migrate",
3
- "version": "0.11.6",
3
+ "version": "0.11.7",
4
4
  "description": "Migration program from swagger to NestJS",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -65,6 +65,11 @@ export class MigrateApplication {
65
65
  ...MigrateApiProgrammer.write(program),
66
66
  MigrateApiStartProgrammer.write(program),
67
67
  ...(config.e2e ? MigrateE2eProgrammer.write(program) : []),
68
+ {
69
+ location: "",
70
+ file: "swagger.json",
71
+ content: JSON.stringify(this.swagger, null, 2),
72
+ },
68
73
  ],
69
74
  };
70
75
  }
@@ -1,194 +1,194 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
- import { StatementFactory } from "typia/lib/factories/StatementFactory";
4
-
5
- import { IMigrateFile } from "../structures/IMigrateFile";
6
- import { IMigrateProgram } from "../structures/IMigrateProgram";
7
- import { IMigrateRoute } from "../structures/IMigrateRoute";
8
- import { ISwagger } from "../structures/ISwagger";
9
- import { FilePrinter } from "../utils/FilePrinter";
10
- import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
11
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
-
13
- export namespace MigrateApiStartProgrammer {
14
- export const write = (program: IMigrateProgram): IMigrateFile => {
15
- const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
16
- const main: ts.VariableStatement = writeMain(program)(program.swagger)(
17
- importer,
18
- )(pick(program.controllers.map((c) => c.routes).flat()));
19
- const statements: ts.Statement[] = [
20
- ...importer.toStatements(
21
- (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
22
- ),
23
- FilePrinter.newLine(),
24
- ts.factory.createImportDeclaration(
25
- undefined,
26
- ts.factory.createImportClause(
27
- false,
28
- undefined,
29
- ts.factory.createNamedImports([
30
- ts.factory.createImportSpecifier(
31
- false,
32
- undefined,
33
- ts.factory.createIdentifier("TestGlobal"),
34
- ),
35
- ]),
36
- ),
37
- ts.factory.createStringLiteral("./TestGlobal"),
38
- undefined,
39
- ),
40
- FilePrinter.newLine(),
41
- main,
42
- ts.factory.createExpressionStatement(writeStarter()),
43
- ];
44
- return {
45
- location: `test`,
46
- file: "start.ts",
47
- content: FilePrinter.write({ statements }),
48
- };
49
- };
50
-
51
- const writeMain =
52
- (config: IMigrateProgram.IConfig) =>
53
- (swagger: ISwagger) =>
54
- (importer: MigrateImportProgrammer) =>
55
- (route: IMigrateRoute): ts.VariableStatement =>
56
- StatementFactory.constant(
57
- "main",
58
- ts.factory.createArrowFunction(
59
- [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
- undefined,
61
- [],
62
- undefined,
63
- undefined,
64
- ts.factory.createBlock(
65
- [
66
- writeConnection(config)(swagger)(importer),
67
- ...MigrateE2eFunctionProgrammer.writeBody(swagger.components)(
68
- importer,
69
- )(route),
70
- ],
71
- true,
72
- ),
73
- ),
74
- );
75
-
76
- const writeConnection =
77
- (config: IMigrateProgram.IConfig) =>
78
- (swagger: ISwagger) =>
79
- (importer: MigrateImportProgrammer): ts.VariableStatement =>
80
- ts.factory.createVariableStatement(
81
- undefined,
82
- ts.factory.createVariableDeclarationList(
83
- [
84
- ts.factory.createVariableDeclaration(
85
- "connection",
86
- undefined,
87
- ts.factory.createTypeReferenceNode(
88
- ts.factory.createQualifiedName(
89
- ts.factory.createIdentifier(
90
- importer.external({
91
- type: "default",
92
- library: "@ORGANIZATION/PROJECT-api",
93
- name: "api",
94
- }),
95
- ),
96
- ts.factory.createIdentifier("IConnection"),
97
- ),
98
- ),
99
- ts.factory.createObjectLiteralExpression(
100
- [
101
- ts.factory.createSpreadAssignment(
102
- ts.factory.createCallExpression(
103
- ts.factory.createPropertyAccessExpression(
104
- ts.factory.createIdentifier("TestGlobal"),
105
- "connection",
106
- ),
107
- undefined,
108
- undefined,
109
- ),
110
- ),
111
- ...(swagger.servers[0]?.url?.length
112
- ? [
113
- ts.factory.createPropertyAssignment(
114
- "host",
115
- ts.factory.createStringLiteral(
116
- swagger.servers[0].url,
117
- ),
118
- ),
119
- ]
120
- : []),
121
- ...(config.simulate === true
122
- ? [
123
- ts.factory.createPropertyAssignment(
124
- "simulate",
125
- ts.factory.createTrue(),
126
- ),
127
- ]
128
- : []),
129
- ],
130
- true,
131
- ),
132
- ),
133
- ],
134
- ts.NodeFlags.Const,
135
- ),
136
- );
137
-
138
- const writeStarter = (): ts.CallExpression =>
139
- ts.factory.createCallExpression(
140
- ts.factory.createPropertyAccessExpression(
141
- ts.factory.createCallExpression(
142
- ts.factory.createIdentifier("main"),
143
- undefined,
144
- undefined,
145
- ),
146
- "catch",
147
- ),
148
- undefined,
149
- [
150
- ts.factory.createArrowFunction(
151
- undefined,
152
- undefined,
153
- [IdentifierFactory.parameter("exp")],
154
- undefined,
155
- undefined,
156
- ts.factory.createBlock(
157
- [
158
- ts.factory.createExpressionStatement(
159
- ts.factory.createCallExpression(
160
- ts.factory.createPropertyAccessExpression(
161
- ts.factory.createIdentifier("console"),
162
- "log",
163
- ),
164
- undefined,
165
- [ts.factory.createIdentifier("exp")],
166
- ),
167
- ),
168
- ts.factory.createExpressionStatement(
169
- ts.factory.createCallExpression(
170
- ts.factory.createPropertyAccessExpression(
171
- ts.factory.createIdentifier("process"),
172
- "exit",
173
- ),
174
- undefined,
175
- [
176
- ts.factory.createPrefixMinus(
177
- ts.factory.createNumericLiteral("1"),
178
- ),
179
- ],
180
- ),
181
- ),
182
- ],
183
- true,
184
- ),
185
- ),
186
- ],
187
- );
188
- }
189
-
190
- const pick = <T>(array: T[]): T => {
191
- const rand: number = Math.random() * array.length;
192
- const index: number = Math.min(array.length - 1, Math.floor(rand));
193
- return array[index];
194
- };
1
+ import ts from "typescript";
2
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
4
+
5
+ import { IMigrateFile } from "../structures/IMigrateFile";
6
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
7
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
8
+ import { ISwagger } from "../structures/ISwagger";
9
+ import { FilePrinter } from "../utils/FilePrinter";
10
+ import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
11
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
+
13
+ export namespace MigrateApiStartProgrammer {
14
+ export const write = (program: IMigrateProgram): IMigrateFile => {
15
+ const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
16
+ const main: ts.VariableStatement = writeMain(program)(program.swagger)(
17
+ importer,
18
+ )(pick(program.controllers.map((c) => c.routes).flat()));
19
+ const statements: ts.Statement[] = [
20
+ ...importer.toStatements(
21
+ (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
22
+ ),
23
+ FilePrinter.newLine(),
24
+ ts.factory.createImportDeclaration(
25
+ undefined,
26
+ ts.factory.createImportClause(
27
+ false,
28
+ undefined,
29
+ ts.factory.createNamedImports([
30
+ ts.factory.createImportSpecifier(
31
+ false,
32
+ undefined,
33
+ ts.factory.createIdentifier("TestGlobal"),
34
+ ),
35
+ ]),
36
+ ),
37
+ ts.factory.createStringLiteral("./TestGlobal"),
38
+ undefined,
39
+ ),
40
+ FilePrinter.newLine(),
41
+ main,
42
+ ts.factory.createExpressionStatement(writeStarter()),
43
+ ];
44
+ return {
45
+ location: `test`,
46
+ file: "start.ts",
47
+ content: FilePrinter.write({ statements }),
48
+ };
49
+ };
50
+
51
+ const writeMain =
52
+ (config: IMigrateProgram.IConfig) =>
53
+ (swagger: ISwagger) =>
54
+ (importer: MigrateImportProgrammer) =>
55
+ (route: IMigrateRoute): ts.VariableStatement =>
56
+ StatementFactory.constant(
57
+ "main",
58
+ ts.factory.createArrowFunction(
59
+ [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
+ undefined,
61
+ [],
62
+ undefined,
63
+ undefined,
64
+ ts.factory.createBlock(
65
+ [
66
+ writeConnection(config)(swagger)(importer),
67
+ ...MigrateE2eFunctionProgrammer.writeBody(swagger.components)(
68
+ importer,
69
+ )(route),
70
+ ],
71
+ true,
72
+ ),
73
+ ),
74
+ );
75
+
76
+ const writeConnection =
77
+ (config: IMigrateProgram.IConfig) =>
78
+ (swagger: ISwagger) =>
79
+ (importer: MigrateImportProgrammer): ts.VariableStatement =>
80
+ ts.factory.createVariableStatement(
81
+ undefined,
82
+ ts.factory.createVariableDeclarationList(
83
+ [
84
+ ts.factory.createVariableDeclaration(
85
+ "connection",
86
+ undefined,
87
+ ts.factory.createTypeReferenceNode(
88
+ ts.factory.createQualifiedName(
89
+ ts.factory.createIdentifier(
90
+ importer.external({
91
+ type: "default",
92
+ library: "@ORGANIZATION/PROJECT-api",
93
+ name: "api",
94
+ }),
95
+ ),
96
+ ts.factory.createIdentifier("IConnection"),
97
+ ),
98
+ ),
99
+ ts.factory.createObjectLiteralExpression(
100
+ [
101
+ ts.factory.createSpreadAssignment(
102
+ ts.factory.createCallExpression(
103
+ ts.factory.createPropertyAccessExpression(
104
+ ts.factory.createIdentifier("TestGlobal"),
105
+ "connection",
106
+ ),
107
+ undefined,
108
+ undefined,
109
+ ),
110
+ ),
111
+ ...(swagger.servers[0]?.url?.length
112
+ ? [
113
+ ts.factory.createPropertyAssignment(
114
+ "host",
115
+ ts.factory.createStringLiteral(
116
+ swagger.servers[0].url,
117
+ ),
118
+ ),
119
+ ]
120
+ : []),
121
+ ...(config.simulate === true
122
+ ? [
123
+ ts.factory.createPropertyAssignment(
124
+ "simulate",
125
+ ts.factory.createTrue(),
126
+ ),
127
+ ]
128
+ : []),
129
+ ],
130
+ true,
131
+ ),
132
+ ),
133
+ ],
134
+ ts.NodeFlags.Const,
135
+ ),
136
+ );
137
+
138
+ const writeStarter = (): ts.CallExpression =>
139
+ ts.factory.createCallExpression(
140
+ ts.factory.createPropertyAccessExpression(
141
+ ts.factory.createCallExpression(
142
+ ts.factory.createIdentifier("main"),
143
+ undefined,
144
+ undefined,
145
+ ),
146
+ "catch",
147
+ ),
148
+ undefined,
149
+ [
150
+ ts.factory.createArrowFunction(
151
+ undefined,
152
+ undefined,
153
+ [IdentifierFactory.parameter("exp")],
154
+ undefined,
155
+ undefined,
156
+ ts.factory.createBlock(
157
+ [
158
+ ts.factory.createExpressionStatement(
159
+ ts.factory.createCallExpression(
160
+ ts.factory.createPropertyAccessExpression(
161
+ ts.factory.createIdentifier("console"),
162
+ "log",
163
+ ),
164
+ undefined,
165
+ [ts.factory.createIdentifier("exp")],
166
+ ),
167
+ ),
168
+ ts.factory.createExpressionStatement(
169
+ ts.factory.createCallExpression(
170
+ ts.factory.createPropertyAccessExpression(
171
+ ts.factory.createIdentifier("process"),
172
+ "exit",
173
+ ),
174
+ undefined,
175
+ [
176
+ ts.factory.createPrefixMinus(
177
+ ts.factory.createNumericLiteral("1"),
178
+ ),
179
+ ],
180
+ ),
181
+ ),
182
+ ],
183
+ true,
184
+ ),
185
+ ),
186
+ ],
187
+ );
188
+ }
189
+
190
+ const pick = <T>(array: T[]): T => {
191
+ const rand: number = Math.random() * array.length;
192
+ const index: number = Math.min(array.length - 1, Math.floor(rand));
193
+ return array[index];
194
+ };