@nestia/core 1.0.10 → 1.0.11
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 +15 -9
- package/lib/decorators/EncryptedBody.d.ts +1 -1
- package/lib/decorators/EncryptedBody.js +1 -1
- package/lib/decorators/EncryptedRoute.d.ts +4 -4
- package/lib/decorators/EncryptedRoute.js +4 -4
- package/lib/decorators/TypedRoute.d.ts +3 -2
- package/lib/decorators/TypedRoute.js +3 -2
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/executable/core.js +45 -23
- package/lib/executable/core.js.map +1 -1
- package/lib/executable/internal/ArgumentParser.d.ts +9 -0
- package/lib/executable/internal/ArgumentParser.js +269 -0
- package/lib/executable/internal/ArgumentParser.js.map +1 -0
- package/lib/executable/internal/CommandExecutor.d.ts +3 -0
- package/lib/executable/internal/CommandExecutor.js +17 -0
- package/lib/executable/internal/CommandExecutor.js.map +1 -0
- package/lib/executable/internal/PackageManager.d.ts +27 -0
- package/lib/executable/internal/PackageManager.js +140 -0
- package/lib/executable/internal/PackageManager.js.map +1 -0
- package/lib/executable/internal/PluginConfigurator.d.ts +5 -0
- package/lib/executable/internal/PluginConfigurator.js +168 -0
- package/lib/executable/internal/PluginConfigurator.js.map +1 -0
- package/package.json +7 -3
- package/src/decorators/EncryptedBody.ts +1 -1
- package/src/decorators/EncryptedRoute.ts +4 -4
- package/src/decorators/TypedRoute.ts +3 -2
- package/src/executable/core.ts +39 -18
- package/src/executable/internal/ArgumentParser.ts +144 -0
- package/src/executable/internal/CommandExecutor.ts +8 -0
- package/src/executable/internal/PackageManager.ts +99 -0
- package/src/executable/internal/PluginConfigurator.ts +128 -0
- package/lib/executable/internal/CommandParser.d.ts +0 -3
- package/lib/executable/internal/CommandParser.js +0 -21
- package/lib/executable/internal/CommandParser.js.map +0 -1
- package/lib/executable/internal/CoreSetupWizard.d.ts +0 -8
- package/lib/executable/internal/CoreSetupWizard.js +0 -271
- package/lib/executable/internal/CoreSetupWizard.js.map +0 -1
- package/src/executable/internal/CommandParser.ts +0 -15
- package/src/executable/internal/CoreSetupWizard.ts +0 -225
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
import type Comment from "comment-json";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
export namespace CoreSetupWizard {
|
|
6
|
-
export interface IArguments {
|
|
7
|
-
manager: "npm" | "pnpm" | "yarn";
|
|
8
|
-
project: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function ttypescript(
|
|
12
|
-
args: string | IArguments,
|
|
13
|
-
): Promise<void> {
|
|
14
|
-
// POLYFILL
|
|
15
|
-
if (typeof args === "string")
|
|
16
|
-
args = {
|
|
17
|
-
manager: args as "npm",
|
|
18
|
-
project: "tsconfig.json",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// INSTALL
|
|
22
|
-
const pack: any = await prepare(args.manager);
|
|
23
|
-
add(args.manager)(pack)("ttypescript", true);
|
|
24
|
-
add(args.manager)(pack)("ts-node", true);
|
|
25
|
-
|
|
26
|
-
// TSCONFIG.JSON
|
|
27
|
-
await configure(args)(pack);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function tsPatch(args: string | IArguments): Promise<void> {
|
|
31
|
-
// POLYFILL
|
|
32
|
-
if (typeof args === "string")
|
|
33
|
-
args = {
|
|
34
|
-
manager: args as "npm",
|
|
35
|
-
project: "tsconfig.json",
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// INSTALL
|
|
39
|
-
add(args.manager)(await prepare(args.manager))("ts-patch", true);
|
|
40
|
-
execute("npx ts-patch install");
|
|
41
|
-
|
|
42
|
-
// PACKAGE.JSON
|
|
43
|
-
const pack: any = JSON.parse(
|
|
44
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
45
|
-
);
|
|
46
|
-
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
47
|
-
pack.scripts = {};
|
|
48
|
-
if (typeof pack.scripts.prepare === "string") {
|
|
49
|
-
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
50
|
-
pack.scripts.prepare =
|
|
51
|
-
"ts-patch install && " + pack.scripts.prepare;
|
|
52
|
-
} else pack.scripts.prepare = "ts-patch install";
|
|
53
|
-
|
|
54
|
-
await fs.promises.writeFile(
|
|
55
|
-
"package.json",
|
|
56
|
-
JSON.stringify(pack, null, 2),
|
|
57
|
-
"utf8",
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// TSCONFIG.JSON
|
|
61
|
-
await configure(args)(pack);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function prepare(manager: string): Promise<any> {
|
|
65
|
-
if (fs.existsSync("package.json") === false)
|
|
66
|
-
halt(() => {})("make package.json file or move to it.");
|
|
67
|
-
|
|
68
|
-
const pack: any = JSON.parse(
|
|
69
|
-
await fs.promises.readFile("package.json", "utf8"),
|
|
70
|
-
);
|
|
71
|
-
add(manager)(pack)("typescript", true);
|
|
72
|
-
add(manager)(pack)("typia", false);
|
|
73
|
-
add(manager)(pack)("@nestia/core", false);
|
|
74
|
-
return pack;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const configure =
|
|
78
|
-
(args: IArguments) =>
|
|
79
|
-
async (pack: any): Promise<void> => {
|
|
80
|
-
if (fs.existsSync(args.project) === false) {
|
|
81
|
-
if (args.project === "tsconfig.json") execute("npx tsc --init");
|
|
82
|
-
if (fs.existsSync(args.project) === false)
|
|
83
|
-
halt(() => {})(`${args.project} file does not exist.`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const temporary: boolean = !fs.existsSync(
|
|
87
|
-
"node_modules/comment-json",
|
|
88
|
-
);
|
|
89
|
-
if (temporary === true)
|
|
90
|
-
add(args.manager)(pack)("comment-json", true);
|
|
91
|
-
|
|
92
|
-
const halter: (msg: string) => never = halt(() => {
|
|
93
|
-
if (temporary === true)
|
|
94
|
-
remove(args.manager)("comment-json", true);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// READ TSCONFIG FILE
|
|
98
|
-
const Comment: typeof import("comment-json") = await import(
|
|
99
|
-
process.cwd() + "/node_modules/comment-json"
|
|
100
|
-
);
|
|
101
|
-
const config: Comment.CommentObject = Comment.parse(
|
|
102
|
-
await fs.promises.readFile(args.project, "utf8"),
|
|
103
|
-
) as Comment.CommentObject;
|
|
104
|
-
const options = config.compilerOptions as
|
|
105
|
-
| Comment.CommentObject
|
|
106
|
-
| undefined;
|
|
107
|
-
if (options === undefined)
|
|
108
|
-
halter(
|
|
109
|
-
`${args.project} file does not have "compilerOptions" property.`,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
113
|
-
(() => {
|
|
114
|
-
const plugins = options.plugins as
|
|
115
|
-
| Comment.CommentArray<Comment.CommentObject>
|
|
116
|
-
| undefined;
|
|
117
|
-
if (plugins === undefined)
|
|
118
|
-
return (options.plugins = [] as any);
|
|
119
|
-
else if (!Array.isArray(plugins))
|
|
120
|
-
halter(
|
|
121
|
-
`"plugins" property of ${args.project} must be array type.`,
|
|
122
|
-
);
|
|
123
|
-
return plugins;
|
|
124
|
-
})();
|
|
125
|
-
|
|
126
|
-
// CHECK WHETHER CONFIGURED
|
|
127
|
-
const strict: boolean = options.strict === true;
|
|
128
|
-
const core: Comment.CommentObject | undefined = plugins.find(
|
|
129
|
-
(p) =>
|
|
130
|
-
typeof p === "object" &&
|
|
131
|
-
p !== null &&
|
|
132
|
-
p.transform === "@nestia/core/lib/transform",
|
|
133
|
-
);
|
|
134
|
-
const typia: Comment.CommentObject | undefined = plugins.find(
|
|
135
|
-
(p) =>
|
|
136
|
-
typeof p === "object" &&
|
|
137
|
-
p !== null &&
|
|
138
|
-
p.transform === "typia/lib/transform",
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
if (strict === true && core !== undefined && typia !== undefined) {
|
|
142
|
-
console.log(
|
|
143
|
-
`you've been already configured the ${args.project} file.`,
|
|
144
|
-
);
|
|
145
|
-
} else {
|
|
146
|
-
// DO CONFIGURE
|
|
147
|
-
options.strict = true;
|
|
148
|
-
if (core === undefined)
|
|
149
|
-
plugins.push(
|
|
150
|
-
Comment.parse(`{
|
|
151
|
-
"transform": "@nestia/core/lib/transform",
|
|
152
|
-
/**
|
|
153
|
-
* Validate request body.
|
|
154
|
-
*
|
|
155
|
-
* - "assert": Use typia.assert() function
|
|
156
|
-
* - "is": Use typia.is() function
|
|
157
|
-
* - "validate": Use typia.validate() function
|
|
158
|
-
*/
|
|
159
|
-
"validate": "assert",
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Validate JSON typed response body.
|
|
163
|
-
*
|
|
164
|
-
* - null: Just use JSON.stringify() function, without boosting
|
|
165
|
-
* - "stringify": Use typia.stringify() function, but dangerous
|
|
166
|
-
* - "assert": Use typia.assertStringify() function
|
|
167
|
-
* - "is": Use typia.isStringify() function
|
|
168
|
-
* - "validate": Use typia.validateStringify() function
|
|
169
|
-
*/
|
|
170
|
-
"stringify": "is"
|
|
171
|
-
}`) as Comment.CommentObject,
|
|
172
|
-
);
|
|
173
|
-
if (typia === undefined)
|
|
174
|
-
plugins.push(
|
|
175
|
-
Comment.parse(`{
|
|
176
|
-
"transform": "typia/lib/transform"
|
|
177
|
-
}`) as Comment.CommentObject,
|
|
178
|
-
);
|
|
179
|
-
await fs.promises.writeFile(
|
|
180
|
-
args.project,
|
|
181
|
-
Comment.stringify(config, null, 2),
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
if (temporary === true) remove(args.manager)("comment-json", false);
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const add =
|
|
189
|
-
(manager: string) =>
|
|
190
|
-
(pack: any) =>
|
|
191
|
-
(modulo: string, devOnly: boolean): void => {
|
|
192
|
-
const exists: boolean =
|
|
193
|
-
(devOnly === false
|
|
194
|
-
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
195
|
-
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
196
|
-
fs.existsSync("node_modules/" + modulo);
|
|
197
|
-
const middle: string =
|
|
198
|
-
manager === "yarn"
|
|
199
|
-
? `add${devOnly ? " -D" : ""}`
|
|
200
|
-
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
201
|
-
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const remove =
|
|
205
|
-
(manager: string) =>
|
|
206
|
-
(modulo: string, devOnly: boolean): void => {
|
|
207
|
-
const middle: string =
|
|
208
|
-
manager === "yarn"
|
|
209
|
-
? `remove${devOnly ? " -D" : ""}`
|
|
210
|
-
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
211
|
-
execute(`${manager} ${middle} ${modulo}`);
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const halt =
|
|
215
|
-
(closer: () => any) =>
|
|
216
|
-
(desc: string): never => {
|
|
217
|
-
closer();
|
|
218
|
-
console.error(desc);
|
|
219
|
-
process.exit(-1);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
function execute(command: string): void {
|
|
223
|
-
console.log(command);
|
|
224
|
-
cp.execSync(command, { stdio: "inherit" });
|
|
225
|
-
}
|