@nestia/migrate 0.7.5 → 0.7.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.
- package/lib/MigrateApplication.d.ts +9 -2
- package/lib/MigrateApplication.js +14 -8
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.js +2 -2
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/{ControllerAnalyzer.d.ts → MigrateControllerAnalyzer.d.ts} +1 -1
- package/lib/analyzers/{ControllerAnalyzer.js → MigrateControllerAnalyzer.js} +11 -9
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -0
- package/lib/analyzers/{MethodAnalyzer.d.ts → MigrateMethodAnalyzer.d.ts} +1 -1
- package/lib/analyzers/{MethodAnalyzer.js → MigrateMethodAnalyzer.js} +26 -25
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -0
- package/lib/archivers/{FileArchiver.d.ts → MigrateFileArchiver.d.ts} +1 -1
- package/lib/archivers/{FileArchiver.js → MigrateFileArchiver.js} +6 -6
- package/lib/archivers/MigrateFileArchiver.js.map +1 -0
- package/lib/bundles/SDK_TEMPLATE.js +0 -5
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js +1 -0
- package/lib/executable/bundle.js.map +1 -1
- package/lib/internal/MigrateCommander.js +3 -3
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/{ApiFileProgrammer.d.ts → MigrateApiFileProgrammer.d.ts} +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.js +28 -0
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -0
- package/lib/programmers/{ApiFunctionProgrammer.d.ts → MigrateApiFunctionProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiFunctionProgrammer.js → MigrateApiFunctionProgrammer.js} +10 -10
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -0
- package/lib/programmers/{ApiNamespaceProgrammer.d.ts → MigrateApiNamespaceProgrammer.d.ts} +3 -3
- package/lib/programmers/{ApiNamespaceProgrammer.js → MigrateApiNamespaceProgrammer.js} +19 -19
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -0
- package/lib/programmers/{ApiProgrammer.d.ts → MigrateApiProgrammer.d.ts} +1 -1
- package/lib/programmers/{ApiProgrammer.js → MigrateApiProgrammer.js} +25 -20
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -0
- package/lib/programmers/{ApiSimulatationProgrammer.d.ts → MigrateApiSimulatationProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiSimulatationProgrammer.js → MigrateApiSimulatationProgrammer.js} +16 -16
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -0
- package/lib/programmers/{DtoProgrammer.d.ts → MigrateDtoProgrammer.d.ts} +3 -3
- package/lib/programmers/{DtoProgrammer.js → MigrateDtoProgrammer.js} +8 -8
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -0
- package/lib/programmers/{ImportProgrammer.d.ts → MigrateImportProgrammer.d.ts} +3 -3
- package/lib/programmers/{ImportProgrammer.js → MigrateImportProgrammer.js} +7 -5
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -0
- package/lib/programmers/{NestControllerProgrammer.d.ts → MigrateNestControllerProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestControllerProgrammer.js → MigrateNestControllerProgrammer.js} +11 -11
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -0
- package/lib/programmers/{NestMethodProgrammer.d.ts → MigrateNestMethodProgrammer.d.ts} +3 -3
- package/lib/programmers/{NestMethodProgrammer.js → MigrateNestMethodProgrammer.js} +13 -11
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -0
- package/lib/programmers/{NestModuleProgrammer.d.ts → MigrateNestModuleProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestModuleProgrammer.js → MigrateNestModuleProgrammer.js} +8 -8
- package/lib/programmers/MigrateNestModuleProgrammer.js.map +1 -0
- package/lib/programmers/{NestProgrammer.d.ts → MigrateNestProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestProgrammer.js → MigrateNestProgrammer.js} +17 -15
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -0
- package/lib/programmers/{SchemaProgrammer.d.ts → MigrateSchemaProgrammer.d.ts} +3 -3
- package/lib/programmers/{SchemaProgrammer.js → MigrateSchemaProgrammer.js} +23 -23
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -0
- package/lib/structures/IMigrateRoute.d.ts +1 -0
- package/lib/utils/FilePrinter.d.ts +1 -1
- package/lib/utils/FilePrinter.js +1 -1
- package/lib/utils/FilePrinter.js.map +1 -1
- package/lib/utils/{JsonTypeChecker.d.ts → SwaggerTypeChecker.d.ts} +1 -1
- package/lib/utils/SwaggerTypeChecker.js +34 -0
- package/lib/utils/SwaggerTypeChecker.js.map +1 -0
- package/package.json +68 -68
- package/src/IMigrateConfig.ts +4 -4
- package/src/MigrateApplication.ts +48 -35
- package/src/analyzers/MigrateAnalyzer.ts +13 -13
- package/src/analyzers/{ControllerAnalyzer.ts → MigrateControllerAnalyzer.ts} +122 -123
- package/src/analyzers/{MethodAnalyzer.ts → MigrateMethodAnalyzer.ts} +348 -347
- package/src/archivers/{FileArchiver.ts → MigrateFileArchiver.ts} +38 -38
- package/src/bundles/SDK_TEMPLATE.ts +0 -5
- package/src/executable/bundle.ts +109 -108
- package/src/executable/migrate.ts +7 -7
- package/src/internal/MigrateCommander.ts +51 -52
- package/src/internal/MigrateInquirer.ts +79 -79
- package/src/module.ts +4 -4
- package/src/programmers/{ApiFileProgrammer.ts → MigrateApiFileProgrammer.ts} +53 -53
- package/src/programmers/{ApiFunctionProgrammer.ts → MigrateApiFunctionProgrammer.ts} +203 -203
- package/src/programmers/{ApiNamespaceProgrammer.ts → MigrateApiNamespaceProgrammer.ts} +430 -418
- package/src/programmers/{ApiProgrammer.ts → MigrateApiProgrammer.ts} +132 -128
- package/src/programmers/{ApiSimulatationProgrammer.ts → MigrateApiSimulatationProgrammer.ts} +328 -328
- package/src/programmers/{DtoProgrammer.ts → MigrateDtoProgrammer.ts} +78 -74
- package/src/programmers/{ImportProgrammer.ts → MigrateImportProgrammer.ts} +116 -114
- package/src/programmers/{NestControllerProgrammer.ts → MigrateNestControllerProgrammer.ts} +50 -48
- package/src/programmers/{NestMethodProgrammer.ts → MigrateNestMethodProgrammer.ts} +249 -243
- package/src/programmers/{NestModuleProgrammer.ts → MigrateNestModuleProgrammer.ts} +62 -62
- package/src/programmers/{NestProgrammer.ts → MigrateNestProgrammer.ts} +74 -74
- package/src/programmers/{SchemaProgrammer.ts → MigrateSchemaProgrammer.ts} +257 -255
- package/src/structures/IMigrateProgram.ts +9 -9
- package/src/structures/IMigrateRoute.ts +46 -45
- package/src/structures/ISwaggeSchema.ts +90 -90
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +60 -60
- package/src/utils/{JsonTypeChecker.ts → SwaggerTypeChecker.ts} +67 -67
- package/lib/analyzers/ControllerAnalyzer.js.map +0 -1
- package/lib/analyzers/MethodAnalyzer.js.map +0 -1
- package/lib/archivers/FileArchiver.js.map +0 -1
- package/lib/programmers/ApiFileProgrammer.js +0 -28
- package/lib/programmers/ApiFileProgrammer.js.map +0 -1
- package/lib/programmers/ApiFunctionProgrammer.js.map +0 -1
- package/lib/programmers/ApiNamespaceProgrammer.js.map +0 -1
- package/lib/programmers/ApiProgrammer.js.map +0 -1
- package/lib/programmers/ApiSimulatationProgrammer.js.map +0 -1
- package/lib/programmers/DtoProgrammer.js.map +0 -1
- package/lib/programmers/ImportProgrammer.js.map +0 -1
- package/lib/programmers/NestControllerProgrammer.js.map +0 -1
- package/lib/programmers/NestMethodProgrammer.js.map +0 -1
- package/lib/programmers/NestModuleProgrammer.js.map +0 -1
- package/lib/programmers/NestProgrammer.js.map +0 -1
- package/lib/programmers/SchemaProgrammer.js.map +0 -1
- package/lib/utils/JsonTypeChecker.js +0 -34
- package/lib/utils/JsonTypeChecker.js.map +0 -1
@@ -1,38 +1,38 @@
|
|
1
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
2
|
-
|
3
|
-
export namespace
|
4
|
-
export interface IOperator {
|
5
|
-
mkdir(path: string): Promise<void>;
|
6
|
-
writeFile(path: string, content: string): Promise<void>;
|
7
|
-
}
|
8
|
-
|
9
|
-
export const archive =
|
10
|
-
(operator: IOperator) =>
|
11
|
-
(output: string) =>
|
12
|
-
async (files: IMigrateFile[]): Promise<void> => {
|
13
|
-
const visited: Set<string> = new Set();
|
14
|
-
for (const f of files) {
|
15
|
-
await mkdir(operator.mkdir)(output)(visited)(f.location);
|
16
|
-
await operator.writeFile(
|
17
|
-
[output, f.location, f.file].join("/"),
|
18
|
-
f.content,
|
19
|
-
);
|
20
|
-
}
|
21
|
-
};
|
22
|
-
|
23
|
-
const mkdir =
|
24
|
-
(creator: (path: string) => void) =>
|
25
|
-
(output: string) =>
|
26
|
-
(visited: Set<string>) =>
|
27
|
-
async (path: string): Promise<void> => {
|
28
|
-
const sequence: string[] = path
|
29
|
-
.split("/")
|
30
|
-
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
31
|
-
for (const s of sequence)
|
32
|
-
if (visited.has(s) === false)
|
33
|
-
try {
|
34
|
-
await creator([output, s].join("/"));
|
35
|
-
visited.add(s);
|
36
|
-
} catch {}
|
37
|
-
};
|
38
|
-
}
|
1
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
2
|
+
|
3
|
+
export namespace MigrateFileArchiver {
|
4
|
+
export interface IOperator {
|
5
|
+
mkdir(path: string): Promise<void>;
|
6
|
+
writeFile(path: string, content: string): Promise<void>;
|
7
|
+
}
|
8
|
+
|
9
|
+
export const archive =
|
10
|
+
(operator: IOperator) =>
|
11
|
+
(output: string) =>
|
12
|
+
async (files: IMigrateFile[]): Promise<void> => {
|
13
|
+
const visited: Set<string> = new Set();
|
14
|
+
for (const f of files) {
|
15
|
+
await mkdir(operator.mkdir)(output)(visited)(f.location);
|
16
|
+
await operator.writeFile(
|
17
|
+
[output, f.location, f.file].join("/"),
|
18
|
+
f.content,
|
19
|
+
);
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
const mkdir =
|
24
|
+
(creator: (path: string) => void) =>
|
25
|
+
(output: string) =>
|
26
|
+
(visited: Set<string>) =>
|
27
|
+
async (path: string): Promise<void> => {
|
28
|
+
const sequence: string[] = path
|
29
|
+
.split("/")
|
30
|
+
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
31
|
+
for (const s of sequence)
|
32
|
+
if (visited.has(s) === false)
|
33
|
+
try {
|
34
|
+
await creator([output, s].join("/"));
|
35
|
+
visited.add(s);
|
36
|
+
} catch {}
|
37
|
+
};
|
38
|
+
}
|
@@ -1,9 +1,4 @@
|
|
1
1
|
export const SDK_TEMPLATE = [
|
2
|
-
{
|
3
|
-
"location": ".github/workflows",
|
4
|
-
"file": "build.yml",
|
5
|
-
"content": "name: build\r\non: [push, pull_request]\r\n\r\njobs:\r\n Ubuntu:\r\n runs-on: ubuntu-latest\r\n steps:\r\n - uses: actions/checkout@v4\r\n - uses: actions/setup-node@v4\r\n with:\r\n node-version: 20.x\r\n - uses: pnpm/action-setup@v2\r\n with:\r\n version: 8\r\n\r\n - name: Install\r\n run: pnpm install\r\n\r\n - name: Build\r\n run: npm run build\r\n"
|
6
|
-
},
|
7
2
|
{
|
8
3
|
"location": "",
|
9
4
|
"file": ".gitignore",
|
package/src/executable/bundle.ts
CHANGED
@@ -1,108 +1,109 @@
|
|
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
|
-
"
|
101
|
-
"src/
|
102
|
-
|
103
|
-
|
104
|
-
};
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
+
],
|
104
|
+
});
|
105
|
+
};
|
106
|
+
main().catch((exp) => {
|
107
|
+
console.error(exp);
|
108
|
+
process.exit(-1);
|
109
|
+
});
|
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import { MigrateCommander } from "../internal/MigrateCommander";
|
3
|
-
|
4
|
-
MigrateCommander.main().catch((exp) => {
|
5
|
-
console.error(exp);
|
6
|
-
process.exit(-1);
|
7
|
-
});
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import { MigrateCommander } from "../internal/MigrateCommander";
|
3
|
+
|
4
|
+
MigrateCommander.main().catch((exp) => {
|
5
|
+
console.error(exp);
|
6
|
+
process.exit(-1);
|
7
|
+
});
|
@@ -1,52 +1,51 @@
|
|
1
|
-
import fs from "fs";
|
2
|
-
import path from "path";
|
3
|
-
|
4
|
-
import {
|
5
|
-
import { MigrateApplication } from "../module";
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
|
9
|
-
|
10
|
-
export
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if (fs.existsSync(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
const
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
const
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
|
4
|
+
import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
|
5
|
+
import { MigrateApplication } from "../module";
|
6
|
+
import { ISwagger } from "../structures/ISwagger";
|
7
|
+
import { MigrateInquirer } from "./MigrateInquirer";
|
8
|
+
|
9
|
+
export namespace MigrateCommander {
|
10
|
+
export const main = async (): Promise<void> => {
|
11
|
+
const resolve = (str: string | undefined) =>
|
12
|
+
str ? path.resolve(str).split("\\").join("/") : undefined;
|
13
|
+
const options: MigrateInquirer.IOutput = await MigrateInquirer.parse();
|
14
|
+
|
15
|
+
// VALIDATE OUTPUT DIRECTORY
|
16
|
+
const parent: string = resolve(options.output + "/..")!;
|
17
|
+
if (fs.existsSync(options.output)) halt("Output directory alreay exists.");
|
18
|
+
else if (fs.existsSync(parent) === false)
|
19
|
+
halt("Output directory's parent directory does not exist.");
|
20
|
+
else if (fs.statSync(parent).isDirectory() === false)
|
21
|
+
halt("Output directory's parent is not a directory.");
|
22
|
+
|
23
|
+
// READ SWAGGER
|
24
|
+
const swagger: ISwagger = (() => {
|
25
|
+
if (fs.existsSync(options.input) === false)
|
26
|
+
halt("Unable to find the input swagger.json file.");
|
27
|
+
const stats: fs.Stats = fs.statSync(options.input);
|
28
|
+
if (stats.isFile() === false)
|
29
|
+
halt("The input swagger.json is not a file.");
|
30
|
+
const content: string = fs.readFileSync(options.input, "utf-8");
|
31
|
+
const swagger: ISwagger = JSON.parse(content);
|
32
|
+
return swagger;
|
33
|
+
})();
|
34
|
+
|
35
|
+
const app: MigrateApplication = new MigrateApplication(swagger);
|
36
|
+
const { files } =
|
37
|
+
options.mode === "nest"
|
38
|
+
? app.nest(options.simulate)
|
39
|
+
: app.sdk(options.simulate);
|
40
|
+
await MigrateFileArchiver.archive({
|
41
|
+
mkdir: fs.promises.mkdir,
|
42
|
+
writeFile: (file, content) =>
|
43
|
+
fs.promises.writeFile(file, content, "utf-8"),
|
44
|
+
})(options.output)(files);
|
45
|
+
};
|
46
|
+
|
47
|
+
const halt = (desc: string): never => {
|
48
|
+
console.error(desc);
|
49
|
+
process.exit(-1);
|
50
|
+
};
|
51
|
+
}
|
@@ -1,79 +1,79 @@
|
|
1
|
-
import commander from "commander";
|
2
|
-
import inquirer from "inquirer";
|
3
|
-
|
4
|
-
export namespace MigrateInquirer {
|
5
|
-
export interface IOutput {
|
6
|
-
mode: "nest" | "sdk";
|
7
|
-
simulate: boolean;
|
8
|
-
input: string;
|
9
|
-
output: string;
|
10
|
-
}
|
11
|
-
|
12
|
-
export const parse = async (): Promise<IOutput> => {
|
13
|
-
// PREPARE ASSETS
|
14
|
-
commander.program.option("--mode [nest/sdk]", "migration mode");
|
15
|
-
commander.program.option(
|
16
|
-
"--input [swagger.json]",
|
17
|
-
"location of target swagger.json file",
|
18
|
-
);
|
19
|
-
commander.program.option("--output [directory]", "output directory path");
|
20
|
-
commander.program.option("--simulate", "Mockup simulator");
|
21
|
-
|
22
|
-
// INTERNAL PROCEDURES
|
23
|
-
const questioned = { value: false };
|
24
|
-
const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
|
25
|
-
new Promise<IOutput>((resolve, reject) => {
|
26
|
-
commander.program.action(async (options) => {
|
27
|
-
try {
|
28
|
-
resolve(await closure(options));
|
29
|
-
} catch (exp) {
|
30
|
-
reject(exp);
|
31
|
-
}
|
32
|
-
});
|
33
|
-
commander.program.parseAsync().catch(reject);
|
34
|
-
});
|
35
|
-
const select =
|
36
|
-
(name: string) =>
|
37
|
-
(message: string) =>
|
38
|
-
async <Choice extends string>(
|
39
|
-
choices: Choice[],
|
40
|
-
filter?: (value: string) => Choice,
|
41
|
-
): Promise<Choice> => {
|
42
|
-
questioned.value = true;
|
43
|
-
return (
|
44
|
-
await inquirer.createPromptModule()({
|
45
|
-
type: "list",
|
46
|
-
name: name,
|
47
|
-
message: message,
|
48
|
-
choices: choices,
|
49
|
-
filter,
|
50
|
-
})
|
51
|
-
)[name];
|
52
|
-
};
|
53
|
-
const input = (name: string) => async (message: string) =>
|
54
|
-
(
|
55
|
-
await inquirer.createPromptModule()({
|
56
|
-
type: "input",
|
57
|
-
name,
|
58
|
-
message,
|
59
|
-
})
|
60
|
-
)[name];
|
61
|
-
|
62
|
-
// DO CONSTRUCT
|
63
|
-
return action(async (partial) => {
|
64
|
-
partial.mode ??= await select("mode")("Migration mode")(
|
65
|
-
["NestJS" as "nest", "SDK" as "sdk"],
|
66
|
-
(value) => (value === "NestJS" ? "nest" : "sdk"),
|
67
|
-
);
|
68
|
-
partial.input ??= await input("input")("Swagger file location");
|
69
|
-
partial.output ??= await input("output")("Output directory path");
|
70
|
-
if (partial.simulate)
|
71
|
-
partial.simulate = (partial.simulate as any) === "true";
|
72
|
-
else
|
73
|
-
partial.simulate =
|
74
|
-
(await select("simulate")("Mokup Simulator")(["true", "false"])) ===
|
75
|
-
"true";
|
76
|
-
return partial as IOutput;
|
77
|
-
});
|
78
|
-
};
|
79
|
-
}
|
1
|
+
import commander from "commander";
|
2
|
+
import inquirer from "inquirer";
|
3
|
+
|
4
|
+
export namespace MigrateInquirer {
|
5
|
+
export interface IOutput {
|
6
|
+
mode: "nest" | "sdk";
|
7
|
+
simulate: boolean;
|
8
|
+
input: string;
|
9
|
+
output: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
export const parse = async (): Promise<IOutput> => {
|
13
|
+
// PREPARE ASSETS
|
14
|
+
commander.program.option("--mode [nest/sdk]", "migration mode");
|
15
|
+
commander.program.option(
|
16
|
+
"--input [swagger.json]",
|
17
|
+
"location of target swagger.json file",
|
18
|
+
);
|
19
|
+
commander.program.option("--output [directory]", "output directory path");
|
20
|
+
commander.program.option("--simulate", "Mockup simulator");
|
21
|
+
|
22
|
+
// INTERNAL PROCEDURES
|
23
|
+
const questioned = { value: false };
|
24
|
+
const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
|
25
|
+
new Promise<IOutput>((resolve, reject) => {
|
26
|
+
commander.program.action(async (options) => {
|
27
|
+
try {
|
28
|
+
resolve(await closure(options));
|
29
|
+
} catch (exp) {
|
30
|
+
reject(exp);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
commander.program.parseAsync().catch(reject);
|
34
|
+
});
|
35
|
+
const select =
|
36
|
+
(name: string) =>
|
37
|
+
(message: string) =>
|
38
|
+
async <Choice extends string>(
|
39
|
+
choices: Choice[],
|
40
|
+
filter?: (value: string) => Choice,
|
41
|
+
): Promise<Choice> => {
|
42
|
+
questioned.value = true;
|
43
|
+
return (
|
44
|
+
await inquirer.createPromptModule()({
|
45
|
+
type: "list",
|
46
|
+
name: name,
|
47
|
+
message: message,
|
48
|
+
choices: choices,
|
49
|
+
filter,
|
50
|
+
})
|
51
|
+
)[name];
|
52
|
+
};
|
53
|
+
const input = (name: string) => async (message: string) =>
|
54
|
+
(
|
55
|
+
await inquirer.createPromptModule()({
|
56
|
+
type: "input",
|
57
|
+
name,
|
58
|
+
message,
|
59
|
+
})
|
60
|
+
)[name];
|
61
|
+
|
62
|
+
// DO CONSTRUCT
|
63
|
+
return action(async (partial) => {
|
64
|
+
partial.mode ??= await select("mode")("Migration mode")(
|
65
|
+
["NestJS" as "nest", "SDK" as "sdk"],
|
66
|
+
(value) => (value === "NestJS" ? "nest" : "sdk"),
|
67
|
+
);
|
68
|
+
partial.input ??= await input("input")("Swagger file location");
|
69
|
+
partial.output ??= await input("output")("Output directory path");
|
70
|
+
if (partial.simulate)
|
71
|
+
partial.simulate = (partial.simulate as any) === "true";
|
72
|
+
else
|
73
|
+
partial.simulate =
|
74
|
+
(await select("simulate")("Mokup Simulator")(["true", "false"])) ===
|
75
|
+
"true";
|
76
|
+
return partial as IOutput;
|
77
|
+
});
|
78
|
+
};
|
79
|
+
}
|
package/src/module.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export * from "./MigrateApplication";
|
2
|
-
|
3
|
-
export * from "./structures/ISwagger";
|
4
|
-
export * from "./structures/IMigrateProgram";
|
1
|
+
export * from "./MigrateApplication";
|
2
|
+
|
3
|
+
export * from "./structures/ISwagger";
|
4
|
+
export * from "./structures/IMigrateProgram";
|