@nestia/migrate 0.13.0 → 0.13.2
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.
- package/lib/MigrateApplication.js +45 -9
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateMethodAnalyzer.js +19 -3
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.js +3 -4
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
- package/package.json +5 -6
- package/src/analyzers/MigrateControllerAnalyzer.ts +137 -137
- package/src/analyzers/MigrateMethodAnalyzer.ts +383 -363
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/internal/MigrateCommander.ts +76 -70
- package/src/module.ts +8 -8
- package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
- package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
- package/src/programmers/MigrateApiProgrammer.ts +172 -172
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
- package/src/programmers/MigrateDtoProgrammer.ts +77 -77
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +36 -36
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/structures/IMigrateDto.ts +8 -8
- package/src/structures/IMigrateProgram.ts +27 -27
- package/src/structures/IMigrateRoute.ts +51 -51
- package/src/utils/OpenApiTypeChecker.ts +73 -73
@@ -47,7 +47,7 @@ export const NEST_TEMPLATE = [
|
|
47
47
|
{
|
48
48
|
"location": "",
|
49
49
|
"file": "package.json",
|
50
|
-
"content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.3\",\r\n \"@nestia/sdk\": \"^3.0.
|
50
|
+
"content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.3\",\r\n \"@nestia/sdk\": \"^3.0.1\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/cli\": \"^0.11.21\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"^8.2.5\",\r\n \"@types/node\": \"^18.11.0\",\r\n \"@types/uuid\": \"^8.3.4\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.1\",\r\n \"@typescript-eslint/parser\": \"^6.19.1\",\r\n \"chalk\": \"^4.1.0\",\r\n \"cli\": \"^1.0.1\",\r\n \"copy-webpack-plugin\": \"^11.0.0\",\r\n \"eslint-plugin-deprecation\": \"^2.0.0\",\r\n \"express\": \"^4.18.2\",\r\n \"nestia\": \"^5.3.0\",\r\n \"prettier\": \"^3.2.4\",\r\n \"prettier-plugin-prisma\": \"^5.0.0\",\r\n \"rimraf\": \"^3.0.2\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-loader\": \"^9.5.1\",\r\n \"ts-node\": \"^10.9.1\",\r\n \"ts-patch\": \"^3.0.2\",\r\n \"typescript\": \"^5.3.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\",\r\n \"webpack\": \"^5.89.0\",\r\n \"webpack-cli\": \"^5.1.4\",\r\n \"write-file-webpack-plugin\": \"^4.5.1\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/core\": \"^3.0.1\",\r\n \"@nestia/fetcher\": \"^3.0.1\",\r\n \"@nestjs/common\": \"^10.3.7\",\r\n \"@nestjs/core\": \"^10.3.7\",\r\n \"@nestjs/platform-express\": \"^10.3.7\",\r\n \"commander\": \"10.0.0\",\r\n \"dotenv\": \"^16.3.1\",\r\n \"dotenv-expand\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"serialize-error\": \"^4.1.0\",\r\n \"tstl\": \"^3.0.0\",\r\n \"typia\": \"^6.0.1\",\r\n \"uuid\": \"^9.0.0\"\r\n },\r\n \"stackblitz\": {\r\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test\"\r\n }\r\n}"
|
51
51
|
},
|
52
52
|
{
|
53
53
|
"location": "packages/api",
|
@@ -62,7 +62,7 @@ export const NEST_TEMPLATE = [
|
|
62
62
|
{
|
63
63
|
"location": "packages/api",
|
64
64
|
"file": "package.json",
|
65
|
-
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.0.
|
65
|
+
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.0.1\",\r\n \"typia\": \"^6.0.1\"\r\n }\r\n}"
|
66
66
|
},
|
67
67
|
{
|
68
68
|
"location": "packages/api",
|
@@ -27,7 +27,7 @@ export const SDK_TEMPLATE = [
|
|
27
27
|
{
|
28
28
|
"location": "",
|
29
29
|
"file": "package.json",
|
30
|
-
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"exports\": {\r\n \".\": {\r\n \"types\": \"./lib/index.d.ts\",\r\n \"require\": \"./lib/index.js\",\r\n \"import\": \"./lib/index.mjs\"\r\n }\r\n },\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc && rollup -c\",\r\n \"build:test\": \"rimraf bin && tsc --project test/tsconfig.json\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"hello\": \"node hello\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"start\": \"ts-node test/start.ts\",\r\n \"swagger\": \"ts-node test/swagger.ts\",\r\n \"test\": \"ts-node test/index.ts\",\r\n \"test:simulate\": \"ts-node test/index.ts --simulate true\",\r\n \"test:manual\": \"ts-node test/manual.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.0.
|
30
|
+
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"exports\": {\r\n \".\": {\r\n \"types\": \"./lib/index.d.ts\",\r\n \"require\": \"./lib/index.js\",\r\n \"import\": \"./lib/index.mjs\"\r\n }\r\n },\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc && rollup -c\",\r\n \"build:test\": \"rimraf bin && tsc --project test/tsconfig.json\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"hello\": \"node hello\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"start\": \"ts-node test/start.ts\",\r\n \"swagger\": \"ts-node test/swagger.ts\",\r\n \"test\": \"ts-node test/index.ts\",\r\n \"test:simulate\": \"ts-node test/index.ts --simulate true\",\r\n \"test:manual\": \"ts-node test/manual.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^3.0.1\",\r\n \"typia\": \"^6.0.1\"\r\n },\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.3\",\r\n \"@rollup/plugin-terser\": \"^0.4.4\",\r\n \"@rollup/plugin-typescript\": \"^11.1.6\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"8.2.5\",\r\n \"@types/swagger-ui-express\": \"^4.1.6\",\r\n \"commander\": \"^10.0.0\",\r\n \"express\": \"^4.19.2\",\r\n \"inquirer\": \"8.2.5\",\r\n \"prettier\": \"^3.2.5\",\r\n \"rimraf\": \"^5.0.5\",\r\n \"rollup\": \"^4.13.2\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\",\r\n \"typescript-transform-paths\": \"^3.4.6\"\r\n }\r\n}"
|
31
31
|
},
|
32
32
|
{
|
33
33
|
"location": "",
|
@@ -1,70 +1,76 @@
|
|
1
|
-
import {
|
2
|
-
import fs from "fs";
|
3
|
-
import path from "path";
|
4
|
-
import { format } from "prettier";
|
5
|
-
import { IValidation } from "typia";
|
6
|
-
|
7
|
-
import { MigrateApplication } from "../MigrateApplication";
|
8
|
-
import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
|
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 document:
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (
|
31
|
-
halt("
|
32
|
-
const
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
}
|
1
|
+
import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
|
2
|
+
import fs from "fs";
|
3
|
+
import path from "path";
|
4
|
+
import { format } from "prettier";
|
5
|
+
import { IValidation } from "typia";
|
6
|
+
|
7
|
+
import { MigrateApplication } from "../MigrateApplication";
|
8
|
+
import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
|
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 document:
|
27
|
+
| SwaggerV2.IDocument
|
28
|
+
| OpenApiV3.IDocument
|
29
|
+
| OpenApiV3_1.IDocument = (() => {
|
30
|
+
if (fs.existsSync(options.input) === false)
|
31
|
+
halt("Unable to find the input swagger.json file.");
|
32
|
+
const stats: fs.Stats = fs.statSync(options.input);
|
33
|
+
if (stats.isFile() === false)
|
34
|
+
halt("The input swagger.json is not a file.");
|
35
|
+
const content: string = fs.readFileSync(options.input, "utf-8");
|
36
|
+
const swagger:
|
37
|
+
| SwaggerV2.IDocument
|
38
|
+
| OpenApiV3.IDocument
|
39
|
+
| OpenApiV3_1.IDocument = JSON.parse(content);
|
40
|
+
return swagger;
|
41
|
+
})();
|
42
|
+
|
43
|
+
const result: IValidation<MigrateApplication> =
|
44
|
+
await MigrateApplication.create(document);
|
45
|
+
if (result.success === false) {
|
46
|
+
console.log(result.errors);
|
47
|
+
throw new Error(
|
48
|
+
`Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
|
49
|
+
);
|
50
|
+
}
|
51
|
+
|
52
|
+
const app: MigrateApplication = result.data;
|
53
|
+
const { files } =
|
54
|
+
options.mode === "nest" ? app.nest(options) : app.sdk(options);
|
55
|
+
await MigrateFileArchiver.archive({
|
56
|
+
mkdir: fs.promises.mkdir,
|
57
|
+
writeFile: async (file, content) =>
|
58
|
+
fs.promises.writeFile(file, await beautify(content), "utf-8"),
|
59
|
+
})(options.output)(files);
|
60
|
+
};
|
61
|
+
|
62
|
+
const beautify = async (script: string): Promise<string> => {
|
63
|
+
try {
|
64
|
+
return await format(script, {
|
65
|
+
parser: "typescript",
|
66
|
+
});
|
67
|
+
} catch {
|
68
|
+
return script;
|
69
|
+
}
|
70
|
+
};
|
71
|
+
|
72
|
+
const halt = (desc: string): never => {
|
73
|
+
console.error(desc);
|
74
|
+
process.exit(-1);
|
75
|
+
};
|
76
|
+
}
|
package/src/module.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
export * from "./MigrateApplication";
|
2
|
-
|
3
|
-
export * from "./analyzers/MigrateAnalyzer";
|
4
|
-
|
5
|
-
export * from "./archivers/MigrateFileArchiver";
|
6
|
-
|
7
|
-
export * from "./structures/IMigrateProgram";
|
8
|
-
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/IMigrateProgram";
|
8
|
+
export * from "./structures/IMigrateSchema";
|
@@ -1,53 +1,53 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
|
4
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
5
|
-
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
6
|
-
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
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: OpenApi.IComponents) =>
|
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 { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
|
4
|
+
import { IMigrateController } from "../structures/IMigrateController";
|
5
|
+
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
6
|
+
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
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: OpenApi.IComponents) =>
|
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
|
+
}
|