typia 3.4.13 → 3.4.14
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 +9 -8
- package/lib/factories/internal/iterate_metadata_object.js +4 -2
- package/lib/factories/internal/iterate_metadata_object.js.map +1 -1
- package/package.json +1 -1
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/TypiaSetupWizard.ts +175 -175
- package/src/executable/typia.ts +46 -46
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/MetadataTagFactory.ts +347 -347
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/MetadataHelper.ts +12 -12
- package/src/factories/internal/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/explore_metadata.ts +91 -91
- package/src/factories/internal/iterate_metadata.ts +80 -80
- package/src/factories/internal/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/iterate_metadata_object.ts +48 -45
- package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/iterate_metadata_union.ts +59 -59
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$number.ts +19 -19
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +122 -122
- package/src/metadata/Metadata.ts +477 -477
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertParseProgrammer.ts +45 -45
- package/src/programmers/AssertProgrammer.ts +444 -444
- package/src/programmers/AssertStringifyProgrammer.ts +45 -45
- package/src/programmers/CheckerProgrammer.ts +804 -804
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +51 -51
- package/src/programmers/IsProgrammer.ts +172 -172
- package/src/programmers/IsStringifyProgrammer.ts +49 -49
- package/src/programmers/StringifyProgrammer.ts +756 -756
- package/src/programmers/ValidateParseProgrammer.ts +49 -49
- package/src/programmers/ValidateProgrammer.ts +236 -236
- package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +11 -11
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_schema.ts +221 -221
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_number.ts +178 -178
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transform.ts +20 -20
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +4 -4
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
import type Comment from "comment-json";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
export namespace TypiaSetupWizard {
|
|
6
|
-
export async function ttypescript(manager: string): Promise<void> {
|
|
7
|
-
// INSTALL
|
|
8
|
-
const pack: any = await prepare(manager);
|
|
9
|
-
add(manager)(pack)("ttypescript", true);
|
|
10
|
-
add(manager)(pack)("ts-node", true);
|
|
11
|
-
|
|
12
|
-
// TSCONFIG.JSON
|
|
13
|
-
await configure(manager)(pack);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function tsPatch(manager: string): Promise<void> {
|
|
17
|
-
// INSTALL
|
|
18
|
-
add(manager)(await prepare(manager))("ts-patch", true);
|
|
19
|
-
execute("npx ts-patch install");
|
|
20
|
-
|
|
21
|
-
// PACKAGE.JSON
|
|
22
|
-
const pack: any = JSON.parse(
|
|
23
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
24
|
-
);
|
|
25
|
-
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
26
|
-
pack.scripts = {};
|
|
27
|
-
if (typeof pack.scripts.prepare === "string") {
|
|
28
|
-
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
29
|
-
pack.scripts.prepare =
|
|
30
|
-
"ts-patch install && " + pack.scripts.prepare;
|
|
31
|
-
} else pack.scripts.prepare = "ts-patch install";
|
|
32
|
-
|
|
33
|
-
await fs.promises.writeFile(
|
|
34
|
-
"package.json",
|
|
35
|
-
JSON.stringify(pack, null, 2),
|
|
36
|
-
"utf8",
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// TSCONFIG.JSON
|
|
40
|
-
await configure(manager)(pack);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function prepare(manager: string): Promise<any> {
|
|
44
|
-
if (fs.existsSync("package.json") === false)
|
|
45
|
-
halt(() => {})("make package.json file or move to it.");
|
|
46
|
-
|
|
47
|
-
const pack: any = JSON.parse(
|
|
48
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
49
|
-
);
|
|
50
|
-
const wizard = add(manager)(pack);
|
|
51
|
-
|
|
52
|
-
wizard("typia", false);
|
|
53
|
-
wizard("typescript", true);
|
|
54
|
-
return pack;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const configure =
|
|
58
|
-
(manager: string) =>
|
|
59
|
-
async (pack: any): Promise<void> => {
|
|
60
|
-
// VALIDATE PRERATATION
|
|
61
|
-
if (fs.existsSync("tsconfig.json") === false) {
|
|
62
|
-
execute("npx tsc --init");
|
|
63
|
-
if (fs.existsSync("tsconfig.json") === false)
|
|
64
|
-
halt(() => {})("tsconfig.json file does not exist.");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const temporary: boolean = !fs.existsSync(
|
|
68
|
-
"node_modules/comment-json",
|
|
69
|
-
);
|
|
70
|
-
if (temporary === true) add(manager)(pack)("comment-json", true);
|
|
71
|
-
|
|
72
|
-
const halter: (msg: string) => never = halt(() => {
|
|
73
|
-
if (temporary === true) remove(manager)("comment-json", true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// READ TSCONFIG FILE
|
|
77
|
-
const Comment: typeof import("comment-json") = await import(
|
|
78
|
-
process.cwd() + "/node_modules/comment-json"
|
|
79
|
-
);
|
|
80
|
-
const config: Comment.CommentObject = Comment.parse(
|
|
81
|
-
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
82
|
-
) as Comment.CommentObject;
|
|
83
|
-
const options = config.compilerOptions as
|
|
84
|
-
| Comment.CommentObject
|
|
85
|
-
| undefined;
|
|
86
|
-
if (options === undefined)
|
|
87
|
-
halter(
|
|
88
|
-
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
92
|
-
(() => {
|
|
93
|
-
const plugins = options.plugins as
|
|
94
|
-
| Comment.CommentArray<Comment.CommentObject>
|
|
95
|
-
| undefined;
|
|
96
|
-
if (plugins === undefined)
|
|
97
|
-
return (options.plugins = [] as any);
|
|
98
|
-
else if (!Array.isArray(plugins))
|
|
99
|
-
halter(
|
|
100
|
-
`"plugins" property of tsconfig.json must be array type.`,
|
|
101
|
-
);
|
|
102
|
-
return plugins;
|
|
103
|
-
})();
|
|
104
|
-
|
|
105
|
-
// CHECK WHETHER CONFIGURED
|
|
106
|
-
const strict: boolean = options.strict === true;
|
|
107
|
-
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
108
|
-
(p) =>
|
|
109
|
-
typeof p === "object" &&
|
|
110
|
-
p !== null &&
|
|
111
|
-
p.transform === "typia/lib/transform",
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (strict === true && oldbie !== undefined) {
|
|
115
|
-
console.log(
|
|
116
|
-
"you've been already configured the tsconfig.json file.",
|
|
117
|
-
);
|
|
118
|
-
} else {
|
|
119
|
-
// DO CONFIGURE
|
|
120
|
-
options.strict = true;
|
|
121
|
-
if (oldbie === undefined)
|
|
122
|
-
plugins.push(
|
|
123
|
-
Comment.parse(`{
|
|
124
|
-
"transform": "typia/lib/transform",
|
|
125
|
-
"numeric": true, // check isNaN() and isFinite()
|
|
126
|
-
"functional": false, // validate function type
|
|
127
|
-
}`) as Comment.CommentObject,
|
|
128
|
-
);
|
|
129
|
-
await fs.promises.writeFile(
|
|
130
|
-
"tsconfig.json",
|
|
131
|
-
Comment.stringify(config, null, 2),
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
if (temporary === true) remove(manager)("comment-json", false);
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const add =
|
|
139
|
-
(manager: string) =>
|
|
140
|
-
(pack: any) =>
|
|
141
|
-
(modulo: string, devOnly: boolean): void => {
|
|
142
|
-
const exists: boolean =
|
|
143
|
-
(devOnly === false
|
|
144
|
-
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
145
|
-
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
146
|
-
fs.existsSync("node_modules/" + modulo);
|
|
147
|
-
const middle: string =
|
|
148
|
-
manager === "yarn"
|
|
149
|
-
? `add${devOnly ? " -D" : ""}`
|
|
150
|
-
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
151
|
-
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const remove =
|
|
155
|
-
(manager: string) =>
|
|
156
|
-
(modulo: string, devOnly: boolean): void => {
|
|
157
|
-
const middle: string =
|
|
158
|
-
manager === "yarn"
|
|
159
|
-
? `remove${devOnly ? " -D" : ""}`
|
|
160
|
-
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
161
|
-
execute(`${manager} ${middle} ${modulo}`);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const halt =
|
|
165
|
-
(closer: () => any) =>
|
|
166
|
-
(desc: string): never => {
|
|
167
|
-
closer();
|
|
168
|
-
console.error(desc);
|
|
169
|
-
process.exit(-1);
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
function execute(command: string): void {
|
|
173
|
-
console.log(command);
|
|
174
|
-
cp.execSync(command, { stdio: "inherit" });
|
|
175
|
-
}
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
import type Comment from "comment-json";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
export namespace TypiaSetupWizard {
|
|
6
|
+
export async function ttypescript(manager: string): Promise<void> {
|
|
7
|
+
// INSTALL
|
|
8
|
+
const pack: any = await prepare(manager);
|
|
9
|
+
add(manager)(pack)("ttypescript", true);
|
|
10
|
+
add(manager)(pack)("ts-node", true);
|
|
11
|
+
|
|
12
|
+
// TSCONFIG.JSON
|
|
13
|
+
await configure(manager)(pack);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function tsPatch(manager: string): Promise<void> {
|
|
17
|
+
// INSTALL
|
|
18
|
+
add(manager)(await prepare(manager))("ts-patch", true);
|
|
19
|
+
execute("npx ts-patch install");
|
|
20
|
+
|
|
21
|
+
// PACKAGE.JSON
|
|
22
|
+
const pack: any = JSON.parse(
|
|
23
|
+
await fs.promises.readFile("package.json", "utf8"),
|
|
24
|
+
);
|
|
25
|
+
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
26
|
+
pack.scripts = {};
|
|
27
|
+
if (typeof pack.scripts.prepare === "string") {
|
|
28
|
+
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
29
|
+
pack.scripts.prepare =
|
|
30
|
+
"ts-patch install && " + pack.scripts.prepare;
|
|
31
|
+
} else pack.scripts.prepare = "ts-patch install";
|
|
32
|
+
|
|
33
|
+
await fs.promises.writeFile(
|
|
34
|
+
"package.json",
|
|
35
|
+
JSON.stringify(pack, null, 2),
|
|
36
|
+
"utf8",
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// TSCONFIG.JSON
|
|
40
|
+
await configure(manager)(pack);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function prepare(manager: string): Promise<any> {
|
|
44
|
+
if (fs.existsSync("package.json") === false)
|
|
45
|
+
halt(() => {})("make package.json file or move to it.");
|
|
46
|
+
|
|
47
|
+
const pack: any = JSON.parse(
|
|
48
|
+
await fs.promises.readFile("package.json", "utf8"),
|
|
49
|
+
);
|
|
50
|
+
const wizard = add(manager)(pack);
|
|
51
|
+
|
|
52
|
+
wizard("typia", false);
|
|
53
|
+
wizard("typescript", true);
|
|
54
|
+
return pack;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const configure =
|
|
58
|
+
(manager: string) =>
|
|
59
|
+
async (pack: any): Promise<void> => {
|
|
60
|
+
// VALIDATE PRERATATION
|
|
61
|
+
if (fs.existsSync("tsconfig.json") === false) {
|
|
62
|
+
execute("npx tsc --init");
|
|
63
|
+
if (fs.existsSync("tsconfig.json") === false)
|
|
64
|
+
halt(() => {})("tsconfig.json file does not exist.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const temporary: boolean = !fs.existsSync(
|
|
68
|
+
"node_modules/comment-json",
|
|
69
|
+
);
|
|
70
|
+
if (temporary === true) add(manager)(pack)("comment-json", true);
|
|
71
|
+
|
|
72
|
+
const halter: (msg: string) => never = halt(() => {
|
|
73
|
+
if (temporary === true) remove(manager)("comment-json", true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// READ TSCONFIG FILE
|
|
77
|
+
const Comment: typeof import("comment-json") = await import(
|
|
78
|
+
process.cwd() + "/node_modules/comment-json"
|
|
79
|
+
);
|
|
80
|
+
const config: Comment.CommentObject = Comment.parse(
|
|
81
|
+
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
82
|
+
) as Comment.CommentObject;
|
|
83
|
+
const options = config.compilerOptions as
|
|
84
|
+
| Comment.CommentObject
|
|
85
|
+
| undefined;
|
|
86
|
+
if (options === undefined)
|
|
87
|
+
halter(
|
|
88
|
+
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
92
|
+
(() => {
|
|
93
|
+
const plugins = options.plugins as
|
|
94
|
+
| Comment.CommentArray<Comment.CommentObject>
|
|
95
|
+
| undefined;
|
|
96
|
+
if (plugins === undefined)
|
|
97
|
+
return (options.plugins = [] as any);
|
|
98
|
+
else if (!Array.isArray(plugins))
|
|
99
|
+
halter(
|
|
100
|
+
`"plugins" property of tsconfig.json must be array type.`,
|
|
101
|
+
);
|
|
102
|
+
return plugins;
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
// CHECK WHETHER CONFIGURED
|
|
106
|
+
const strict: boolean = options.strict === true;
|
|
107
|
+
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
108
|
+
(p) =>
|
|
109
|
+
typeof p === "object" &&
|
|
110
|
+
p !== null &&
|
|
111
|
+
p.transform === "typia/lib/transform",
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
if (strict === true && oldbie !== undefined) {
|
|
115
|
+
console.log(
|
|
116
|
+
"you've been already configured the tsconfig.json file.",
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
// DO CONFIGURE
|
|
120
|
+
options.strict = true;
|
|
121
|
+
if (oldbie === undefined)
|
|
122
|
+
plugins.push(
|
|
123
|
+
Comment.parse(`{
|
|
124
|
+
"transform": "typia/lib/transform",
|
|
125
|
+
"numeric": true, // check isNaN() and isFinite()
|
|
126
|
+
"functional": false, // validate function type
|
|
127
|
+
}`) as Comment.CommentObject,
|
|
128
|
+
);
|
|
129
|
+
await fs.promises.writeFile(
|
|
130
|
+
"tsconfig.json",
|
|
131
|
+
Comment.stringify(config, null, 2),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (temporary === true) remove(manager)("comment-json", false);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const add =
|
|
139
|
+
(manager: string) =>
|
|
140
|
+
(pack: any) =>
|
|
141
|
+
(modulo: string, devOnly: boolean): void => {
|
|
142
|
+
const exists: boolean =
|
|
143
|
+
(devOnly === false
|
|
144
|
+
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
145
|
+
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
146
|
+
fs.existsSync("node_modules/" + modulo);
|
|
147
|
+
const middle: string =
|
|
148
|
+
manager === "yarn"
|
|
149
|
+
? `add${devOnly ? " -D" : ""}`
|
|
150
|
+
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
151
|
+
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const remove =
|
|
155
|
+
(manager: string) =>
|
|
156
|
+
(modulo: string, devOnly: boolean): void => {
|
|
157
|
+
const middle: string =
|
|
158
|
+
manager === "yarn"
|
|
159
|
+
? `remove${devOnly ? " -D" : ""}`
|
|
160
|
+
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
161
|
+
execute(`${manager} ${middle} ${modulo}`);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const halt =
|
|
165
|
+
(closer: () => any) =>
|
|
166
|
+
(desc: string): never => {
|
|
167
|
+
closer();
|
|
168
|
+
console.error(desc);
|
|
169
|
+
process.exit(-1);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
function execute(command: string): void {
|
|
173
|
+
console.log(command);
|
|
174
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
175
|
+
}
|
package/src/executable/typia.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { CommandParser } from "./internal/CommandParser";
|
|
3
|
-
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
4
|
-
|
|
5
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
|
6
|
-
|
|
7
|
-
npx typia setup \\
|
|
8
|
-
--compiler (ttypescript|ts-patch) \\
|
|
9
|
-
--manager (npm|pnpm|yarn)
|
|
10
|
-
|
|
11
|
-
- npx typia setup
|
|
12
|
-
- npx typia setup --compiler ttypescript
|
|
13
|
-
- npx typia setup --compiler ts-patch
|
|
14
|
-
- npx typia setup --manager pnpm`;
|
|
15
|
-
|
|
16
|
-
function halt(desc: string): never {
|
|
17
|
-
console.error(desc);
|
|
18
|
-
process.exit(-1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function setup(): Promise<void> {
|
|
22
|
-
const options: Record<string, string> = CommandParser.parse(
|
|
23
|
-
process.argv.slice(3),
|
|
24
|
-
);
|
|
25
|
-
const manager: string = options.manager ?? "npm";
|
|
26
|
-
const compiler: string = options.compiler ?? "ttypescript";
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
(compiler !== "ttypescript" && compiler !== "ts-patch") ||
|
|
30
|
-
(manager !== "npm" && manager !== "pnpm" && manager !== "yarn")
|
|
31
|
-
)
|
|
32
|
-
halt(USAGE);
|
|
33
|
-
else if (compiler === "ttypescript")
|
|
34
|
-
await TypiaSetupWizard.ttypescript(manager);
|
|
35
|
-
else await TypiaSetupWizard.tsPatch(manager);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function main(): Promise<void> {
|
|
39
|
-
const type: string | undefined = process.argv[2];
|
|
40
|
-
if (type === "setup") await setup();
|
|
41
|
-
else halt(USAGE);
|
|
42
|
-
}
|
|
43
|
-
main().catch((exp) => {
|
|
44
|
-
console.error(exp);
|
|
45
|
-
process.exit(-1);
|
|
46
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CommandParser } from "./internal/CommandParser";
|
|
3
|
+
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
4
|
+
|
|
5
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
6
|
+
|
|
7
|
+
npx typia setup \\
|
|
8
|
+
--compiler (ttypescript|ts-patch) \\
|
|
9
|
+
--manager (npm|pnpm|yarn)
|
|
10
|
+
|
|
11
|
+
- npx typia setup
|
|
12
|
+
- npx typia setup --compiler ttypescript
|
|
13
|
+
- npx typia setup --compiler ts-patch
|
|
14
|
+
- npx typia setup --manager pnpm`;
|
|
15
|
+
|
|
16
|
+
function halt(desc: string): never {
|
|
17
|
+
console.error(desc);
|
|
18
|
+
process.exit(-1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function setup(): Promise<void> {
|
|
22
|
+
const options: Record<string, string> = CommandParser.parse(
|
|
23
|
+
process.argv.slice(3),
|
|
24
|
+
);
|
|
25
|
+
const manager: string = options.manager ?? "npm";
|
|
26
|
+
const compiler: string = options.compiler ?? "ttypescript";
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
(compiler !== "ttypescript" && compiler !== "ts-patch") ||
|
|
30
|
+
(manager !== "npm" && manager !== "pnpm" && manager !== "yarn")
|
|
31
|
+
)
|
|
32
|
+
halt(USAGE);
|
|
33
|
+
else if (compiler === "ttypescript")
|
|
34
|
+
await TypiaSetupWizard.ttypescript(manager);
|
|
35
|
+
else await TypiaSetupWizard.tsPatch(manager);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function main(): Promise<void> {
|
|
39
|
+
const type: string | undefined = process.argv[2];
|
|
40
|
+
if (type === "setup") await setup();
|
|
41
|
+
else halt(USAGE);
|
|
42
|
+
}
|
|
43
|
+
main().catch((exp) => {
|
|
44
|
+
console.error(exp);
|
|
45
|
+
process.exit(-1);
|
|
46
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
-
return comments
|
|
6
|
-
.map((part) => part.text)
|
|
7
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
-
.join("");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
+
return comments
|
|
6
|
+
.map((part) => part.text)
|
|
7
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
+
.join("");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
-
return ts.factory.createStrictInequality(
|
|
6
|
-
ts.factory.createIdentifier("undefined"),
|
|
7
|
-
input,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
-
return ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
-
undefined,
|
|
15
|
-
[input],
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject(
|
|
20
|
-
input: ts.Expression,
|
|
21
|
-
options: {
|
|
22
|
-
checkNull: boolean;
|
|
23
|
-
checkArray: boolean;
|
|
24
|
-
},
|
|
25
|
-
): ts.Expression {
|
|
26
|
-
const conditions: ts.Expression[] = [
|
|
27
|
-
ts.factory.createStrictEquality(
|
|
28
|
-
ts.factory.createStringLiteral("object"),
|
|
29
|
-
ts.factory.createTypeOfExpression(input),
|
|
30
|
-
),
|
|
31
|
-
];
|
|
32
|
-
if (options.checkNull === true)
|
|
33
|
-
conditions.push(
|
|
34
|
-
ts.factory.createStrictInequality(
|
|
35
|
-
ts.factory.createNull(),
|
|
36
|
-
input,
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
if (options.checkArray === true)
|
|
40
|
-
conditions.push(
|
|
41
|
-
ts.factory.createStrictEquality(
|
|
42
|
-
ts.factory.createFalse(),
|
|
43
|
-
ts.factory.createCallExpression(
|
|
44
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
-
undefined,
|
|
46
|
-
[input],
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return conditions.length === 1
|
|
52
|
-
? conditions[0]!
|
|
53
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isInstanceOf(
|
|
57
|
-
input: ts.Expression,
|
|
58
|
-
type: string,
|
|
59
|
-
): ts.Expression {
|
|
60
|
-
return ts.factory.createBinaryExpression(
|
|
61
|
-
input,
|
|
62
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
-
ts.factory.createIdentifier(type),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
+
return ts.factory.createStrictInequality(
|
|
6
|
+
ts.factory.createIdentifier("undefined"),
|
|
7
|
+
input,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
+
return ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
+
undefined,
|
|
15
|
+
[input],
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isObject(
|
|
20
|
+
input: ts.Expression,
|
|
21
|
+
options: {
|
|
22
|
+
checkNull: boolean;
|
|
23
|
+
checkArray: boolean;
|
|
24
|
+
},
|
|
25
|
+
): ts.Expression {
|
|
26
|
+
const conditions: ts.Expression[] = [
|
|
27
|
+
ts.factory.createStrictEquality(
|
|
28
|
+
ts.factory.createStringLiteral("object"),
|
|
29
|
+
ts.factory.createTypeOfExpression(input),
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
if (options.checkNull === true)
|
|
33
|
+
conditions.push(
|
|
34
|
+
ts.factory.createStrictInequality(
|
|
35
|
+
ts.factory.createNull(),
|
|
36
|
+
input,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
if (options.checkArray === true)
|
|
40
|
+
conditions.push(
|
|
41
|
+
ts.factory.createStrictEquality(
|
|
42
|
+
ts.factory.createFalse(),
|
|
43
|
+
ts.factory.createCallExpression(
|
|
44
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
+
undefined,
|
|
46
|
+
[input],
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return conditions.length === 1
|
|
52
|
+
? conditions[0]!
|
|
53
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isInstanceOf(
|
|
57
|
+
input: ts.Expression,
|
|
58
|
+
type: string,
|
|
59
|
+
): ts.Expression {
|
|
60
|
+
return ts.factory.createBinaryExpression(
|
|
61
|
+
input,
|
|
62
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
+
ts.factory.createIdentifier(type),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|