@nestia/migrate 0.5.1 → 0.6.1
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/{NestiaMigrateApplication.d.ts → MigrateApplication.d.ts} +1 -1
- package/lib/{NestiaMigrateApplication.js → MigrateApplication.js} +38 -32
- package/lib/MigrateApplication.js.map +1 -0
- package/lib/analyzers/ControllerAnalyzer.d.ts +5 -0
- package/lib/{programmers/ControllerProgrammer.js → analyzers/ControllerAnalyzer.js} +8 -32
- package/lib/analyzers/ControllerAnalyzer.js.map +1 -0
- package/lib/analyzers/MethodAnalyzer.d.ts +9 -0
- package/lib/{programmers/RouteProgrammer.js → analyzers/MethodAnalyzer.js} +30 -134
- package/lib/analyzers/MethodAnalyzer.js.map +1 -0
- package/lib/analyzers/MigrateAnalyzer.d.ts +4 -0
- package/lib/analyzers/MigrateAnalyzer.js +12 -0
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -0
- package/lib/analyzers/RouteAnalyzer.d.ts +0 -0
- package/lib/analyzers/RouteAnalyzer.js +2 -0
- package/lib/analyzers/RouteAnalyzer.js.map +1 -0
- package/lib/archivers/FileArchiver.js.map +1 -1
- package/lib/bundles/TEMPLATE.js +10 -10
- package/lib/bundles/TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js.map +1 -1
- package/lib/executable/migrate.js +7 -7
- package/lib/executable/migrate.js.map +1 -1
- package/lib/module.d.ts +1 -1
- package/lib/module.js +1 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/DtoProgrammer.d.ts +8 -4
- package/lib/programmers/DtoProgrammer.js +36 -77
- package/lib/programmers/DtoProgrammer.js.map +1 -1
- package/lib/programmers/ImportProgrammer.d.ts +5 -5
- package/lib/programmers/ImportProgrammer.js +27 -19
- package/lib/programmers/ImportProgrammer.js.map +1 -1
- package/lib/programmers/{ControllerProgrammer.d.ts → NestControllerProgrammer.d.ts} +3 -4
- package/lib/programmers/NestControllerProgrammer.js +30 -0
- package/lib/programmers/NestControllerProgrammer.js.map +1 -0
- package/lib/programmers/NestMethodProgrammer.d.ts +7 -0
- package/lib/programmers/NestMethodProgrammer.js +103 -0
- package/lib/programmers/NestMethodProgrammer.js.map +1 -0
- package/lib/programmers/NestModuleProgrammer.d.ts +5 -0
- package/lib/programmers/NestModuleProgrammer.js +29 -0
- package/lib/programmers/NestModuleProgrammer.js.map +1 -0
- package/lib/programmers/NestProgrammer.d.ts +5 -0
- package/lib/programmers/NestProgrammer.js +60 -0
- package/lib/programmers/NestProgrammer.js.map +1 -0
- package/lib/programmers/SchemaProgrammer.d.ts +2 -1
- package/lib/programmers/SchemaProgrammer.js +122 -189
- package/lib/programmers/SchemaProgrammer.js.map +1 -1
- package/lib/structures/IMigrateProgram.d.ts +2 -2
- package/lib/structures/ISwaggerInfo.d.ts +3 -3
- package/lib/utils/FilePrinter.d.ts +9 -0
- package/lib/utils/FilePrinter.js +25 -0
- package/lib/utils/FilePrinter.js.map +1 -0
- package/lib/utils/JsonTypeChecker.d.ts +3 -1
- package/lib/utils/JsonTypeChecker.js +31 -18
- package/lib/utils/JsonTypeChecker.js.map +1 -1
- package/lib/utils/MapUtil.js.map +1 -1
- package/lib/utils/SetupWizard.js.map +1 -1
- package/lib/utils/StringUtil.js.map +1 -1
- package/package.json +8 -6
- package/src/MigrateApplication.ts +73 -0
- package/src/analyzers/ControllerAnalyzer.ts +107 -0
- package/src/analyzers/MethodAnalyzer.ts +315 -0
- package/src/analyzers/MigrateAnalyzer.ts +9 -0
- package/src/analyzers/RouteAnalyzer.ts +0 -0
- package/src/archivers/FileArchiver.ts +35 -38
- package/src/bundles/TEMPLATE.ts +10 -10
- package/src/executable/bundle.ts +72 -78
- package/src/executable/migrate.ts +59 -60
- package/src/index.ts +4 -4
- package/src/module.ts +4 -4
- package/src/programmers/DtoProgrammer.ts +74 -118
- package/src/programmers/ImportProgrammer.ts +98 -60
- package/src/programmers/NestControllerProgrammer.ts +47 -0
- package/src/programmers/NestMethodProgrammer.ts +211 -0
- package/src/programmers/NestModuleProgrammer.ts +62 -0
- package/src/programmers/NestProgrammer.ts +74 -0
- package/src/programmers/SchemaProgrammer.ts +247 -339
- package/src/structures/IMigrateController.ts +8 -8
- package/src/structures/IMigrateDto.ts +8 -8
- package/src/structures/IMigrateFile.ts +5 -5
- package/src/structures/IMigrateProgram.ts +7 -7
- package/src/structures/IMigrateRoute.ts +36 -36
- package/src/structures/IMigrateSchema.ts +4 -4
- package/src/structures/ISwaggeSchema.ts +82 -82
- package/src/structures/ISwagger.ts +20 -20
- package/src/structures/ISwaggerComponents.ts +7 -7
- package/src/structures/ISwaggerInfo.ts +57 -57
- package/src/structures/ISwaggerRoute.ts +52 -52
- package/src/structures/ISwaggerSecurity.ts +47 -47
- package/src/utils/FilePrinter.ts +36 -0
- package/src/utils/JsonTypeChecker.ts +67 -52
- package/src/utils/MapUtil.ts +13 -13
- package/src/utils/SetupWizard.ts +15 -15
- package/src/utils/StringUtil.ts +51 -51
- package/lib/NestiaMigrateApplication.js.map +0 -1
- package/lib/programmers/ControllerProgrammer.js.map +0 -1
- package/lib/programmers/MigrateProgrammer.d.ts +0 -8
- package/lib/programmers/MigrateProgrammer.js +0 -48
- package/lib/programmers/MigrateProgrammer.js.map +0 -1
- package/lib/programmers/RouteProgrammer.d.ts +0 -13
- package/lib/programmers/RouteProgrammer.js.map +0 -1
- package/src/NestiaMigrateApplication.ts +0 -73
- package/src/programmers/ControllerProgrammer.ts +0 -157
- package/src/programmers/MigrateProgrammer.ts +0 -62
- package/src/programmers/RouteProgrammer.ts +0 -506
package/src/executable/bundle.ts
CHANGED
@@ -1,78 +1,72 @@
|
|
1
|
-
import cp from "child_process";
|
2
|
-
import fs from "fs";
|
3
|
-
|
4
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
5
|
-
|
6
|
-
const ROOT = __dirname + "/../..";
|
7
|
-
const ASSETS = ROOT + "/assets";
|
8
|
-
const TEMPLATE = ASSETS + "/template";
|
9
|
-
|
10
|
-
const clone = async (): Promise<void> => {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
const
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
await archive(collection);
|
74
|
-
};
|
75
|
-
main().catch((exp) => {
|
76
|
-
console.error(exp);
|
77
|
-
process.exit(-1);
|
78
|
-
});
|
1
|
+
import cp from "child_process";
|
2
|
+
import fs from "fs";
|
3
|
+
|
4
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
5
|
+
|
6
|
+
const ROOT = __dirname + "/../..";
|
7
|
+
const ASSETS = ROOT + "/assets";
|
8
|
+
const TEMPLATE = ASSETS + "/template";
|
9
|
+
|
10
|
+
const clone = async (): Promise<void> => {
|
11
|
+
console.log("Preparing bundles...");
|
12
|
+
|
13
|
+
// CLONE REPOSITORY
|
14
|
+
if (fs.existsSync(TEMPLATE))
|
15
|
+
await fs.promises.rm(TEMPLATE, { recursive: true });
|
16
|
+
else
|
17
|
+
try {
|
18
|
+
await fs.promises.mkdir(ASSETS);
|
19
|
+
} catch {}
|
20
|
+
|
21
|
+
cp.execSync("git clone https://github.com/samchon/nestia-template template", {
|
22
|
+
cwd: __dirname + "/../../assets",
|
23
|
+
});
|
24
|
+
|
25
|
+
// REMOVE VUNLERABLE FILES
|
26
|
+
for (const path of [
|
27
|
+
`${TEMPLATE}/.git`,
|
28
|
+
`${TEMPLATE}/src/api`,
|
29
|
+
`${TEMPLATE}/src/controllers`,
|
30
|
+
`${TEMPLATE}/src/providers`,
|
31
|
+
`${TEMPLATE}/test/features`,
|
32
|
+
])
|
33
|
+
await fs.promises.rm(path, { recursive: true });
|
34
|
+
};
|
35
|
+
|
36
|
+
const iterate = (collection: IMigrateFile[]) => async (location: string) => {
|
37
|
+
const directory: string[] = await fs.promises.readdir(location);
|
38
|
+
for (const file of directory) {
|
39
|
+
const absolute: string = location + "/" + file;
|
40
|
+
const stats: fs.Stats = await fs.promises.stat(absolute);
|
41
|
+
if (stats.isDirectory()) await iterate(collection)(absolute);
|
42
|
+
else {
|
43
|
+
const content: string = await fs.promises.readFile(absolute, "utf-8");
|
44
|
+
collection.push({
|
45
|
+
location: location.replace(TEMPLATE, ""),
|
46
|
+
file,
|
47
|
+
content,
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}
|
51
|
+
};
|
52
|
+
|
53
|
+
const archive = async (collection: IMigrateFile[]): Promise<void> => {
|
54
|
+
const body: string = JSON.stringify(collection, null, 4);
|
55
|
+
const content: string = `export const TEMPLATE = ${body}`;
|
56
|
+
|
57
|
+
try {
|
58
|
+
await fs.promises.mkdir(`${ROOT}/src/bundles`);
|
59
|
+
} catch {}
|
60
|
+
await fs.promises.writeFile(`${ROOT}/src/bundles/TEMPLATE.ts`, content);
|
61
|
+
};
|
62
|
+
|
63
|
+
const main = async (): Promise<void> => {
|
64
|
+
const collection: IMigrateFile[] = [];
|
65
|
+
await clone();
|
66
|
+
await iterate(collection)(TEMPLATE);
|
67
|
+
await archive(collection);
|
68
|
+
};
|
69
|
+
main().catch((exp) => {
|
70
|
+
console.error(exp);
|
71
|
+
process.exit(-1);
|
72
|
+
});
|
@@ -1,60 +1,59 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import fs from "fs";
|
3
|
-
import path from "path";
|
4
|
-
|
5
|
-
import {
|
6
|
-
import { ISwagger } from "../structures/ISwagger";
|
7
|
-
import { SetupWizard } from "../utils/SetupWizard";
|
8
|
-
|
9
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
10
|
-
|
11
|
-
npx @nestia/migrate [input] [output]
|
12
|
-
|
13
|
-
ex) npx @nestia/migrate swagger.json my-new-project
|
14
|
-
`;
|
15
|
-
|
16
|
-
function halt(desc: string): never {
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
const main = (argv: string[]) => {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
main(process.argv.slice(2));
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import fs from "fs";
|
3
|
+
import path from "path";
|
4
|
+
|
5
|
+
import { MigrateApplication } from "../MigrateApplication";
|
6
|
+
import { ISwagger } from "../structures/ISwagger";
|
7
|
+
import { SetupWizard } from "../utils/SetupWizard";
|
8
|
+
|
9
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
10
|
+
|
11
|
+
npx @nestia/migrate [input] [output]
|
12
|
+
|
13
|
+
ex) npx @nestia/migrate swagger.json my-new-project
|
14
|
+
`;
|
15
|
+
|
16
|
+
function halt(desc: string): never {
|
17
|
+
console.error(desc);
|
18
|
+
process.exit(-1);
|
19
|
+
}
|
20
|
+
|
21
|
+
const main = (argv: string[]) => {
|
22
|
+
const resolve = (str: string | undefined) =>
|
23
|
+
str ? path.resolve(str).split("\\").join("/") : undefined;
|
24
|
+
const input: string | undefined = resolve(argv[0]);
|
25
|
+
const output: string | undefined = resolve(argv[1]);
|
26
|
+
|
27
|
+
// VALIDATE ARGUMENTS
|
28
|
+
if (input === undefined || output === undefined) halt(USAGE);
|
29
|
+
|
30
|
+
// VALIDATE OUTPUT DIRECTORY
|
31
|
+
const parent: string = resolve(output + "/..")!;
|
32
|
+
if (fs.existsSync(output)) halt("Output directory alreay exists.");
|
33
|
+
else if (fs.existsSync(parent) === false)
|
34
|
+
halt("Output directory's parent directory does not exist.");
|
35
|
+
else if (fs.statSync(parent).isDirectory() === false)
|
36
|
+
halt("Output directory's parent is not a directory.");
|
37
|
+
|
38
|
+
// READ SWAGGER
|
39
|
+
const swagger: ISwagger = (() => {
|
40
|
+
if (fs.existsSync(input) === false)
|
41
|
+
halt("Unable to find the input swagger.json file.");
|
42
|
+
const stats: fs.Stats = fs.statSync(input);
|
43
|
+
if (stats.isFile() === false) halt("The input swagger.json is not a file.");
|
44
|
+
const content: string = fs.readFileSync(input, "utf-8");
|
45
|
+
const swagger: ISwagger = JSON.parse(content);
|
46
|
+
return swagger;
|
47
|
+
})();
|
48
|
+
|
49
|
+
// DO GENERATE
|
50
|
+
const app = new MigrateApplication(swagger);
|
51
|
+
app.generate({
|
52
|
+
mkdir: fs.mkdirSync,
|
53
|
+
writeFile: (path, content) => fs.writeFileSync(path, content, "utf8"),
|
54
|
+
})(output);
|
55
|
+
|
56
|
+
// RUN SCRIPTS
|
57
|
+
SetupWizard.setup(output);
|
58
|
+
};
|
59
|
+
main(process.argv.slice(2));
|
package/src/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import * as migrate from "./module";
|
2
|
-
|
3
|
-
export default migrate;
|
4
|
-
export * from "./module";
|
1
|
+
import * as migrate from "./module";
|
2
|
+
|
3
|
+
export default migrate;
|
4
|
+
export * from "./module";
|
package/src/module.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export * from "./
|
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";
|
@@ -1,118 +1,74 @@
|
|
1
|
-
import {
|
2
|
-
import
|
3
|
-
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
const
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
`}`,
|
76
|
-
);
|
77
|
-
}
|
78
|
-
return content.join("\n");
|
79
|
-
};
|
80
|
-
|
81
|
-
const describe = (schema: ISwaggerSchema): string | undefined => {
|
82
|
-
const content: string[] = [];
|
83
|
-
const add = (text: string) => {
|
84
|
-
if (schema.description && !schema.description.includes(text))
|
85
|
-
content.push(text);
|
86
|
-
};
|
87
|
-
if (schema.description) {
|
88
|
-
content.push(...schema.description.split("\n"));
|
89
|
-
if (!schema.description.split("\n").at(-1)?.startsWith("@"))
|
90
|
-
content.push("");
|
91
|
-
}
|
92
|
-
if (schema.deprecated) add("@deprecated");
|
93
|
-
if (schema.title) add(`@title ${schema.title}`);
|
94
|
-
return content.length ? content.join("\n") : undefined;
|
95
|
-
};
|
96
|
-
}
|
97
|
-
|
98
|
-
class Modulo {
|
99
|
-
public readonly dto: IMigrateDto;
|
100
|
-
public readonly children: Map<string, Modulo>;
|
101
|
-
|
102
|
-
public constructor(name: string) {
|
103
|
-
this.dto = {
|
104
|
-
name,
|
105
|
-
location: "src/api/structures",
|
106
|
-
schema: null,
|
107
|
-
children: [],
|
108
|
-
};
|
109
|
-
this.children = new Map();
|
110
|
-
}
|
111
|
-
|
112
|
-
public toDto(): IMigrateDto {
|
113
|
-
this.dto.children = Array.from(this.children.values()).map((modulo) =>
|
114
|
-
modulo.toDto(),
|
115
|
-
);
|
116
|
-
return this.dto;
|
117
|
-
}
|
118
|
-
}
|
1
|
+
import { IPointer } from "tstl";
|
2
|
+
import ts from "typescript";
|
3
|
+
|
4
|
+
import { ISwaggerSchema } from "../structures/ISwaggeSchema";
|
5
|
+
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
6
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
7
|
+
import { MapUtil } from "../utils/MapUtil";
|
8
|
+
import { ImportProgrammer } from "./ImportProgrammer";
|
9
|
+
import { SchemaProgrammer } from "./SchemaProgrammer";
|
10
|
+
|
11
|
+
export namespace DtoProgrammer {
|
12
|
+
export interface IModule {
|
13
|
+
name: string;
|
14
|
+
children: Map<string, IModule>;
|
15
|
+
programmer:
|
16
|
+
| null
|
17
|
+
| ((importer: ImportProgrammer) => ts.TypeAliasDeclaration);
|
18
|
+
}
|
19
|
+
|
20
|
+
export const write = (
|
21
|
+
components: ISwaggerComponents,
|
22
|
+
): Map<string, IModule> => {
|
23
|
+
const dict: Map<string, IModule> = new Map();
|
24
|
+
for (const [key, value] of Object.entries(components.schemas ?? {}))
|
25
|
+
prepare(dict)(key)((importer) =>
|
26
|
+
writeAlias(importer)(components)(key, value),
|
27
|
+
);
|
28
|
+
return dict;
|
29
|
+
};
|
30
|
+
|
31
|
+
const prepare =
|
32
|
+
(dict: Map<string, IModule>) =>
|
33
|
+
(name: string) =>
|
34
|
+
(programmer: (importer: ImportProgrammer) => ts.TypeAliasDeclaration) => {
|
35
|
+
const accessors: string[] = name.split(".");
|
36
|
+
const modulo: IPointer<IModule> = { value: null! };
|
37
|
+
|
38
|
+
accessors.forEach((acc, i) => {
|
39
|
+
modulo.value = MapUtil.take(dict)(acc)(() => ({
|
40
|
+
name: acc,
|
41
|
+
children: new Map(),
|
42
|
+
programmer: null,
|
43
|
+
}));
|
44
|
+
if (i === accessors.length - 1) modulo.value.programmer = programmer;
|
45
|
+
dict = modulo.value.children;
|
46
|
+
});
|
47
|
+
return modulo!;
|
48
|
+
};
|
49
|
+
|
50
|
+
const writeAlias =
|
51
|
+
(importer: ImportProgrammer) =>
|
52
|
+
(components: ISwaggerComponents) =>
|
53
|
+
(key: string, value: ISwaggerSchema) =>
|
54
|
+
FilePrinter.description(
|
55
|
+
ts.factory.createTypeAliasDeclaration(
|
56
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
57
|
+
key.split(".").at(-1)!,
|
58
|
+
[],
|
59
|
+
SchemaProgrammer.write(importer)(components)(value),
|
60
|
+
),
|
61
|
+
writeComment(value),
|
62
|
+
);
|
63
|
+
}
|
64
|
+
|
65
|
+
const writeComment = (schema: ISwaggerSchema): string =>
|
66
|
+
[
|
67
|
+
...(schema.description?.length ? [schema.description] : []),
|
68
|
+
...(schema.description?.length &&
|
69
|
+
(schema.title !== undefined || schema.deprecated === true)
|
70
|
+
? [""]
|
71
|
+
: []),
|
72
|
+
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
73
|
+
...(schema.deprecated === true ? [`@deprecated`] : []),
|
74
|
+
].join("\n");
|
@@ -1,60 +1,98 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
1
|
+
import ts from "typescript";
|
2
|
+
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
3
|
+
|
4
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
5
|
+
import { MapUtil } from "../utils/MapUtil";
|
6
|
+
|
7
|
+
export class ImportProgrammer {
|
8
|
+
private external_: Map<string, Set<string>> = new Map();
|
9
|
+
private dtos_: Set<string> = new Set();
|
10
|
+
|
11
|
+
public constructor() {}
|
12
|
+
|
13
|
+
public empty(): boolean {
|
14
|
+
return this.external_.size === 0 && this.dtos_.size === 0;
|
15
|
+
}
|
16
|
+
|
17
|
+
public external(props: ImportProgrammer.IProps): string {
|
18
|
+
MapUtil.take(this.external_)(props.library)(() => new Set()).add(
|
19
|
+
props.instance.split(".")[0],
|
20
|
+
);
|
21
|
+
return props.instance;
|
22
|
+
}
|
23
|
+
|
24
|
+
public dto(name: string): ts.TypeReferenceNode {
|
25
|
+
const file: string = name.split(".")[0];
|
26
|
+
this.dtos_.add(file);
|
27
|
+
return ts.factory.createTypeReferenceNode(name);
|
28
|
+
}
|
29
|
+
|
30
|
+
public tag(type: string, arg: number | string): ts.TypeReferenceNode {
|
31
|
+
this.external({
|
32
|
+
library: "typia",
|
33
|
+
instance: "tags",
|
34
|
+
});
|
35
|
+
return ts.factory.createTypeReferenceNode(`tags.${type}`, [
|
36
|
+
ts.factory.createLiteralTypeNode(
|
37
|
+
typeof arg === "string"
|
38
|
+
? ts.factory.createStringLiteral(arg)
|
39
|
+
: ExpressionFactory.number(arg),
|
40
|
+
),
|
41
|
+
]);
|
42
|
+
}
|
43
|
+
|
44
|
+
public toStatements(
|
45
|
+
dtoPath: (name: string) => string,
|
46
|
+
current?: string,
|
47
|
+
): ts.Statement[] {
|
48
|
+
return [
|
49
|
+
...[...this.external_.entries()].map(([library, properties]) =>
|
50
|
+
ts.factory.createImportDeclaration(
|
51
|
+
undefined,
|
52
|
+
ts.factory.createImportClause(
|
53
|
+
false,
|
54
|
+
undefined,
|
55
|
+
ts.factory.createNamedImports(
|
56
|
+
[...properties].map((i) =>
|
57
|
+
ts.factory.createImportSpecifier(
|
58
|
+
false,
|
59
|
+
undefined,
|
60
|
+
ts.factory.createIdentifier(i),
|
61
|
+
),
|
62
|
+
),
|
63
|
+
),
|
64
|
+
),
|
65
|
+
ts.factory.createStringLiteral(library),
|
66
|
+
),
|
67
|
+
),
|
68
|
+
...(this.external_.size && this.dtos_.size ? [FilePrinter.enter()] : []),
|
69
|
+
...[...this.dtos_]
|
70
|
+
.filter(
|
71
|
+
current ? (name) => name !== current!.split(".")[0] : () => true,
|
72
|
+
)
|
73
|
+
.map((i) =>
|
74
|
+
ts.factory.createImportDeclaration(
|
75
|
+
undefined,
|
76
|
+
ts.factory.createImportClause(
|
77
|
+
false,
|
78
|
+
undefined,
|
79
|
+
ts.factory.createNamedImports([
|
80
|
+
ts.factory.createImportSpecifier(
|
81
|
+
false,
|
82
|
+
undefined,
|
83
|
+
ts.factory.createIdentifier(i),
|
84
|
+
),
|
85
|
+
]),
|
86
|
+
),
|
87
|
+
ts.factory.createStringLiteral(dtoPath(i)),
|
88
|
+
),
|
89
|
+
),
|
90
|
+
];
|
91
|
+
}
|
92
|
+
}
|
93
|
+
export namespace ImportProgrammer {
|
94
|
+
export interface IProps {
|
95
|
+
library: string;
|
96
|
+
instance: string;
|
97
|
+
}
|
98
|
+
}
|