typia 3.5.0 → 3.5.1-dev.20220217

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.
Files changed (33) hide show
  1. package/README.md +13 -21
  2. package/lib/executable/internal/ArgumentParser.d.ts +9 -0
  3. package/lib/executable/internal/ArgumentParser.js +265 -0
  4. package/lib/executable/internal/ArgumentParser.js.map +1 -0
  5. package/lib/executable/internal/CommandExecutor.d.ts +3 -0
  6. package/lib/executable/internal/CommandExecutor.js +17 -0
  7. package/lib/executable/internal/CommandExecutor.js.map +1 -0
  8. package/lib/executable/internal/PackageManager.d.ts +27 -0
  9. package/lib/executable/internal/PackageManager.js +140 -0
  10. package/lib/executable/internal/PackageManager.js.map +1 -0
  11. package/lib/executable/internal/PluginConfigurator.d.ts +5 -0
  12. package/lib/executable/internal/PluginConfigurator.js +158 -0
  13. package/lib/executable/internal/PluginConfigurator.js.map +1 -0
  14. package/lib/executable/typia.js +43 -22
  15. package/lib/executable/typia.js.map +1 -1
  16. package/lib/transform.d.ts +2 -1
  17. package/lib/transform.js +2 -0
  18. package/lib/transform.js.map +1 -1
  19. package/package.json +10 -5
  20. package/src/executable/internal/ArgumentParser.ts +143 -0
  21. package/src/executable/internal/CommandExecutor.ts +8 -0
  22. package/src/executable/internal/PackageManager.ts +99 -0
  23. package/src/executable/internal/PluginConfigurator.ts +96 -0
  24. package/src/executable/typia.ts +40 -17
  25. package/src/transform.ts +2 -1
  26. package/lib/executable/internal/CommandParser.d.ts +0 -3
  27. package/lib/executable/internal/CommandParser.js +0 -21
  28. package/lib/executable/internal/CommandParser.js.map +0 -1
  29. package/lib/executable/internal/TypiaSetupWizard.d.ts +0 -8
  30. package/lib/executable/internal/TypiaSetupWizard.js +0 -244
  31. package/lib/executable/internal/TypiaSetupWizard.js.map +0 -1
  32. package/src/executable/internal/CommandParser.ts +0 -15
  33. package/src/executable/internal/TypiaSetupWizard.ts +0 -182
