typia 3.4.4 → 3.4.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/README.md +5 -47
- package/lib/executable/internal/TypiaSetupWizard.js +8 -6
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/internal/TypiaSetupWizard.ts +148 -149
- package/src/executable/typia.ts +35 -35
- package/src/factories/MetadataTagFactory.ts +347 -347
- package/src/factories/internal/iterate_metadata.ts +81 -81
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/functional/$number.ts +19 -19
- package/src/index.ts +4 -4
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/StringifyProgrammer.ts +746 -746
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- 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/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Just type `npx typia setup`, that's all.
|
|
|
51
51
|
|
|
52
52
|
After the setup, you can compile `typia` utilized code by using `ttsc` ([`ttypescript`](https://github.com/cevek/ttypescript)) command. If you want to run your TypeScript file directly through `ts-node`, add `-C ttypescript` argument like below:
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
```bash
|
|
55
55
|
# COMPILE THROUGH TTYPESCRIPT
|
|
56
56
|
npx ttsc
|
|
57
57
|
|
|
@@ -59,28 +59,10 @@ npx ttsc
|
|
|
59
59
|
npx ts-node -C ttypescript src/index.ts
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
> If you want to use only `tsc` command, you can choose another option: [`ts-patch`](https://github.com/nonara/ts-patch).
|
|
63
|
-
>
|
|
64
|
-
> Set it up through `npx typia setup ts-patch` command and compile your project with pure(?) TypeScript compiler (`tsc`). When you want to run your TypeScript file directly, just use the pure `ts-node`, too.
|
|
65
|
-
>
|
|
66
|
-
> However, note that, the `ts-patch` will modify JavaScript files in `node_modules/typescript` directly. Therefore, it may cause some problems when you update typescript version after the `setup` process, until running `npm run prepare` command.
|
|
67
|
-
>
|
|
68
|
-
> ```bash
|
|
69
|
-
> # SETUP
|
|
70
|
-
> npx typia setup ts-patch
|
|
71
|
-
>
|
|
72
|
-
> #COMPILE
|
|
73
|
-
> npx tsc
|
|
74
|
-
> npx ts-node src/index.ts
|
|
75
|
-
>
|
|
76
|
-
> # AFTER UPDATE, HAVE TO RUN PREPARE COMMAND
|
|
77
|
-
> npm install --save-dev typescript@latest
|
|
78
|
-
> npm run prepare
|
|
79
|
-
> ``` -->
|
|
80
|
-
|
|
81
62
|
### Manual Setup
|
|
82
63
|
If you want to install and setup `typia` manually, read [Guide Documents - Setup](https://github.com/samchon/typia/wiki/Setup).
|
|
83
64
|
|
|
65
|
+
- [Setup Wizard](https://github.com/samchon/typia/wiki/Setup#setup-wizard)
|
|
84
66
|
- [NPM Packages](https://github.com/samchon/typia/wiki/Setup#npm-packages)
|
|
85
67
|
- [`tsconfig.json`](https://github.com/samchon/typia/wiki/Setup#tsconfigjson)
|
|
86
68
|
- [vite](https://github.com/samchon/typia/wiki/Setup#vite)
|
|
@@ -89,7 +71,7 @@ If you want to install and setup `typia` manually, read [Guide Documents - Setup
|
|
|
89
71
|
### vite
|
|
90
72
|
When you want to setup `typia` on your frontend project with [`vite`](https://vitejs.dev/), just configure `vite.config.ts` like below.
|
|
91
73
|
|
|
92
|
-
For reference, don't forget [
|
|
74
|
+
For reference, don't forget running [Setup Wizard](#setup-wizard) before.
|
|
93
75
|
|
|
94
76
|
```typescript
|
|
95
77
|
import { defineConfig } from "vite";
|
|
@@ -116,7 +98,7 @@ export default defineConfig({
|
|
|
116
98
|
|
|
117
99
|
In here README documents, only summarized informations are provided.
|
|
118
100
|
|
|
119
|
-
For more details,
|
|
101
|
+
For more details, refer to the [Guide Documents (wiki)](https://github.com/samchon/typia/wiki).
|
|
120
102
|
|
|
121
103
|
> - **Runtime Validators**
|
|
122
104
|
> - [powerful validator](https://github.com/samchon/typia/wiki/Runtime-Validators#powerful-validator)
|
|
@@ -163,31 +145,7 @@ export function createValidateEquals<T>(): (input: unknown) => IValidation<T>;
|
|
|
163
145
|
|
|
164
146
|
Also, if you want more strict validator functions that even do not allowing superfluous properties not written in the type `T`, you can use those functions instead; `equals()`, `assertEquals()`, `validateEquals()`. Otherwise you want to create resuable validator functions, you can utilize factory functions like `createIs()` instead.
|
|
165
147
|
|
|
166
|
-
When you want to add special validation logics, like limiting range of numeric values, you can do it through comment tags. If you want to know about it,
|
|
167
|
-
|
|
168
|
-
<!-- > By the way, comparing those validator functions with other competitive libaries, you can find that only `typia` is able to validate complicate union type. It is because `typia` is supporting entire TypeScript type specs. Therefore, adapt `typia` with confidence. It can validate everything.
|
|
169
|
-
>
|
|
170
|
-
> Moreover, validation speed of `typia` is extremely faster than any other validation libraries. For an example, `typia` is maximum 15,000x times faster than `class-validator`. Visit [benchmarks](https://github.com/samchon/typia/wiki/Benchmarks#validate-functions) section of Guide Documents and feel how fast `typia` is.
|
|
171
|
-
>
|
|
172
|
-
> Components | `typia` | `TypeBox` | `ajv` | `io-ts` | `zod` | `C.V.`
|
|
173
|
-
> -------------------------|--------|-----------|-------|---------|-------|------------------
|
|
174
|
-
> **Easy to use** | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
175
|
-
> [Object (simple)](https://github.com/samchon/typia/blob/master/test/structures/ObjectSimple.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
176
|
-
> [Object (hierarchical)](https://github.com/samchon/typia/blob/master/test/structures/ObjectHierarchical.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
177
|
-
> [Object (recursive)](https://github.com/samchon/typia/blob/master/test/structures/ObjectRecursive.ts) | ✔ | ❌ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
178
|
-
> [Object (union, implicit)](https://github.com/samchon/typia/blob/master/test/structures/ObjectUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
179
|
-
> [Object (union, explicit)](https://github.com/samchon/typia/blob/master/test/structures/ObjectUnionExplicit.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌
|
|
180
|
-
> [Object (additional tags)](https://github.com/samchon/typia/#comment-tags) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
181
|
-
> [Object (template literal types)](https://github.com/samchon/typia/blob/master/test/structures/TemplateUnion.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
182
|
-
> [Object (dynamic properties)](https://github.com/samchon/typia/blob/master/test/structures/DynamicTemplate.ts) | ✔ | ✔ | ✔ | ❌ | ❌ | ❌
|
|
183
|
-
> [Array (hierarchical)](https://github.com/samchon/typia/blob/master/test/structures/ArrayHierarchical.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
|
|
184
|
-
> [Array (recursive)](https://github.com/samchon/typia/blob/master/test/structures/ArrayRecursive.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌
|
|
185
|
-
> [Array (recursive, union)](https://github.com/samchon/typia/blob/master/test/structures/ArrayRecursiveUnionExplicit.ts) | ✔ | ✔ | ❌ | ✔ | ✔ | ❌
|
|
186
|
-
> [Array (R+U, implicit)](https://github.com/samchon/typia/blob/master/test/structures/ArrayRecursiveUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
187
|
-
> [**Ultimate Union Type**](https://github.com/samchon/typia/blob/master/src/schemas/IJsonSchema.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌
|
|
188
|
-
>
|
|
189
|
-
> - typia: `typia`
|
|
190
|
-
> - C.V.: `class-validator` -->
|
|
148
|
+
When you want to add special validation logics, like limiting range of numeric values, you can do it through comment tags. If you want to know about it, visit the Guide Documents ([Features > Runtime Validators > Comment Tags](https://github.com/samchon/typia/wiki/Runtime-Validators#comment-tags)).
|
|
191
149
|
|
|
192
150
|
### Enhanced JSON
|
|
193
151
|
```typescript
|
|
@@ -179,15 +179,17 @@ var TypiaSetupWizard;
|
|
|
179
179
|
p !== null &&
|
|
180
180
|
p.transform === "typia/lib/transform";
|
|
181
181
|
});
|
|
182
|
-
if (strict === true && oldbie !== undefined)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
if (!(strict === true && oldbie !== undefined)) return [3, 3];
|
|
183
|
+
console.log("you've been already configured the tsconfig.json file.");
|
|
184
|
+
return [3, 5];
|
|
185
|
+
case 3:
|
|
186
186
|
options.strict = true;
|
|
187
187
|
plugins.push({ transform: "typia/lib/transform" });
|
|
188
188
|
return [4, fs_1.default.promises.writeFile("tsconfig.json", Comment.stringify(config, null, 2))];
|
|
189
|
-
case
|
|
189
|
+
case 4:
|
|
190
190
|
_c.sent();
|
|
191
|
+
_c.label = 5;
|
|
192
|
+
case 5:
|
|
191
193
|
if (temporary === true)
|
|
192
194
|
child_process_1.default.execSync("npm uninstall --save-dev comment-json");
|
|
193
195
|
return [2];
|
|
@@ -206,8 +208,8 @@ function install(pack, modulo, mode) {
|
|
|
206
208
|
}
|
|
207
209
|
var halt = function (closer) {
|
|
208
210
|
return function (desc) {
|
|
209
|
-
console.error(desc);
|
|
210
211
|
closer();
|
|
212
|
+
console.error(desc);
|
|
211
213
|
process.exit(-1);
|
|
212
214
|
};
|
|
213
215
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypiaSetupWizard.js","sourceRoot":"","sources":["../../../src/executable/internal/TypiaSetupWizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA+B;AAE/B,0CAAoB;AAEpB,IAAiB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"TypiaSetupWizard.js","sourceRoot":"","sources":["../../../src/executable/internal/TypiaSetupWizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA+B;AAE/B,0CAAoB;AAEpB,IAAiB,gBAAgB,CAqHhC;AArHD,WAAiB,gBAAgB;IAC7B,SAAsB,WAAW;;;;;4BA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BAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAqHhC;AAED,SAAS,OAAO,CACZ,IAAS,EACT,MAAc,EACd,IAA6B;IAE7B,IAAM,MAAM,GACR,CAAC,IAAI,KAAK,QAAQ;QACd,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;QACpD,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC/D,YAAE,CAAC,UAAU,CAAC,eAAe,GAAG,MAAM,CAAC,CAAC;IAC5C,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,CAAC,sBAAe,IAAI,cAAI,MAAM,CAAE,CAAC,CAAC;AACnE,CAAC;AAED,IAAM,IAAI,GACN,UAAC,MAAiB;IAClB,OAAA,UAAC,IAAY;QACT,MAAM,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;AAJD,CAIC,CAAC;AAEN,SAAS,OAAO,CAAC,OAAe;IAC5B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,uBAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,149 +1,148 @@
|
|
|
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(): Promise<void> {
|
|
7
|
-
// INSTALL
|
|
8
|
-
const pack: any = await prepare();
|
|
9
|
-
install(pack, "ttypescript", "--save-dev");
|
|
10
|
-
install(pack, "ts-node", "--save-dev");
|
|
11
|
-
|
|
12
|
-
// TSCONFIG.JSON
|
|
13
|
-
await configure();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function tsPatch(): Promise<void> {
|
|
17
|
-
// INSTALL
|
|
18
|
-
const pack: any = await prepare();
|
|
19
|
-
install(pack, "ts-patch", "--save-dev");
|
|
20
|
-
execute("npx ts-patch install");
|
|
21
|
-
|
|
22
|
-
// PACKAGE.JSON
|
|
23
|
-
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
24
|
-
pack.scripts = {};
|
|
25
|
-
if (typeof pack.scripts.prepare === "string") {
|
|
26
|
-
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
27
|
-
pack.scripts.prepare =
|
|
28
|
-
"ts-patch install && " + pack.scripts.prepare;
|
|
29
|
-
} else pack.scripts.prepare = "ts-patch install";
|
|
30
|
-
|
|
31
|
-
await fs.promises.writeFile(
|
|
32
|
-
"package.json",
|
|
33
|
-
JSON.stringify(pack, null, 2),
|
|
34
|
-
"utf8",
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// TSCONFIG.JSON
|
|
38
|
-
await configure();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function prepare(): Promise<any> {
|
|
42
|
-
if (fs.existsSync("package.json") === false)
|
|
43
|
-
halt(() => {})("make package.json file or move to it.");
|
|
44
|
-
const pack: any = JSON.parse(
|
|
45
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
46
|
-
);
|
|
47
|
-
install(pack, "typia", "--save");
|
|
48
|
-
install(pack, "typescript", "--save-dev");
|
|
49
|
-
return pack;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function configure(): Promise<void> {
|
|
53
|
-
// VALIDATE PRERATATION
|
|
54
|
-
if (fs.existsSync("tsconfig.json") === false) {
|
|
55
|
-
execute("npx tsc --init");
|
|
56
|
-
if (fs.existsSync("tsconfig.json") === false)
|
|
57
|
-
halt(() => {})("tsconfig.json file does not exist.");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const temporary: boolean = !fs.existsSync("node_modules/comment-json");
|
|
61
|
-
if (temporary === true)
|
|
62
|
-
cp.execSync("npm install --save-dev comment-json");
|
|
63
|
-
|
|
64
|
-
const halter: (msg: string) => never = halt(() => {
|
|
65
|
-
if (temporary === true)
|
|
66
|
-
cp.execSync("npm uninstall --save-dev comment-json");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// READ TSCONFIG FILE
|
|
70
|
-
const Comment: typeof import("comment-json") = await import(
|
|
71
|
-
process.cwd() + "/node_modules/comment-json"
|
|
72
|
-
);
|
|
73
|
-
const config: Comment.CommentObject = Comment.parse(
|
|
74
|
-
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
75
|
-
) as Comment.CommentObject;
|
|
76
|
-
const options = config.compilerOptions as
|
|
77
|
-
| Comment.CommentObject
|
|
78
|
-
| undefined;
|
|
79
|
-
if (options === undefined)
|
|
80
|
-
halter(
|
|
81
|
-
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const plugins: Comment.CommentArray<Comment.CommentObject> = (() => {
|
|
85
|
-
const plugins = options.plugins as
|
|
86
|
-
| Comment.CommentArray<Comment.CommentObject>
|
|
87
|
-
| undefined;
|
|
88
|
-
if (plugins === undefined) return (options.plugins = [] as any);
|
|
89
|
-
else if (!Array.isArray(plugins))
|
|
90
|
-
halter(
|
|
91
|
-
`"plugins" property of tsconfig.json must be array type.`,
|
|
92
|
-
);
|
|
93
|
-
return plugins;
|
|
94
|
-
})();
|
|
95
|
-
|
|
96
|
-
// CHECK WHETHER CONFIGURED
|
|
97
|
-
const strict: boolean = options.strict === true;
|
|
98
|
-
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
99
|
-
(p) =>
|
|
100
|
-
typeof p === "object" &&
|
|
101
|
-
p !== null &&
|
|
102
|
-
p.transform === "typia/lib/transform",
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
if (strict === true && oldbie !== undefined) {
|
|
106
|
-
console.log(
|
|
107
|
-
"you've been already configured the tsconfig.json file.",
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
(
|
|
140
|
-
|
|
141
|
-
console.error(desc);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
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(): Promise<void> {
|
|
7
|
+
// INSTALL
|
|
8
|
+
const pack: any = await prepare();
|
|
9
|
+
install(pack, "ttypescript", "--save-dev");
|
|
10
|
+
install(pack, "ts-node", "--save-dev");
|
|
11
|
+
|
|
12
|
+
// TSCONFIG.JSON
|
|
13
|
+
await configure();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function tsPatch(): Promise<void> {
|
|
17
|
+
// INSTALL
|
|
18
|
+
const pack: any = await prepare();
|
|
19
|
+
install(pack, "ts-patch", "--save-dev");
|
|
20
|
+
execute("npx ts-patch install");
|
|
21
|
+
|
|
22
|
+
// PACKAGE.JSON
|
|
23
|
+
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
24
|
+
pack.scripts = {};
|
|
25
|
+
if (typeof pack.scripts.prepare === "string") {
|
|
26
|
+
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
27
|
+
pack.scripts.prepare =
|
|
28
|
+
"ts-patch install && " + pack.scripts.prepare;
|
|
29
|
+
} else pack.scripts.prepare = "ts-patch install";
|
|
30
|
+
|
|
31
|
+
await fs.promises.writeFile(
|
|
32
|
+
"package.json",
|
|
33
|
+
JSON.stringify(pack, null, 2),
|
|
34
|
+
"utf8",
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// TSCONFIG.JSON
|
|
38
|
+
await configure();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function prepare(): Promise<any> {
|
|
42
|
+
if (fs.existsSync("package.json") === false)
|
|
43
|
+
halt(() => {})("make package.json file or move to it.");
|
|
44
|
+
const pack: any = JSON.parse(
|
|
45
|
+
await fs.promises.readFile("package.json", "utf8"),
|
|
46
|
+
);
|
|
47
|
+
install(pack, "typia", "--save");
|
|
48
|
+
install(pack, "typescript", "--save-dev");
|
|
49
|
+
return pack;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function configure(): Promise<void> {
|
|
53
|
+
// VALIDATE PRERATATION
|
|
54
|
+
if (fs.existsSync("tsconfig.json") === false) {
|
|
55
|
+
execute("npx tsc --init");
|
|
56
|
+
if (fs.existsSync("tsconfig.json") === false)
|
|
57
|
+
halt(() => {})("tsconfig.json file does not exist.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const temporary: boolean = !fs.existsSync("node_modules/comment-json");
|
|
61
|
+
if (temporary === true)
|
|
62
|
+
cp.execSync("npm install --save-dev comment-json");
|
|
63
|
+
|
|
64
|
+
const halter: (msg: string) => never = halt(() => {
|
|
65
|
+
if (temporary === true)
|
|
66
|
+
cp.execSync("npm uninstall --save-dev comment-json");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// READ TSCONFIG FILE
|
|
70
|
+
const Comment: typeof import("comment-json") = await import(
|
|
71
|
+
process.cwd() + "/node_modules/comment-json"
|
|
72
|
+
);
|
|
73
|
+
const config: Comment.CommentObject = Comment.parse(
|
|
74
|
+
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
75
|
+
) as Comment.CommentObject;
|
|
76
|
+
const options = config.compilerOptions as
|
|
77
|
+
| Comment.CommentObject
|
|
78
|
+
| undefined;
|
|
79
|
+
if (options === undefined)
|
|
80
|
+
halter(
|
|
81
|
+
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const plugins: Comment.CommentArray<Comment.CommentObject> = (() => {
|
|
85
|
+
const plugins = options.plugins as
|
|
86
|
+
| Comment.CommentArray<Comment.CommentObject>
|
|
87
|
+
| undefined;
|
|
88
|
+
if (plugins === undefined) return (options.plugins = [] as any);
|
|
89
|
+
else if (!Array.isArray(plugins))
|
|
90
|
+
halter(
|
|
91
|
+
`"plugins" property of tsconfig.json must be array type.`,
|
|
92
|
+
);
|
|
93
|
+
return plugins;
|
|
94
|
+
})();
|
|
95
|
+
|
|
96
|
+
// CHECK WHETHER CONFIGURED
|
|
97
|
+
const strict: boolean = options.strict === true;
|
|
98
|
+
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
99
|
+
(p) =>
|
|
100
|
+
typeof p === "object" &&
|
|
101
|
+
p !== null &&
|
|
102
|
+
p.transform === "typia/lib/transform",
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (strict === true && oldbie !== undefined) {
|
|
106
|
+
console.log(
|
|
107
|
+
"you've been already configured the tsconfig.json file.",
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
// DO CONFIGURE
|
|
111
|
+
options.strict = true;
|
|
112
|
+
plugins.push({ transform: "typia/lib/transform" } as any);
|
|
113
|
+
|
|
114
|
+
await fs.promises.writeFile(
|
|
115
|
+
"tsconfig.json",
|
|
116
|
+
Comment.stringify(config, null, 2),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (temporary === true)
|
|
120
|
+
cp.execSync("npm uninstall --save-dev comment-json");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function install(
|
|
125
|
+
pack: any,
|
|
126
|
+
modulo: string,
|
|
127
|
+
mode: "--save" | "--save-dev",
|
|
128
|
+
): void {
|
|
129
|
+
const exists: boolean =
|
|
130
|
+
(mode === "--save"
|
|
131
|
+
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
132
|
+
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
133
|
+
fs.existsSync("node_modules/" + modulo);
|
|
134
|
+
if (exists === false) execute(`npm install ${mode} ${modulo}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const halt =
|
|
138
|
+
(closer: () => any) =>
|
|
139
|
+
(desc: string): never => {
|
|
140
|
+
closer();
|
|
141
|
+
console.error(desc);
|
|
142
|
+
process.exit(-1);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
function execute(command: string): void {
|
|
146
|
+
console.log(command);
|
|
147
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
148
|
+
}
|
package/src/executable/typia.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
3
|
-
|
|
4
|
-
const USAGE = `Usage: npx typia setup (transformer?: "ttypescript" | "ts-patch")
|
|
5
|
-
|
|
6
|
-
- npx typia setup
|
|
7
|
-
- npx typia setup ttypescript
|
|
8
|
-
- npx typia setup ts-patch`;
|
|
9
|
-
|
|
10
|
-
function halt(desc: string): never {
|
|
11
|
-
console.error(desc);
|
|
12
|
-
process.exit(-1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function setup(): Promise<void> {
|
|
16
|
-
const compiler: string = process.argv[3] ?? "ttypescript";
|
|
17
|
-
if (compiler !== "ttypescript" && compiler !== "ts-patch")
|
|
18
|
-
halt(
|
|
19
|
-
"typia supports only two transformers: ttypescript and ts-patch" +
|
|
20
|
-
"\n\n" +
|
|
21
|
-
USAGE,
|
|
22
|
-
);
|
|
23
|
-
else if (compiler === "ttypescript") await TypiaSetupWizard.ttypescript();
|
|
24
|
-
else await TypiaSetupWizard.tsPatch();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function main(): Promise<void> {
|
|
28
|
-
const type: string | undefined = process.argv[2];
|
|
29
|
-
if (type === undefined) halt(USAGE);
|
|
30
|
-
else if (type === "setup") await setup();
|
|
31
|
-
}
|
|
32
|
-
main().catch((exp) => {
|
|
33
|
-
console.error(exp);
|
|
34
|
-
process.exit(-1);
|
|
35
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
3
|
+
|
|
4
|
+
const USAGE = `Usage: npx typia setup (transformer?: "ttypescript" | "ts-patch")
|
|
5
|
+
|
|
6
|
+
- npx typia setup
|
|
7
|
+
- npx typia setup ttypescript
|
|
8
|
+
- npx typia setup ts-patch`;
|
|
9
|
+
|
|
10
|
+
function halt(desc: string): never {
|
|
11
|
+
console.error(desc);
|
|
12
|
+
process.exit(-1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function setup(): Promise<void> {
|
|
16
|
+
const compiler: string = process.argv[3] ?? "ttypescript";
|
|
17
|
+
if (compiler !== "ttypescript" && compiler !== "ts-patch")
|
|
18
|
+
halt(
|
|
19
|
+
"typia supports only two transformers: ttypescript and ts-patch" +
|
|
20
|
+
"\n\n" +
|
|
21
|
+
USAGE,
|
|
22
|
+
);
|
|
23
|
+
else if (compiler === "ttypescript") await TypiaSetupWizard.ttypescript();
|
|
24
|
+
else await TypiaSetupWizard.tsPatch();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function main(): Promise<void> {
|
|
28
|
+
const type: string | undefined = process.argv[2];
|
|
29
|
+
if (type === undefined) halt(USAGE);
|
|
30
|
+
else if (type === "setup") await setup();
|
|
31
|
+
}
|
|
32
|
+
main().catch((exp) => {
|
|
33
|
+
console.error(exp);
|
|
34
|
+
process.exit(-1);
|
|
35
|
+
});
|