typia 3.4.7 → 3.4.8

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 CHANGED
@@ -12,7 +12,7 @@ export function assert<T>(input: unknown | T): T; // throws TypeGuardError
12
12
  export function validate<T>(input: unknown | T): IValidation<T>; // detailed
13
13
 
14
14
  // STRICT VALIDATORS
15
- export function equals<T>(input: unknown: T): input is T;
15
+ export function equals<T>(input: unknown | T): input is T;
16
16
  export function assertEquals<T>(input: unknown | T): T;
17
17
  export function validateEquals<T>(input: unknown | T): IValidation<T>;
18
18
 
@@ -49,7 +49,15 @@ npx typia setup
49
49
 
50
50
  Just type `npx typia setup`, that's all.
51
51
 
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:
52
+ Also, you can specify package manager by `--manager` argument.
53
+
54
+ ```bash
55
+ npx typia setup --manager npm
56
+ npx typia setup --manager pnpm
57
+ npx typia setup --manager yarn
58
+ ```
59
+
60
+ After the setup, you can compile `typia` utilization 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
61
 
54
62
  ```bash
55
63
  # COMPILE THROUGH TTYPESCRIPT
@@ -68,6 +76,8 @@ If you want to install and setup `typia` manually, read [Guide Documents - Setup
68
76
  - [vite](https://github.com/samchon/typia/wiki/Setup#vite)
69
77
  - [webpack](https://github.com/samchon/typia/wiki/Setup#webpack)
70
78
 
79
+ Also, the [Guide Documents - Setup](https://github.com/samchon/typia/wiki/Setup), you can learn how to use pure TypeScript compiler `tsc` instead of installing the `ttypescript` compiler with `ttsc` command.
80
+
71
81
  ### vite
72
82
  When you want to setup `typia` on your frontend project with [`vite`](https://vitejs.dev/), just configure `vite.config.ts` like below.
73
83
 
@@ -0,0 +1,3 @@
1
+ export declare namespace CommandParser {
2
+ function parse(argList: string[]): Record<string, string>;
3
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandParser = void 0;
4
+ var CommandParser;
5
+ (function (CommandParser) {
6
+ function parse(argList) {
7
+ var output = {};
8
+ argList.forEach(function (arg, i) {
9
+ if (arg.startsWith("--") === false)
10
+ return;
11
+ var key = arg.slice(2);
12
+ var value = argList[i + 1];
13
+ if (value === undefined || value.startsWith("--"))
14
+ return;
15
+ output[key] = value;
16
+ });
17
+ return output;
18
+ }
19
+ CommandParser.parse = parse;
20
+ })(CommandParser = exports.CommandParser || (exports.CommandParser = {}));
21
+ //# sourceMappingURL=CommandParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandParser.js","sourceRoot":"","sources":["../../../src/executable/internal/CommandParser.ts"],"names":[],"mappings":";;;AAAA,IAAiB,aAAa,CAc7B;AAdD,WAAiB,aAAa;IAC1B,SAAgB,KAAK,CAAC,OAAiB;QACnC,IAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,OAAO,CAAC,OAAO,CAAC,UAAC,GAAG,EAAE,CAAC;YACnB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,KAAK;gBAAE,OAAO;YAE3C,IAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzB,IAAM,KAAK,GAAuB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;gBAAE,OAAO;YAE1D,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAZe,mBAAK,QAYpB,CAAA;AACL,CAAC,EAdgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAc7B"}
@@ -1,4 +1,4 @@
1
1
  export declare namespace TypiaSetupWizard {
2
- function ttypescript(): Promise<void>;
3
- function tsPatch(): Promise<void>;
2
+ function ttypescript(manager: string): Promise<void>;
3
+ function tsPatch(manager: string): Promise<void>;
4
4
  }
@@ -67,17 +67,18 @@ var child_process_1 = __importDefault(require("child_process"));
67
67
  var fs_1 = __importDefault(require("fs"));
68
68
  var TypiaSetupWizard;
69
69
  (function (TypiaSetupWizard) {
70
- function ttypescript() {
70
+ var _this = this;
71
+ function ttypescript(manager) {
71
72
  return __awaiter(this, void 0, void 0, function () {
72
73
  var pack;
73
74
  return __generator(this, function (_a) {
74
75
  switch (_a.label) {
75
- case 0: return [4, prepare()];
76
+ case 0: return [4, prepare(manager)];
76
77
  case 1:
77
78
  pack = _a.sent();
78
- install(pack, "ttypescript", "--save-dev");
79
- install(pack, "ts-node", "--save-dev");
80
- return [4, configure()];
79
+ add(manager)(pack)("ttypescript", true);
80
+ add(manager)(pack)("ts-node", true);
81
+ return [4, configure(manager)];
81
82
  case 2:
82
83
  _a.sent();
83
84
  return [2];
@@ -86,16 +87,21 @@ var TypiaSetupWizard;
86
87
  });
87
88
  }
88
89
  TypiaSetupWizard.ttypescript = ttypescript;
89
- function tsPatch() {
90
+ function tsPatch(manager) {
90
91
  return __awaiter(this, void 0, void 0, function () {
91
- var pack;
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
94
- case 0: return [4, prepare()];
92
+ var _a, pack, _b, _c;
93
+ return __generator(this, function (_d) {
94
+ switch (_d.label) {
95
+ case 0:
96
+ _a = add(manager);
97
+ return [4, prepare(manager)];
95
98
  case 1:
96
- pack = _a.sent();
97
- install(pack, "ts-patch", "--save-dev");
99
+ _a.apply(void 0, [_d.sent()])("ts-patch", true);
98
100
  execute("npx ts-patch install");
101
+ _c = (_b = JSON).parse;
102
+ return [4, fs_1.default.promises.readFile("package.json", "utf8")];
103
+ case 2:
104
+ pack = _c.apply(_b, [_d.sent()]);
99
105
  if (!pack.scripts || typeof pack.scripts !== "object")
100
106
  pack.scripts = {};
101
107
  if (typeof pack.scripts.prepare === "string") {
@@ -106,20 +112,20 @@ var TypiaSetupWizard;
106
112
  else
107
113
  pack.scripts.prepare = "ts-patch install";
108
114
  return [4, fs_1.default.promises.writeFile("package.json", JSON.stringify(pack, null, 2), "utf8")];
109
- case 2:
110
- _a.sent();
111
- return [4, configure()];
112
115
  case 3:
113
- _a.sent();
116
+ _d.sent();
117
+ return [4, configure(manager)];
118
+ case 4:
119
+ _d.sent();
114
120
  return [2];
115
121
  }
116
122
  });
117
123
  });
118
124
  }
119
125
  TypiaSetupWizard.tsPatch = tsPatch;
120
- function prepare() {
126
+ function prepare(manager) {
121
127
  return __awaiter(this, void 0, void 0, function () {
122
- var pack, _a, _b;
128
+ var pack, _a, _b, wizard;
123
129
  return __generator(this, function (_c) {
124
130
  switch (_c.label) {
125
131
  case 0:
@@ -129,15 +135,16 @@ var TypiaSetupWizard;
129
135
  return [4, fs_1.default.promises.readFile("package.json", "utf8")];
130
136
  case 1:
131
137
  pack = _b.apply(_a, [_c.sent()]);
132
- install(pack, "typia", "--save");
133
- install(pack, "typescript", "--save-dev");
138
+ wizard = add(manager)(pack);
139
+ wizard("typia", false);
140
+ wizard("typescript", true);
134
141
  return [2, pack];
135
142
  }
136
143
  });
137
144
  });
138
145
  }
139
- function configure() {
140
- return __awaiter(this, void 0, void 0, function () {
146
+ var configure = function (manager) {
147
+ return function (pack) { return __awaiter(_this, void 0, void 0, function () {
141
148
  var temporary, halter, Comment, config, _a, _b, options, plugins, strict, oldbie;
142
149
  return __generator(this, function (_c) {
143
150
  var _d;
@@ -150,10 +157,10 @@ var TypiaSetupWizard;
150
157
  }
151
158
  temporary = !fs_1.default.existsSync("node_modules/comment-json");
152
159
  if (temporary === true)
153
- child_process_1.default.execSync("npm install --save-dev comment-json");
160
+ add(manager)(pack)("comment-json", true);
154
161
  halter = halt(function () {
155
162
  if (temporary === true)
156
- child_process_1.default.execSync("npm uninstall --save-dev comment-json");
163
+ remove(manager)("comment-json", true);
157
164
  });
158
165
  return [4, (_d = process.cwd() + "/node_modules/comment-json", Promise.resolve().then(function () { return __importStar(require(_d)); }))];
159
166
  case 1:
@@ -191,21 +198,36 @@ var TypiaSetupWizard;
191
198
  _c.label = 5;
192
199
  case 5:
193
200
  if (temporary === true)
194
- child_process_1.default.execSync("npm uninstall --save-dev comment-json");
201
+ remove(manager)("comment-json", false);
195
202
  return [2];
196
203
  }
197
204
  });
198
- });
199
- }
205
+ }); };
206
+ };
200
207
  })(TypiaSetupWizard = exports.TypiaSetupWizard || (exports.TypiaSetupWizard = {}));
201
- function install(pack, modulo, mode) {
202
- var exists = (mode === "--save"
203
- ? !!pack.dependencies && !!pack.dependencies[modulo]
204
- : !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
205
- fs_1.default.existsSync("node_modules/" + modulo);
206
- if (exists === false)
207
- execute("npm install ".concat(mode, " ").concat(modulo));
208
- }
208
+ var add = function (manager) {
209
+ return function (pack) {
210
+ return function (modulo, devOnly) {
211
+ var exists = (devOnly === false
212
+ ? !!pack.dependencies && !!pack.dependencies[modulo]
213
+ : !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
214
+ fs_1.default.existsSync("node_modules/" + modulo);
215
+ var middle = manager === "yarn"
216
+ ? "add".concat(devOnly ? " -D" : "")
217
+ : "install ".concat(devOnly ? "--save-dev" : "--save");
218
+ if (exists === false)
219
+ execute("".concat(manager, " ").concat(middle, " ").concat(modulo));
220
+ };
221
+ };
222
+ };
223
+ var remove = function (manager) {
224
+ return function (modulo, devOnly) {
225
+ var middle = manager === "yarn"
226
+ ? "remove".concat(devOnly ? " -D" : "")
227
+ : "uninstall ".concat(devOnly ? "--save-dev" : "--save");
228
+ execute("".concat(manager, " ").concat(middle, " ").concat(modulo));
229
+ };
230
+ };
209
231
  var halt = function (closer) {
210
232
  return function (desc) {
211
233
  closer();
@@ -1 +1 @@
1
- {"version":3,"file":"TypiaSetupWizard.js","sourceRoot":"","sources":["../../../src/executable/internal/TypiaSetupW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C,CAAC,EAAE,CAAE;gBAC9B,CAAC,CAAC,kBAAW,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAE,CAAC;YACzD,IAAI,MAAM,KAAK,KAAK;gBAAE,OAAO,CAAC,UAAG,OAAO,cAAI,MAAM,cAAI,MAAM,CAAE,CAAC,CAAC;QACpE,CAAC;IAXD,CAWC;AAZD,CAYC,CAAC;AAEN,IAAM,MAAM,GACR,UAAC,OAAe;IAChB,OAAA,UAAC,MAAc,EAAE,OAAgB;QAC7B,IAAM,MAAM,GACR,OAAO,KAAK,MAAM;YACd,CAAC,CAAC,gBAAS,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAE;YACjC,CAAC,CAAC,oBAAa,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAE,CAAC;QAC3D,OAAO,CAAC,UAAG,OAAO,cAAI,MAAM,cAAI,MAAM,CAAE,CAAC,CAAC;IAC9C,CAAC;AAND,CAMC,CAAC;AAEN,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"}
@@ -37,35 +37,37 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  }
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
+ var CommandParser_1 = require("./internal/CommandParser");
40
41
  var TypiaSetupWizard_1 = require("./internal/TypiaSetupWizard");
41
- var USAGE = "Usage: npx typia setup (transformer?: \"ttypescript\" | \"ts-patch\")\n\n - npx typia setup\n - npx typia setup ttypescript\n - npx typia setup ts-patch";
42
+ var USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --compiler (ttypescript|ts-patch) \\\n --manager (npm|pnpm|yarn)\n\n - npx typia setup\n - npx typia setup --compiler ttypescript\n - npx typia setup --compiler ts-patch\n - npx typia setup --manager pnpm";
42
43
  function halt(desc) {
43
44
  console.error(desc);
44
45
  process.exit(-1);
45
46
  }
46
47
  function setup() {
47
- var _a;
48
+ var _a, _b;
48
49
  return __awaiter(this, void 0, void 0, function () {
49
- var compiler;
50
- return __generator(this, function (_b) {
51
- switch (_b.label) {
50
+ var options, manager, compiler;
51
+ return __generator(this, function (_c) {
52
+ switch (_c.label) {
52
53
  case 0:
53
- compiler = (_a = process.argv[3]) !== null && _a !== void 0 ? _a : "ttypescript";
54
- if (!(compiler !== "ttypescript" && compiler !== "ts-patch")) return [3, 1];
55
- halt("typia supports only two transformers: ttypescript and ts-patch" +
56
- "\n\n" +
57
- USAGE);
54
+ options = CommandParser_1.CommandParser.parse(process.argv.slice(3));
55
+ manager = (_a = options.manager) !== null && _a !== void 0 ? _a : "npm";
56
+ compiler = (_b = options.compiler) !== null && _b !== void 0 ? _b : "ttypescript";
57
+ if (!((compiler !== "ttypescript" && compiler !== "ts-patch") ||
58
+ (manager !== "npm" && manager !== "pnpm" && manager !== "yarn"))) return [3, 1];
59
+ halt(USAGE);
58
60
  return [3, 5];
59
61
  case 1:
60
62
  if (!(compiler === "ttypescript")) return [3, 3];
61
- return [4, TypiaSetupWizard_1.TypiaSetupWizard.ttypescript()];
63
+ return [4, TypiaSetupWizard_1.TypiaSetupWizard.ttypescript(manager)];
62
64
  case 2:
63
- _b.sent();
65
+ _c.sent();
64
66
  return [3, 5];
65
- case 3: return [4, TypiaSetupWizard_1.TypiaSetupWizard.tsPatch()];
67
+ case 3: return [4, TypiaSetupWizard_1.TypiaSetupWizard.tsPatch(manager)];
66
68
  case 4:
67
- _b.sent();
68
- _b.label = 5;
69
+ _c.sent();
70
+ _c.label = 5;
69
71
  case 5: return [2];
70
72
  }
71
73
  });
@@ -78,14 +80,13 @@ function main() {
78
80
  switch (_a.label) {
79
81
  case 0:
80
82
  type = process.argv[2];
81
- if (!(type === undefined)) return [3, 1];
82
- halt(USAGE);
83
- return [3, 3];
84
- case 1:
85
- if (!(type === "setup")) return [3, 3];
83
+ if (!(type === "setup")) return [3, 2];
86
84
  return [4, setup()];
87
- case 2:
85
+ case 1:
88
86
  _a.sent();
87
+ return [3, 3];
88
+ case 2:
89
+ halt(USAGE);
89
90
  _a.label = 3;
90
91
  case 3: return [2];
91
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"typia.js","sourceRoot":"","sources":["../../src/executable/typia.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAA+D;AAE/D,IAAM,KAAK,GAAG,6JAIe,CAAC;AAE9B,SAAS,IAAI,CAAC,IAAY;IACtB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC;AAED,SAAe,KAAK;;;;;;;oBACV,QAAQ,GAAW,MAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,mCAAI,aAAa,CAAC;yBACtD,CAAA,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,UAAU,CAAA,EAArD,cAAqD;oBACrD,IAAI,CACA,gEAAgE;wBAC5D,MAAM;wBACN,KAAK,CACZ,CAAC;;;yBACG,CAAA,QAAQ,KAAK,aAAa,CAAA,EAA1B,cAA0B;oBAAE,WAAM,mCAAgB,CAAC,WAAW,EAAE,EAAA;;oBAApC,SAAoC,CAAC;;wBACrE,WAAM,mCAAgB,CAAC,OAAO,EAAE,EAAA;;oBAAhC,SAAgC,CAAC;;;;;;CACzC;AAED,SAAe,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CAAC,KAAK,CAAC,CAAC;;;yBACP,CAAA,QAAQ,KAAK,aAAa,CAAA,EAA1B,cAA0B;oBAC/B,WAAM,mCAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,EAAA;;oBAA3C,SAA2C,CAAC;;wBAC3C,WAAM,mCAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAA;;oBAAvC,SAAuC,CAAC;;;;;;CAChD;AAED,SAAe,IAAI;;;;;;oBACT,IAAI,GAAuB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;yBAC7C,CAAA,IAAI,KAAK,OAAO,CAAA,EAAhB,cAAgB;oBAAE,WAAM,KAAK,EAAE,EAAA;;oBAAb,SAAa,CAAC;;;oBAC/B,IAAI,CAAC,KAAK,CAAC,CAAC;;;;;;CACpB;AACD,IAAI,EAAE,CAAC,KAAK,CAAC,UAAC,GAAG;IACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typia",
3
- "version": "3.4.7",
3
+ "version": "3.4.8",
4
4
  "description": "Runtime type checkers and 5x faster JSON.stringify() function",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "build": "rimraf lib && ttsc --removeComments --declaration false && ttsc --emitDeclarationOnly",
13
13
  "build:test": "rimraf bin && ttsc -p tsconfig.test.json",
14
14
  "build:test:prettier": "npm run build:test && prettier --write ./bin/**/*.js",
15
- "dev": "npm run build -- --watch",
15
+ "dev": "rimraf lib && ttsc --watch",
16
16
  "dev:test": "rimraf bin && ttsc -p tsconfig.test.json --watch",
17
17
  "eslint": "eslint ./**/*.ts",
18
18
  "eslint:fix": "eslint ./**/*.ts --fix",
@@ -0,0 +1,15 @@
1
+ export namespace CommandParser {
2
+ export function parse(argList: string[]): Record<string, string> {
3
+ const output: Record<string, string> = {};
4
+ argList.forEach((arg, i) => {
5
+ if (arg.startsWith("--") === false) return;
6
+
7
+ const key = arg.slice(2);
8
+ const value: string | undefined = argList[i + 1];
9
+ if (value === undefined || value.startsWith("--")) return;
10
+
11
+ output[key] = value;
12
+ });
13
+ return output;
14
+ }
15
+ }
@@ -3,23 +3,25 @@ import type Comment from "comment-json";
3
3
  import fs from "fs";
4
4
 
5
5
  export namespace TypiaSetupWizard {
6
- export async function ttypescript(): Promise<void> {
6
+ export async function ttypescript(manager: string): Promise<void> {
7
7
  // INSTALL
8
- const pack: any = await prepare();
9
- install(pack, "ttypescript", "--save-dev");
10
- install(pack, "ts-node", "--save-dev");
8
+ const pack: any = await prepare(manager);
9
+ add(manager)(pack)("ttypescript", true);
10
+ add(manager)(pack)("ts-node", true);
11
11
 
12
12
  // TSCONFIG.JSON
13
- await configure();
13
+ await configure(manager);
14
14
  }
15
15
 
16
- export async function tsPatch(): Promise<void> {
16
+ export async function tsPatch(manager: string): Promise<void> {
17
17
  // INSTALL
18
- const pack: any = await prepare();
19
- install(pack, "ts-patch", "--save-dev");
18
+ add(manager)(await prepare(manager))("ts-patch", true);
20
19
  execute("npx ts-patch install");
21
20
 
22
21
  // PACKAGE.JSON
22
+ const pack: any = JSON.parse(
23
+ await fs.promises.readFile("package.json", "utf8"),
24
+ );
23
25
  if (!pack.scripts || typeof pack.scripts !== "object")
24
26
  pack.scripts = {};
25
27
  if (typeof pack.scripts.prepare === "string") {
@@ -35,105 +37,124 @@ export namespace TypiaSetupWizard {
35
37
  );
36
38
 
37
39
  // TSCONFIG.JSON
38
- await configure();
40
+ await configure(manager);
39
41
  }
40
42
 
41
- async function prepare(): Promise<any> {
43
+ async function prepare(manager: string): Promise<any> {
42
44
  if (fs.existsSync("package.json") === false)
43
45
  halt(() => {})("make package.json file or move to it.");
46
+
44
47
  const pack: any = JSON.parse(
45
48
  await fs.promises.readFile("package.json", "utf8"),
46
49
  );
47
- install(pack, "typia", "--save");
48
- install(pack, "typescript", "--save-dev");
50
+ const wizard = add(manager)(pack);
51
+
52
+ wizard("typia", false);
53
+ wizard("typescript", true);
49
54
  return pack;
50
55
  }
51
56
 
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.`,
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",
82
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
+ });
83
75
 