@@ -1,182 +0,0 @@
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 interface IArguments {
7
- manager: "npm" | "pnpm" | "yarn";
8
- project: string;
9
- }
10
-
11
- export async function ttypescript(args: IArguments): Promise<void> {
12
- // INSTALL
13
- const pack: any = await prepare(args.manager);
14
- add(args.manager)(pack)("ttypescript", true);
15
- add(args.manager)(pack)("ts-node", true);
16
-
17
- // TSCONFIG.JSON
18
- await configure(args)(pack);
19
- }
20
-
21
- export async function tsPatch(args: IArguments): Promise<void> {
22
- // INSTALL
23
- add(args.manager)(await prepare(args.manager))("ts-patch", true);
24
- execute("npx ts-patch install");
25
-
26
- // PACKAGE.JSON
27
- const pack: any = JSON.parse(
28
- await fs.promises.readFile("package.json", "utf8"),
29
- );
30
- if (!pack.scripts || typeof pack.scripts !== "object")
31
- pack.scripts = {};
32
- if (typeof pack.scripts.prepare === "string") {
33
- if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
34
- pack.scripts.prepare =
35
- "ts-patch install && " + pack.scripts.prepare;
36
- } else pack.scripts.prepare = "ts-patch install";
37
-
38
- await fs.promises.writeFile(
39
- "package.json",
40
- JSON.stringify(pack, null, 2),
41
- "utf8",
42
- );
43
-
44
- // TSCONFIG.JSON
45
- await configure(args)(pack);
46
- }
47
-
48
- async function prepare(manager: string): Promise<any> {
49
- if (fs.existsSync("package.json") === false)
50
- halt(() => {})("make package.json file or move to it.");
51
-
52
- const pack: any = JSON.parse(
53
- await fs.promises.readFile("package.json", "utf8"),
54
- );
55
- const wizard = add(manager)(pack);
56
- wizard("typia", false);
57
- wizard("typescript", true);
58
- return pack;
59
- }
60
-
61
- const configure =
62
- (args: IArguments) =>
63
- async (pack: any): Promise<void> => {
64
- // VALIDATE PRERATATION
65
- if (fs.existsSync(args.project) === false) {
66
- if (args.project === "tsconfig.json") execute("npx tsc --init");
67
- if (fs.existsSync(args.project) === false)
68
- halt(() => {})(`${args.project} file does not exist.`);
69
- }
70
-
71
- // INSTALL COMMENT-JSON FOR A WHILE
72
- const temporary: boolean = !fs.existsSync(
73
- "node_modules/comment-json",
74
- );
75
- if (temporary === true)
76
- add(args.manager)(pack)("comment-json", true);
77
-
78
- const halter: (msg: string) => never = halt(() => {
79
- if (temporary === true)
80
- remove(args.manager)("comment-json", true);
81
- });
82
-
83
- // READ TSCONFIG FILE
84
- const Comment: typeof import("comment-json") = await import(
85
- process.cwd() + "/node_modules/comment-json"
86
- );
87
- const config: Comment.CommentObject = Comment.parse(
88
- await fs.promises.readFile(args.project, "utf8"),
89
- ) as Comment.CommentObject;
90
- const options = config.compilerOptions as
91
- | Comment.CommentObject
92
- | undefined;
93
- if (options === undefined)
94
- halter(
95
- `${args.project} file does not have "compilerOptions" property.`,
96
- );
97
-
98
- // PREPARE PLUGINS
99
- const plugins: Comment.CommentArray<Comment.CommentObject> =
100
- (() => {
101
- const plugins = options.plugins as
102
- | Comment.CommentArray<Comment.CommentObject>
103
- | undefined;
104
- if (plugins === undefined)
105
- return (options.plugins = [] as any);
106
- else if (!Array.isArray(plugins))
107
- halter(
108
- `"plugins" property of ${args.project} must be array type.`,
109
- );
110
- return plugins;
111
- })();
112
-
113
- // CHECK WHETHER CONFIGURED
114
- const strict: boolean = options.strict === true;
115
- const oldbie: Comment.CommentObject | undefined = plugins.find(
116
- (p) =>
117
- typeof p === "object" &&
118
- p !== null &&
119
- p.transform === "typia/lib/transform",
120
- );
121
-
122
- if (strict === true && oldbie !== undefined) {
123
- console.log(
124
- `you've been already configured the ${args.project} file.`,
125
- );
126
- } else {
127
- // DO CONFIGURE
128
- options.strict = true;
129
- if (oldbie === undefined)
130
- plugins.push(
131
- Comment.parse(`
132
- {
133
- "transform": "typia/lib/transform"
134
- }`) as Comment.CommentObject,
135
- );
136
- await fs.promises.writeFile(
137
- args.project,
138
- Comment.stringify(config, null, 2),
139
- );
140
- }
141
- if (temporary === true) remove(args.manager)("comment-json", false);
142
- };
143
- }
144
-
145
- const add =
146
- (manager: string) =>
147
- (pack: any) =>
148
- (modulo: string, devOnly: boolean): void => {
149
- const exists: boolean =
150
- (devOnly === false
151
- ? !!pack.dependencies && !!pack.dependencies[modulo]
152
- : !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
153
- fs.existsSync("node_modules/" + modulo);
154
- const middle: string =
155
- manager === "yarn"
156
- ? `add${devOnly ? " -D" : ""}`
157
- : `install ${devOnly ? "--save-dev" : "--save"}`;
158
- if (exists === false) execute(`${manager} ${middle} ${modulo}`);
159
- };
160
-
161
- const remove =
162
- (manager: string) =>
163
- (modulo: string, devOnly: boolean): void => {
164
- const middle: string =
165
- manager === "yarn"
166
- ? `remove${devOnly ? " -D" : ""}`
167
- : `uninstall ${devOnly ? "--save-dev" : "--save"}`;
168
- execute(`${manager} ${middle} ${modulo}`);
169
- };
170
-
171
- const halt =
172
- (closer: () => any) =>
173
- (desc: string): never => {
174
- closer();
175
- console.error(desc);
176
- process.exit(-1);
177
- };
178
-
179
- function execute(command: string): void {
180
- console.log(command);
181
- cp.execSync(command, { stdio: "inherit" });
182
- }