@nestia/migrate 0.6.3 → 0.7.0-dev.20240201
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/IMigrateConfig.d.ts +1 -0
- package/lib/MigrateApplication.d.ts +3 -15
- package/lib/MigrateApplication.js +21 -62
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.d.ts +5 -0
- package/{src/bundles/TEMPLATE.ts → lib/bundles/NEST_TEMPLATE.js} +71 -27
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -0
- package/lib/bundles/SDK_TEMPLATE.d.ts +5 -0
- package/lib/bundles/SDK_TEMPLATE.js +61 -0
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -0
- package/lib/bundles/TEMPLATE.d.ts +1 -1
- package/lib/bundles/TEMPLATE.js +23 -23
- package/lib/bundles/TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js +70 -51
- package/lib/executable/bundle.js.map +1 -1
- package/lib/executable/migrate.js +2 -62
- package/lib/executable/migrate.js.map +1 -1
- package/lib/internal/MigrateCli.d.ts +3 -0
- package/lib/internal/MigrateCli.js +59 -0
- package/lib/internal/MigrateCli.js.map +1 -0
- package/lib/internal/{MigrateArguments.d.ts → MigrateCommander.d.ts} +2 -1
- package/lib/internal/{MigrateArguments.js → MigrateCommander.js} +23 -20
- package/lib/internal/MigrateCommander.js.map +1 -0
- package/lib/programmers/ApiProgrammer.js +47 -2
- package/lib/programmers/ApiProgrammer.js.map +1 -1
- package/package.json +3 -2
- package/src/IMigrateConfig.ts +1 -0
- package/src/MigrateApplication.ts +20 -67
- package/src/bundles/NEST_TEMPLATE.ts +202 -0
- package/src/bundles/SDK_TEMPLATE.ts +57 -0
- package/src/executable/bundle.ts +80 -50
- package/src/executable/migrate.ts +2 -60
- package/src/internal/MigrateCommander.ts +52 -0
- package/src/internal/{MigrateArguments.ts → MigrateInquirer.ts} +12 -7
- package/src/programmers/ApiProgrammer.ts +60 -2
- package/lib/internal/MigrateArguments.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/executable/migrate.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/executable/migrate.ts"],"names":[],"mappings":";;;AACA,uDAAoD;AAEpD,uBAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IAC9B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.MigrateCli = void 0;
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
17
|
+
const path_1 = __importDefault(require("path"));
|
18
|
+
const FileArchiver_1 = require("../archivers/FileArchiver");
|
19
|
+
const module_1 = require("../module");
|
20
|
+
const MigrateCommander_1 = require("./MigrateCommander");
|
21
|
+
var MigrateCli;
|
22
|
+
(function (MigrateCli) {
|
23
|
+
MigrateCli.main = () => __awaiter(this, void 0, void 0, function* () {
|
24
|
+
const resolve = (str) => str ? path_1.default.resolve(str).split("\\").join("/") : undefined;
|
25
|
+
const options = yield MigrateCommander_1.MigrateCommander.parse();
|
26
|
+
// VALIDATE OUTPUT DIRECTORY
|
27
|
+
const parent = resolve(options.output + "/..");
|
28
|
+
if (fs_1.default.existsSync(options.output))
|
29
|
+
halt("Output directory alreay exists.");
|
30
|
+
else if (fs_1.default.existsSync(parent) === false)
|
31
|
+
halt("Output directory's parent directory does not exist.");
|
32
|
+
else if (fs_1.default.statSync(parent).isDirectory() === false)
|
33
|
+
halt("Output directory's parent is not a directory.");
|
34
|
+
// READ SWAGGER
|
35
|
+
const swagger = (() => {
|
36
|
+
if (fs_1.default.existsSync(options.input) === false)
|
37
|
+
halt("Unable to find the input swagger.json file.");
|
38
|
+
const stats = fs_1.default.statSync(options.input);
|
39
|
+
if (stats.isFile() === false)
|
40
|
+
halt("The input swagger.json is not a file.");
|
41
|
+
const content = fs_1.default.readFileSync(options.input, "utf-8");
|
42
|
+
const swagger = JSON.parse(content);
|
43
|
+
return swagger;
|
44
|
+
})();
|
45
|
+
const app = new module_1.MigrateApplication(swagger);
|
46
|
+
const files = options.mode === "nest"
|
47
|
+
? app.nest(options.simulate)
|
48
|
+
: app.sdk(options.simulate);
|
49
|
+
yield FileArchiver_1.FileArchiver.archive({
|
50
|
+
mkdir: fs_1.default.promises.mkdir,
|
51
|
+
writeFile: (file, content) => fs_1.default.promises.writeFile(file, content, "utf-8"),
|
52
|
+
})(options.output)(files);
|
53
|
+
});
|
54
|
+
const halt = (desc) => {
|
55
|
+
console.error(desc);
|
56
|
+
process.exit(-1);
|
57
|
+
};
|
58
|
+
})(MigrateCli || (exports.MigrateCli = MigrateCli = {}));
|
59
|
+
//# sourceMappingURL=MigrateCli.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MigrateCli.js","sourceRoot":"","sources":["../../src/internal/MigrateCli.ts"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,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAChE,MAAM,OAAO,GAAa,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC9C,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,EAAE,CAAC;QAEL,MAAM,GAAG,GAAuB,IAAI,2BAAkB,CAAC,OAAO,CAAC,CAAC;QAChE,MAAM,KAAK,GACT,OAAO,CAAC,IAAI,KAAK,MAAM;YACrB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAC5B,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,2BAAY,CAAC,OAAO,CAAC;YACzB,KAAK,EAAE,YAAE,CAAC,QAAQ,CAAC,KAAK;YACxB,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAC3B,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC;SAChD,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC,CAAA,CAAC;IAEF,MAAM,IAAI,GAAG,CAAC,IAAY,EAAS,EAAE;QACnC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC,EA1CgB,UAAU,0BAAV,UAAU,QA0C1B"}
|
@@ -12,31 +12,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
15
|
+
exports.MigrateCommander = void 0;
|
16
16
|
const commander_1 = __importDefault(require("commander"));
|
17
17
|
const inquirer_1 = __importDefault(require("inquirer"));
|
18
|
-
var
|
19
|
-
(function (
|
20
|
-
|
18
|
+
var MigrateCommander;
|
19
|
+
(function (MigrateCommander) {
|
20
|
+
MigrateCommander.parse = () => __awaiter(this, void 0, void 0, function* () {
|
21
21
|
// PREPARE ASSETS
|
22
|
-
commander_1.default.program.option("--
|
22
|
+
commander_1.default.program.option("--mode [nest/sdk]", "migration mode");
|
23
23
|
commander_1.default.program.option("--input [swagger.json]", "location of target swagger.json file");
|
24
24
|
commander_1.default.program.option("--output [directory]", "output directory path");
|
25
|
+
commander_1.default.program.option("--simulate", "Mockup simulator");
|
25
26
|
// INTERNAL PROCEDURES
|
26
27
|
const questioned = { value: false };
|
27
|
-
const action = (closure) => {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
});
|
39
|
-
};
|
28
|
+
const action = (closure) => new Promise((resolve, reject) => {
|
29
|
+
commander_1.default.program.action((options) => __awaiter(this, void 0, void 0, function* () {
|
30
|
+
try {
|
31
|
+
resolve(yield closure(options));
|
32
|
+
}
|
33
|
+
catch (exp) {
|
34
|
+
reject(exp);
|
35
|
+
}
|
36
|
+
}));
|
37
|
+
commander_1.default.program.parseAsync().catch(reject);
|
38
|
+
});
|
40
39
|
const select = (name) => (message) => (choices, filter) => __awaiter(this, void 0, void 0, function* () {
|
41
40
|
questioned.value = true;
|
42
41
|
return (yield inquirer_1.default.createPromptModule()({
|
@@ -60,8 +59,12 @@ var MigrateArguments;
|
|
60
59
|
(_a = partial.mode) !== null && _a !== void 0 ? _a : (partial.mode = yield select("mode")("Migration mode")(["NestJS", "SDK"], (value) => (value === "NestJS" ? "nest" : "sdk")));
|
61
60
|
(_b = partial.input) !== null && _b !== void 0 ? _b : (partial.input = yield input("input")("Swagger file location"));
|
62
61
|
(_c = partial.output) !== null && _c !== void 0 ? _c : (partial.output = yield input("output")("Output directory path"));
|
62
|
+
if (partial.simulate)
|
63
|
+
partial.simulate = partial.simulate === "true";
|
64
|
+
else
|
65
|
+
partial.simulate = yield select("simulate")("Mokup Simulator")(["true", "false"], (str) => str === "Y");
|
63
66
|
return partial;
|
64
67
|
}));
|
65
68
|
});
|
66
|
-
})(
|
67
|
-
//# sourceMappingURL=
|
69
|
+
})(MigrateCommander || (exports.MigrateCommander = MigrateCommander = {}));
|
70
|
+
//# sourceMappingURL=MigrateCommander.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MigrateCommander.js","sourceRoot":"","sources":["../../src/internal/MigrateCommander.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAkC;AAClC,wDAAgC;AAEhC,IAAiB,gBAAgB,CA4EhC;AA5ED,WAAiB,gBAAgB;IAQlB,sBAAK,GAAG,GAA2B,EAAE;QAChD,iBAAiB;QACjB,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;QAChE,mBAAS,CAAC,OAAO,CAAC,MAAM,CACtB,wBAAwB,EACxB,sCAAsC,CACvC,CAAC;QACF,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,EAAE,uBAAuB,CAAC,CAAC;QAC1E,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;QAE3D,sBAAsB;QACtB,MAAM,UAAU,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,CAAC,OAAwD,EAAE,EAAE,CAC1E,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACvC,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAO,OAAO,EAAE,EAAE;gBACzC,IAAI,CAAC;oBACH,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;gBAClC,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,CAAC,GAAG,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,CAAC,EAAC;YAChE,MAAA,OAAO,CAAC,MAAM,oCAAd,OAAO,CAAC,MAAM,GAAK,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC,uBAAuB,CAAC,EAAC;YAClE,IAAI,OAAO,CAAC,QAAQ;gBAClB,OAAO,CAAC,QAAQ,GAAI,OAAO,CAAC,QAAgB,KAAK,MAAM,CAAC;;gBAExD,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC,iBAAiB,CAAC,CAC5D,CAAC,MAAa,EAAE,OAAc,CAAC,EAC/B,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,CACrB,CAAC;YACJ,OAAO,OAAkB,CAAC;QAC5B,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAA,CAAC;AACJ,CAAC,EA5EgB,gBAAgB,gCAAhB,gBAAgB,QA4EhC"}
|
@@ -1,11 +1,17 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.ApiProgrammer = void 0;
|
4
7
|
const tstl_1 = require("tstl");
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
5
9
|
const Escaper_1 = require("typia/lib/utils/Escaper");
|
6
10
|
const FilePrinter_1 = require("../utils/FilePrinter");
|
7
11
|
const StringUtil_1 = require("../utils/StringUtil");
|
8
12
|
const ApiFileProgrammer_1 = require("./ApiFileProgrammer");
|
13
|
+
const DtoProgrammer_1 = require("./DtoProgrammer");
|
14
|
+
const ImportProgrammer_1 = require("./ImportProgrammer");
|
9
15
|
var ApiProgrammer;
|
10
16
|
(function (ApiProgrammer) {
|
11
17
|
ApiProgrammer.write = (program) => {
|
@@ -41,6 +47,13 @@ var ApiProgrammer;
|
|
41
47
|
props.children.add(last.value.namespace.at(-1));
|
42
48
|
last.value = props;
|
43
49
|
});
|
50
|
+
const top = dict.take([], () => ({
|
51
|
+
namespace: [],
|
52
|
+
children: new Set(),
|
53
|
+
entries: [],
|
54
|
+
}));
|
55
|
+
if (namespace.length)
|
56
|
+
top.children.add(namespace[0]);
|
44
57
|
}
|
45
58
|
for (const { second: props } of dict)
|
46
59
|
props.entries.forEach((entry, i) => (entry.alias = StringUtil_1.StringUtil.escapeDuplicate([
|
@@ -50,13 +63,45 @@ var ApiProgrammer;
|
|
50
63
|
...(entry.route.query ? [entry.route.query.key] : []),
|
51
64
|
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
|
52
65
|
])(entry.alias)));
|
53
|
-
|
54
|
-
location: `src
|
66
|
+
const output = [...dict].map(({ second: props }) => ({
|
67
|
+
location: `src/${program.config.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
|
55
68
|
file: "index.ts",
|
56
69
|
content: FilePrinter_1.FilePrinter.write({
|
57
70
|
statements: ApiFileProgrammer_1.ApiFileProgrammer.write(program.config)(program.swagger.components)(props),
|
58
71
|
}),
|
59
72
|
}));
|
73
|
+
if (program.config.mode === "sdk")
|
74
|
+
output.push(...[...DtoProgrammer_1.DtoProgrammer.write(program.swagger.components).entries()].map(([key, value]) => ({
|
75
|
+
location: "src/structures",
|
76
|
+
file: `${key}.ts`,
|
77
|
+
content: FilePrinter_1.FilePrinter.write({
|
78
|
+
statements: writeDtoFile(key, value),
|
79
|
+
}),
|
80
|
+
})));
|
81
|
+
return output;
|
82
|
+
};
|
83
|
+
const writeDtoFile = (key, modulo) => {
|
84
|
+
const importer = new ImportProgrammer_1.ImportProgrammer();
|
85
|
+
const statements = iterate(importer)(modulo);
|
86
|
+
if (statements.length === 0)
|
87
|
+
return [];
|
88
|
+
return [
|
89
|
+
...importer.toStatements((name) => `./${name}`, key),
|
90
|
+
...(importer.empty() ? [] : [FilePrinter_1.FilePrinter.enter()]),
|
91
|
+
...statements,
|
92
|
+
];
|
93
|
+
};
|
94
|
+
const iterate = (importer) => (modulo) => {
|
95
|
+
const output = [];
|
96
|
+
if (modulo.programmer !== null)
|
97
|
+
output.push(modulo.programmer(importer));
|
98
|
+
if (modulo.children.size) {
|
99
|
+
const internal = [];
|
100
|
+
for (const child of modulo.children.values())
|
101
|
+
internal.push(...iterate(importer)(child));
|
102
|
+
output.push(typescript_1.default.factory.createModuleDeclaration([typescript_1.default.factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], typescript_1.default.factory.createIdentifier(modulo.name), typescript_1.default.factory.createModuleBlock(internal), typescript_1.default.NodeFlags.Namespace));
|
103
|
+
}
|
104
|
+
return output;
|
60
105
|
};
|
61
106
|
})(ApiProgrammer || (exports.ApiProgrammer = ApiProgrammer = {}));
|
62
107
|
//# sourceMappingURL=ApiProgrammer.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ApiProgrammer.js","sourceRoot":"","sources":["../../src/programmers/ApiProgrammer.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"ApiProgrammer.js","sourceRoot":"","sources":["../../src/programmers/ApiProgrammer.ts"],"names":[],"mappings":";;;;;;AAAA,+BAA+C;AAC/C,4DAA4B;AAC5B,qDAAkD;AAIlD,sDAAmD;AACnD,oDAAiD;AACjD,2DAAwD;AACxD,mDAAgD;AAChD,yDAAsD;AAEtD,IAAiB,aAAa,CAmH7B;AAnHD,WAAiB,aAAa;IACf,mBAAK,GAAG,CAAC,OAAwB,EAAkB,EAAE;QAChE,MAAM,IAAI,GAAgD,IAAI,cAAO,CACnE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACxB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACtC,CAAC;QACF,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,WAAW;YAC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AE,CAAC,OAAO,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,EACxD,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EACxC,oBAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EACtC,oBAAE,CAAC,SAAS,CAAC,SAAS,CACvB,CACF,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACN,CAAC,EAnHgB,aAAa,6BAAb,aAAa,QAmH7B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nestia/migrate",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.7.0-dev.20240201",
|
4
4
|
"description": "Migration program from swagger to NestJS",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"typings": "lib/index.d.ts",
|
@@ -9,8 +9,9 @@
|
|
9
9
|
},
|
10
10
|
"scripts": {
|
11
11
|
"build": "rimraf lib && tsc",
|
12
|
+
"bundle": "ts-node src/executable/bundle.ts",
|
12
13
|
"dev": "npm run build -- --watch",
|
13
|
-
"prepare": "ts-patch install && typia patch &&
|
14
|
+
"prepare": "ts-patch install && typia patch && npm run bundle",
|
14
15
|
"test": "node lib/test"
|
15
16
|
},
|
16
17
|
"repository": {
|
package/src/IMigrateConfig.ts
CHANGED
@@ -1,82 +1,35 @@
|
|
1
|
-
import cp from "child_process";
|
2
|
-
import fs from "fs";
|
3
1
|
import typia from "typia";
|
4
2
|
|
5
|
-
import { IMigrateConfig } from "./IMigrateConfig";
|
6
3
|
import { MigrateAnalyzer } from "./analyzers/MigrateAnalyzer";
|
7
|
-
import {
|
8
|
-
import {
|
4
|
+
import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
|
5
|
+
import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
|
9
6
|
import { ApiProgrammer } from "./programmers/ApiProgrammer";
|
10
7
|
import { NestProgrammer } from "./programmers/NestProgrammer";
|
11
8
|
import { IMigrateFile } from "./structures/IMigrateFile";
|
12
|
-
import { IMigrateProgram } from "./structures/IMigrateProgram";
|
13
9
|
import { ISwagger } from "./structures/ISwagger";
|
14
10
|
|
15
11
|
export class MigrateApplication {
|
16
|
-
public readonly swagger: ISwagger
|
17
|
-
|
18
|
-
private files: IMigrateFile[] | null;
|
19
|
-
|
20
|
-
public constructor(
|
21
|
-
public readonly config: IMigrateConfig,
|
22
|
-
swagger: ISwagger,
|
23
|
-
) {
|
24
|
-
this.swagger = typia.assert(swagger);
|
25
|
-
this.program = null;
|
26
|
-
this.files = null;
|
27
|
-
}
|
28
|
-
|
29
|
-
public analyze(): IMigrateProgram {
|
30
|
-
if (this.program === null)
|
31
|
-
this.program = MigrateAnalyzer.analyze(this.config)(this.swagger);
|
32
|
-
return this.program;
|
12
|
+
public constructor(public readonly swagger: ISwagger) {
|
13
|
+
typia.assert(swagger);
|
33
14
|
}
|
34
15
|
|
35
|
-
public
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
16
|
+
public nest(simulate: boolean): IMigrateFile[] {
|
17
|
+
const program = MigrateAnalyzer.analyze({
|
18
|
+
mode: "nest",
|
19
|
+
simulate,
|
20
|
+
})(this.swagger);
|
21
|
+
return [
|
22
|
+
...NEST_TEMPLATE,
|
23
|
+
...NestProgrammer.write(program),
|
24
|
+
...ApiProgrammer.write(program),
|
25
|
+
];
|
44
26
|
}
|
45
27
|
|
46
|
-
public
|
47
|
-
const
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
})(output);
|
53
|
-
try {
|
54
|
-
cp.execSync(
|
55
|
-
`git clone https://github.com/samchon/nestia-template "${output}"`,
|
56
|
-
{ stdio: "ignore" },
|
57
|
-
);
|
58
|
-
try {
|
59
|
-
for (const path of [
|
60
|
-
"/.git",
|
61
|
-
"/src/api",
|
62
|
-
"/src/controllers",
|
63
|
-
"/src/providers",
|
64
|
-
"/test/features",
|
65
|
-
])
|
66
|
-
fs.rmSync(`${output}${path}`, {
|
67
|
-
recursive: true,
|
68
|
-
force: true,
|
69
|
-
});
|
70
|
-
} catch {}
|
71
|
-
} catch (exp) {
|
72
|
-
await archiver(TEMPLATE);
|
73
|
-
}
|
74
|
-
await archiver(files);
|
75
|
-
}
|
76
|
-
}
|
77
|
-
export namespace NestiaMigrateApplication {
|
78
|
-
export interface IArchiver {
|
79
|
-
mkdir: (path: string) => void;
|
80
|
-
writeFile: (path: string, content: string) => void;
|
28
|
+
public sdk(simulate: boolean): IMigrateFile[] {
|
29
|
+
const program = MigrateAnalyzer.analyze({
|
30
|
+
mode: "sdk",
|
31
|
+
simulate,
|
32
|
+
})(this.swagger);
|
33
|
+
return [...SDK_TEMPLATE, ...ApiProgrammer.write(program)];
|
81
34
|
}
|
82
35
|
}
|