@nestia/core 0.1.4 → 0.1.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/lib/decorators/DynamicModule.d.ts +3 -0
- package/lib/decorators/DynamicModule.js +73 -0
- package/lib/decorators/DynamicModule.js.map +1 -0
- package/lib/decorators/EncryptedModule.js +16 -137
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/PlainBody.d.ts +1 -1
- package/lib/decorators/PlainBody.js +1 -1
- package/lib/decorators/internal/headers_to_object.d.ts +3 -1
- package/lib/decorators/internal/headers_to_object.js +0 -3
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/load_controller.d.ts +2 -0
- package/lib/decorators/internal/load_controller.js +153 -0
- package/lib/decorators/internal/load_controller.js.map +1 -0
- package/lib/decorators/internal/route_error.d.ts +3 -1
- package/lib/decorators/internal/route_error.js +0 -3
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/lib/executable/core.d.ts +2 -0
- package/lib/executable/core.js +100 -0
- package/lib/executable/core.js.map +1 -0
- package/lib/executable/internal/CommandParser.d.ts +3 -0
- package/lib/executable/internal/CommandParser.js +21 -0
- package/lib/executable/internal/CommandParser.js.map +1 -0
- package/lib/executable/internal/CoreSetupWizard.d.ts +4 -0
- package/lib/executable/internal/CoreSetupWizard.js +259 -0
- package/lib/executable/internal/CoreSetupWizard.js.map +1 -0
- package/lib/module.d.ts +2 -0
- package/lib/module.js +2 -0
- package/lib/module.js.map +1 -1
- package/package.json +5 -1
- package/src/decorators/DynamicModule.ts +16 -0
- package/src/decorators/EncryptedModule.ts +9 -59
- package/src/decorators/PlainBody.ts +1 -1
- package/src/decorators/internal/headers_to_object.ts +0 -3
- package/src/decorators/internal/load_controller.ts +35 -0
- package/src/decorators/internal/route_error.ts +0 -3
- package/src/executable/core.ts +46 -0
- package/src/executable/internal/CommandParser.ts +15 -0
- package/src/executable/internal/CoreSetupWizard.ts +177 -0
- package/src/module.ts +2 -0
- package/src/options/INestiaTransformOptions.ts +1 -1
- package/src/options/INestiaTransformProject.ts +2 -1
|
@@ -0,0 +1,177 @@
|
|
|
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 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
|
+
add(manager)(pack)("typescript", true);
|
|
51
|
+
add(manager)(pack)("typia", false);
|
|
52
|
+
add(manager)(pack)("@nestia/core", false);
|
|
53
|
+
return pack;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const configure =
|
|
57
|
+
(manager: string) =>
|
|
58
|
+
async (pack: any): Promise<void> => {
|
|
59
|
+
// VALIDATE PRERATATION
|
|
60
|
+
if (fs.existsSync("tsconfig.json") === false) {
|
|
61
|
+
execute("npx tsc --init");
|
|
62
|
+
if (fs.existsSync("tsconfig.json") === false)
|
|
63
|
+
halt(() => {})("tsconfig.json file does not exist.");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const temporary: boolean = !fs.existsSync(
|
|
67
|
+
"node_modules/comment-json",
|
|
68
|
+
);
|
|
69
|
+
if (temporary === true) add(manager)(pack)("comment-json", true);
|
|
70
|
+
|
|
71
|
+
const halter: (msg: string) => never = halt(() => {
|
|
72
|
+
if (temporary === true) remove(manager)("comment-json", true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// READ TSCONFIG FILE
|
|
76
|
+
const Comment: typeof import("comment-json") = await import(
|
|
77
|
+
process.cwd() + "/node_modules/comment-json"
|
|
78
|
+
);
|
|
79
|
+
const config: Comment.CommentObject = Comment.parse(
|
|
80
|
+
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
81
|
+
) as Comment.CommentObject;
|
|
82
|
+
const options = config.compilerOptions as
|
|
83
|
+
| Comment.CommentObject
|
|
84
|
+
| undefined;
|
|
85
|
+
if (options === undefined)
|
|
86
|
+
halter(
|
|
87
|
+
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
91
|
+
(() => {
|
|
92
|
+
const plugins = options.plugins as
|
|
93
|
+
| Comment.CommentArray<Comment.CommentObject>
|
|
94
|
+
| undefined;
|
|
95
|
+
if (plugins === undefined)
|
|
96
|
+
return (options.plugins = [] as any);
|
|
97
|
+
else if (!Array.isArray(plugins))
|
|
98
|
+
halter(
|
|
99
|
+
`"plugins" property of tsconfig.json must be array type.`,
|
|
100
|
+
);
|
|
101
|
+
return plugins;
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
// CHECK WHETHER CONFIGURED
|
|
105
|
+
const strict: boolean = options.strict === true;
|
|
106
|
+
const core: Comment.CommentObject | undefined = plugins.find(
|
|
107
|
+
(p) =>
|
|
108
|
+
typeof p === "object" &&
|
|
109
|
+
p !== null &&
|
|
110
|
+
p.transform === "@nestia/core/lib/transform",
|
|
111
|
+
);
|
|
112
|
+
const typia: Comment.CommentObject | undefined = plugins.find(
|
|
113
|
+
(p) =>
|
|
114
|
+
typeof p === "object" &&
|
|
115
|
+
p !== null &&
|
|
116
|
+
p.transform === "typia/lib/transform",
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (strict === true && core !== undefined && typia !== undefined) {
|
|
120
|
+
console.log(
|
|
121
|
+
"you've been already configured the tsconfig.json file.",
|
|
122
|
+
);
|
|
123
|
+
} else {
|
|
124
|
+
// DO CONFIGURE
|
|
125
|
+
options.strict = true;
|
|
126
|
+
if (core === undefined)
|
|
127
|
+
plugins.push({
|
|
128
|
+
transform: "@nestia/core/lib/transform",
|
|
129
|
+
} as any);
|
|
130
|
+
if (typia === undefined)
|
|
131
|
+
await fs.promises.writeFile(
|
|
132
|
+
"tsconfig.json",
|
|
133
|
+
Comment.stringify(config, null, 2),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
if (temporary === true) remove(manager)("comment-json", false);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const add =
|
|
141
|
+
(manager: string) =>
|
|
142
|
+
(pack: any) =>
|
|
143
|
+
(modulo: string, devOnly: boolean): void => {
|
|
144
|
+
const exists: boolean =
|
|
145
|
+
(devOnly === false
|
|
146
|
+
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
147
|
+
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
148
|
+
fs.existsSync("node_modules/" + modulo);
|
|
149
|
+
const middle: string =
|
|
150
|
+
manager === "yarn"
|
|
151
|
+
? `add${devOnly ? " -D" : ""}`
|
|
152
|
+
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
153
|
+
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const remove =
|
|
157
|
+
(manager: string) =>
|
|
158
|
+
(modulo: string, devOnly: boolean): void => {
|
|
159
|
+
const middle: string =
|
|
160
|
+
manager === "yarn"
|
|
161
|
+
? `remove${devOnly ? " -D" : ""}`
|
|
162
|
+
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
163
|
+
execute(`${manager} ${middle} ${modulo}`);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const halt =
|
|
167
|
+
(closer: () => any) =>
|
|
168
|
+
(desc: string): never => {
|
|
169
|
+
closer();
|
|
170
|
+
console.error(desc);
|
|
171
|
+
process.exit(-1);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function execute(command: string): void {
|
|
175
|
+
console.log(command);
|
|
176
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
177
|
+
}
|
package/src/module.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./decorators/DynamicModule";
|
|
1
2
|
export * from "./decorators/EncryptedBody";
|
|
2
3
|
export * from "./decorators/EncryptedController";
|
|
3
4
|
export * from "./decorators/EncryptedModule";
|
|
@@ -7,3 +8,4 @@ export * from "./decorators/PlainBody";
|
|
|
7
8
|
export * from "./decorators/TypedBody";
|
|
8
9
|
export * from "./decorators/TypedParam";
|
|
9
10
|
export * from "./decorators/TypedRoute";
|
|
11
|
+
export * from "./options/INestiaTransformOptions";
|