84
- const plugins: Comment.CommentArray<Comment.CommentObject> = (() => {
85
- const plugins = options.plugins as
86
- | Comment.CommentArray<Comment.CommentObject>
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
87
85
  | undefined;
88
- if (plugins === undefined) return (options.plugins = [] as any);
89
- else if (!Array.isArray(plugins))
86
+ if (options === undefined)
90
87
  halter(
91
- `"plugins" property of tsconfig.json must be array type.`,
88
+ `tsconfig.json file does not have "compilerOptions" property.`,
92
89
  );
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
90
 
105
- if (strict === true && oldbie !== undefined) {
106
- console.log(
107
- "you've been already configured the tsconfig.json file.",
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",
108
112
  );
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
113
 
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}`);
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
+ plugins.push({ transform: "typia/lib/transform" } as any);
122
+
123
+ await fs.promises.writeFile(
124
+ "tsconfig.json",
125
+ Comment.stringify(config, null, 2),
126
+ );
127
+ }
128
+ if (temporary === true) remove(manager)("comment-json", false);
129
+ };
135
130
  }
136
131
 
132
+ const add =
133
+ (manager: string) =>
134
+ (pack: any) =>
135
+ (modulo: string, devOnly: boolean): void => {
136
+ const exists: boolean =
137
+ (devOnly === false
138
+ ? !!pack.dependencies && !!pack.dependencies[modulo]
139
+ : !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
140
+ fs.existsSync("node_modules/" + modulo);
141
+ const middle: string =
142
+ manager === "yarn"
143
+ ? `add${devOnly ? " -D" : ""}`
144
+ : `install ${devOnly ? "--save-dev" : "--save"}`;
145
+ if (exists === false) execute(`${manager} ${middle} ${modulo}`);
146
+ };
147
+
148
+ const remove =
149
+ (manager: string) =>
150
+ (modulo: string, devOnly: boolean): void => {
151
+ const middle: string =
152
+ manager === "yarn"
153
+ ? `remove${devOnly ? " -D" : ""}`
154
+ : `uninstall ${devOnly ? "--save-dev" : "--save"}`;
155
+ execute(`${manager} ${middle} ${modulo}`);
156
+ };
157
+
137
158
  const halt =
138
159
  (closer: () => any) =>
139
160
  (desc: string): never => {
@@ -1,11 +1,17 @@
1
1
  #!/usr/bin/env node
2
+ import { CommandParser } from "./internal/CommandParser";
2
3
  import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
3
4
 
4
- const USAGE = `Usage: npx typia setup (transformer?: "ttypescript" | "ts-patch")
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)
5
10
 
6
11
  - npx typia setup
7
- - npx typia setup ttypescript
8
- - npx typia setup ts-patch`;
12
+ - npx typia setup --compiler ttypescript
13
+ - npx typia setup --compiler ts-patch
14
+ - npx typia setup --manager pnpm`;
9
15
 
10
16
  function halt(desc: string): never {
11
17
  console.error(desc);
@@ -13,21 +19,26 @@ function halt(desc: string): never {
13
19
  }
14
20
 
15
21
  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();
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);
25
36
  }
26
37
 
27
38
  async function main(): Promise<void> {
28
39
  const type: string | undefined = process.argv[2];
29
- if (type === undefined) halt(USAGE);
30
- else if (type === "setup") await setup();
40
+ if (type === "setup") await setup();
41
+ else halt(USAGE);
31
42
  }
32
43
  main().catch((exp) => {
33
44
  console.error(exp);