typia 3.8.0-dev.20230416 → 3.8.0-dev.20230418
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/README.md +35 -228
- package/lib/executable/setup/PackageManager.d.ts +1 -1
- package/lib/factories/TypiaFileFactory.js +9 -4
- package/lib/factories/TypiaFileFactory.js.map +1 -1
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +1 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/typings/Customizable.d.ts +2 -2
- package/lib/utils/RandomGenerator.d.ts +1 -17
- package/lib/utils/RandomGenerator.js.map +1 -1
- package/package.json +2 -2
- package/src/executable/TypiaSetupWizard.ts +118 -118
- package/src/executable/setup/PackageManager.ts +71 -71
- package/src/executable/typia.ts +52 -52
- package/src/factories/IdentifierFactory.ts +59 -59
- package/src/factories/TypiaFileFactory.ts +129 -120
- package/src/metadata/Metadata.ts +533 -533
- package/src/programmers/CheckerProgrammer.ts +920 -920
- package/src/programmers/internal/check_string_tags.ts +67 -67
- package/src/programmers/internal/check_template.ts +56 -56
- package/src/typings/Customizable.ts +5 -5
- package/src/utils/RandomGenerator.ts +96 -93
|
@@ -1,120 +1,129 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
import { ImportTransformer } from "../transformers/ImportTransformer";
|
|
6
|
-
|
|
7
|
-
import transform from "../transform";
|
|
8
|
-
|
|
9
|
-
export namespace TypiaFileFactory {
|
|
10
|
-
export interface IProps {
|
|
11
|
-
input: string;
|
|
12
|
-
output: string;
|
|
13
|
-
project: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function generate(
|
|
17
|
-
props: TypiaFileFactory.IProps,
|
|
18
|
-
): Promise<void> {
|
|
19
|
-
props.input = path.resolve(props.input);
|
|
20
|
-
props.output = path.resolve(props.output);
|
|
21
|
-
|
|
22
|
-
if ((await is_directory(props.input)) === false)
|
|
23
|
-
throw new Error(
|
|
24
|
-
"Error on TypiaGenerator.generate(): input path is not a directory.",
|
|
25
|
-
);
|
|
26
|
-
else if (fs.existsSync(props.output) === false)
|
|
27
|
-
await fs.promises.mkdir(props.output, { recursive: true });
|
|
28
|
-
else if ((await is_directory(props.output)) === false) {
|
|
29
|
-
const parent: string = path.join(props.output, "..");
|
|
30
|
-
if ((await is_directory(parent)) === false)
|
|
31
|
-
throw new Error(
|
|
32
|
-
"Error on TypiaGenerator.generate(): output path is not a directory.",
|
|
33
|
-
);
|
|
34
|
-
await fs.promises.mkdir(props.output);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// CREATE PROGRAM
|
|
38
|
-
const {
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
content
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { ImportTransformer } from "../transformers/ImportTransformer";
|
|
6
|
+
|
|
7
|
+
import transform from "../transform";
|
|
8
|
+
|
|
9
|
+
export namespace TypiaFileFactory {
|
|
10
|
+
export interface IProps {
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
project: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function generate(
|
|
17
|
+
props: TypiaFileFactory.IProps,
|
|
18
|
+
): Promise<void> {
|
|
19
|
+
props.input = path.resolve(props.input);
|
|
20
|
+
props.output = path.resolve(props.output);
|
|
21
|
+
|
|
22
|
+
if ((await is_directory(props.input)) === false)
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Error on TypiaGenerator.generate(): input path is not a directory.",
|
|
25
|
+
);
|
|
26
|
+
else if (fs.existsSync(props.output) === false)
|
|
27
|
+
await fs.promises.mkdir(props.output, { recursive: true });
|
|
28
|
+
else if ((await is_directory(props.output)) === false) {
|
|
29
|
+
const parent: string = path.join(props.output, "..");
|
|
30
|
+
if ((await is_directory(parent)) === false)
|
|
31
|
+
throw new Error(
|
|
32
|
+
"Error on TypiaGenerator.generate(): output path is not a directory.",
|
|
33
|
+
);
|
|
34
|
+
await fs.promises.mkdir(props.output);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// CREATE PROGRAM
|
|
38
|
+
const { options: compilerOptions } = ts.parseJsonConfigFileContent(
|
|
39
|
+
ts.readConfigFile(props.project, ts.sys.readFile).config,
|
|
40
|
+
{
|
|
41
|
+
fileExists: ts.sys.fileExists,
|
|
42
|
+
readFile: ts.sys.readFile,
|
|
43
|
+
readDirectory: ts.sys.readDirectory,
|
|
44
|
+
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
45
|
+
},
|
|
46
|
+
path.dirname(props.project),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const program: ts.Program = ts.createProgram(
|
|
50
|
+
await (async () => {
|
|
51
|
+
const container: string[] = [];
|
|
52
|
+
await gather(props)(container)(props.input)(props.output);
|
|
53
|
+
return container;
|
|
54
|
+
})(),
|
|
55
|
+
compilerOptions,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// DO TRANSFORM
|
|
59
|
+
const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
|
|
60
|
+
program
|
|
61
|
+
.getSourceFiles()
|
|
62
|
+
.filter(
|
|
63
|
+
(file) =>
|
|
64
|
+
!file.isDeclarationFile &&
|
|
65
|
+
path.resolve(file.fileName).indexOf(props.input) !== -1,
|
|
66
|
+
),
|
|
67
|
+
[
|
|
68
|
+
ImportTransformer.transform(props.input)(props.output),
|
|
69
|
+
transform(
|
|
70
|
+
program,
|
|
71
|
+
((compilerOptions.plugins as any[]) ?? []).find(
|
|
72
|
+
(p: any) =>
|
|
73
|
+
p.transform === "typia/lib/transform" ||
|
|
74
|
+
p.transform === "../src/transform.ts",
|
|
75
|
+
) ?? {},
|
|
76
|
+
),
|
|
77
|
+
],
|
|
78
|
+
program.getCompilerOptions(),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// ARCHIVE TRANSFORMED FILES
|
|
82
|
+
const printer: ts.Printer = ts.createPrinter({
|
|
83
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
84
|
+
});
|
|
85
|
+
for (const file of result.transformed) {
|
|
86
|
+
const to: string = path
|
|
87
|
+
.resolve(file.fileName)
|
|
88
|
+
.replace(props.input, props.output);
|
|
89
|
+
|
|
90
|
+
const content: string = printer.printFile(file);
|
|
91
|
+
await fs.promises.writeFile(to, emend(content), "utf8");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const emend = (content: string): string => {
|
|
96
|
+
if (
|
|
97
|
+
content.indexOf("typia.") === -1 ||
|
|
98
|
+
content.indexOf("import typia") !== -1 ||
|
|
99
|
+
content.indexOf("import * as typia") !== -1
|
|
100
|
+
)
|
|
101
|
+
return content;
|
|
102
|
+
return `import typia from "typia";\n\n${content}`;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const is_directory = async (current: string): Promise<boolean> => {
|
|
106
|
+
const stat: fs.Stats = await fs.promises.stat(current);
|
|
107
|
+
return stat.isDirectory();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const gather =
|
|
111
|
+
(props: IProps) =>
|
|
112
|
+
(container: string[]) =>
|
|
113
|
+
(from: string) =>
|
|
114
|
+
async (to: string) => {
|
|
115
|
+
if (from === props.output) return;
|
|
116
|
+
else if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
|
|
117
|
+
|
|
118
|
+
for (const file of await fs.promises.readdir(from)) {
|
|
119
|
+
const next: string = path.join(from, file);
|
|
120
|
+
const stat: fs.Stats = await fs.promises.stat(next);
|
|
121
|
+
|
|
122
|
+
if (stat.isDirectory()) {
|
|
123
|
+
await gather(props)(container)(next)(path.join(to, file));
|
|
124
|
+
continue;
|
|
125
|
+
} else if (file.substring(file.length - 3) === ".ts")
|
|
126
|
+
container.push(next);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|