@nestia/migrate 0.7.6 → 0.7.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.
- package/lib/MigrateApplication.js +7 -4
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.d.ts +2 -3
- package/lib/analyzers/MigrateAnalyzer.js +1 -5
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateControllerAnalyzer.js +22 -13
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateMethodAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateMethodAnalyzer.js +16 -16
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
- package/lib/module.d.ts +8 -0
- package/lib/module.js +8 -0
- package/lib/module.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +3 -3
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateImportProgrammer.js +5 -5
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.d.ts +1 -1
- package/lib/structures/IMigrateDto.d.ts +1 -1
- package/lib/structures/IMigrateProgram.d.ts +20 -4
- package/lib/structures/IMigrateRoute.d.ts +1 -1
- package/lib/structures/ISwaggerComponents.d.ts +1 -1
- package/lib/structures/ISwaggerRoute.d.ts +1 -1
- package/lib/structures/{ISwaggeSchema.js → ISwaggerSchema.js} +1 -1
- package/lib/structures/ISwaggerSchema.js.map +1 -0
- package/lib/utils/SwaggerTypeChecker.d.ts +1 -1
- package/package.json +1 -1
- package/src/MigrateApplication.ts +54 -48
- package/src/analyzers/MigrateAnalyzer.ts +9 -13
- package/src/analyzers/MigrateControllerAnalyzer.ts +139 -122
- package/src/analyzers/MigrateMethodAnalyzer.ts +350 -348
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/executable/bundle.ts +109 -109
- package/src/internal/MigrateCommander.ts +51 -51
- package/src/module.ts +10 -0
- package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
- package/src/programmers/MigrateApiFunctionProgrammer.ts +203 -203
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +430 -430
- package/src/programmers/MigrateApiProgrammer.ts +132 -132
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +328 -328
- package/src/programmers/MigrateDtoProgrammer.ts +78 -78
- package/src/programmers/MigrateImportProgrammer.ts +114 -116
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +249 -249
- package/src/programmers/MigrateNestModuleProgrammer.ts +62 -62
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/programmers/MigrateSchemaProgrammer.ts +257 -257
- package/src/structures/IMigrateDto.ts +1 -1
- package/src/structures/IMigrateProgram.ts +20 -4
- package/src/structures/IMigrateRoute.ts +46 -46
- package/src/structures/ISwaggerComponents.ts +1 -1
- package/src/structures/ISwaggerRoute.ts +1 -1
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/SwaggerTypeChecker.ts +67 -67
- package/lib/IMigrateConfig.d.ts +0 -4
- package/lib/IMigrateConfig.js +0 -3
- package/lib/IMigrateConfig.js.map +0 -1
- package/lib/structures/ISwaggeSchema.js.map +0 -1
- package/src/IMigrateConfig.ts +0 -4
- /package/lib/structures/{ISwaggeSchema.d.ts → ISwaggerSchema.d.ts} +0 -0
- /package/src/structures/{ISwaggeSchema.ts → ISwaggerSchema.ts} +0 -0
@@ -1,38 +1,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
|
+
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
|
+
}
|
package/src/executable/bundle.ts
CHANGED
@@ -1,109 +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
|
-
".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
|
+
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,51 +1,51 @@
|
|
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
|
+
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
|
+
}
|
package/src/module.ts
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
export * from "./MigrateApplication";
|
2
2
|
|
3
|
+
export * from "./analyzers/MigrateAnalyzer";
|
4
|
+
|
5
|
+
export * from "./archivers/MigrateFileArchiver";
|
6
|
+
|
3
7
|
export * from "./structures/ISwagger";
|
8
|
+
export * from "./structures/ISwaggerComponents";
|
9
|
+
export * from "./structures/ISwaggerInfo";
|
10
|
+
export * from "./structures/ISwaggerRoute";
|
11
|
+
export * from "./structures/ISwaggerSecurity";
|
12
|
+
export * from "./structures/ISwaggerSchema";
|
4
13
|
export * from "./structures/IMigrateProgram";
|
14
|
+
export * from "./structures/IMigrateSchema";
|
@@ -1,53 +1,53 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
|
3
|
-
import {
|
4
|
-
import { IMigrateController } from "../structures/IMigrateController";
|
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:
|
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 { IMigrateProgram } from "../module";
|
4
|
+
import { IMigrateController } from "../structures/IMigrateController";
|
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
|
+
}
|