@nestia/core 1.0.9 → 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 +34 -285
- package/lib/decorators/DynamicModule.d.ts +20 -1
- package/lib/decorators/DynamicModule.js +22 -3
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.d.ts +8 -7
- package/lib/decorators/EncryptedBody.js +8 -7
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedRoute.d.ts +7 -8
- package/lib/decorators/EncryptedRoute.js +9 -9
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/TypedBody.d.ts +8 -6
- package/lib/decorators/TypedBody.js +8 -6
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedParam.d.ts +5 -5
- package/lib/decorators/TypedParam.js +5 -5
- package/lib/decorators/TypedQuery.d.ts +14 -1
- package/lib/decorators/TypedQuery.js +18 -1
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.d.ts +6 -5
- package/lib/decorators/TypedRoute.js +6 -5
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/internal/TransformError.d.ts +1 -0
- package/lib/decorators/internal/TransformError.js +11 -0
- package/lib/decorators/internal/TransformError.js.map +1 -0
- package/lib/decorators/internal/get_path_and_stringify.js +2 -1
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +2 -1
- package/lib/decorators/internal/validate_request_body.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 +8 -3
- package/src/decorators/DynamicModule.ts +21 -2
- package/src/decorators/EncryptedBody.ts +12 -8
- package/src/decorators/EncryptedRoute.ts +10 -11
- package/src/decorators/TypedBody.ts +9 -6
- package/src/decorators/TypedParam.ts +6 -6
- package/src/decorators/TypedQuery.ts +22 -3
- package/src/decorators/TypedRoute.ts +7 -5
- package/src/decorators/internal/TransformError.ts +8 -0
- package/src/decorators/internal/get_path_and_stringify.ts +3 -4
- package/src/decorators/internal/validate_request_body.ts +3 -4
- 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
|
@@ -3,9 +3,25 @@ import express from "express";
|
|
|
3
3
|
|
|
4
4
|
import { assert } from "typia";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { TransformError } from "./internal/TransformError";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type safe URL query decorator.
|
|
10
|
+
*
|
|
11
|
+
* `TypedQuery` is a decorator function that can parse URL query string. It is almost
|
|
12
|
+
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
13
|
+
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
14
|
+
*
|
|
15
|
+
* For referecen, when URL query parameters are different with their promised
|
|
16
|
+
* type `T`, `BadRequestException` error (status code: 400) would be thrown.
|
|
17
|
+
*
|
|
18
|
+
* @returns Parameter decorator
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
21
|
+
export function TypedQuery<T>(
|
|
22
|
+
decoder?: (params: URLSearchParams) => T,
|
|
23
|
+
): ParameterDecorator {
|
|
24
|
+
if (decoder === undefined) throw TransformError("TypedQuery");
|
|
9
25
|
|
|
10
26
|
return createParamDecorator(async function TypedQuery(
|
|
11
27
|
_unknown: any,
|
|
@@ -36,6 +52,9 @@ export namespace TypedQuery {
|
|
|
36
52
|
}
|
|
37
53
|
Object.assign(TypedQuery, assert);
|
|
38
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
39
58
|
function tail(url: string): string {
|
|
40
59
|
const index: number = url.indexOf("?");
|
|
41
60
|
return index === -1 ? "" : url.substring(index + 1);
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { HttpArgumentsHost } from "@nestjs/common/interfaces";
|
|
14
14
|
import express from "express";
|
|
15
15
|
import { Observable, catchError, map } from "rxjs";
|
|
16
|
+
|
|
16
17
|
import {
|
|
17
18
|
assertStringify,
|
|
18
19
|
isStringify,
|
|
@@ -25,14 +26,15 @@ import { get_path_and_stringify } from "./internal/get_path_and_stringify";
|
|
|
25
26
|
import { route_error } from "./internal/route_error";
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
+
* Type safe router decorator functions.
|
|
29
30
|
*
|
|
30
31
|
* `TypedRoute` is a module containing router decorator functions which can boost up
|
|
31
|
-
* JSON string conversion speed about
|
|
32
|
-
*
|
|
32
|
+
* JSON string conversion speed about 50x times faster than `class-transformer`.
|
|
33
|
+
* Furthermore, such JSON string conversion is even type safe through
|
|
34
|
+
* [typia](https://github.com/samchon/typia).
|
|
33
35
|
*
|
|
34
|
-
*
|
|
35
|
-
* regular {@link nest.HttpException} class automatically, through
|
|
36
|
+
* For reference, router functions of `TypedRoute` can convert custom error classes to
|
|
37
|
+
* the regular {@link nest.HttpException} class automatically, through
|
|
36
38
|
* {@link ExceptionManager}.
|
|
37
39
|
*
|
|
38
40
|
* @author Jeongho Nam - https://github.com/samchon
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export function TransformError(method: string): Error {
|
|
5
|
+
return new Error(
|
|
6
|
+
`Error on nestia.core.${method}(): no transform has been configured. Configure "tsconfig.json" file following [Guide Documents](https://github.com/samchon/nestia/wiki/Setup#tsconfigjson).`,
|
|
7
|
+
);
|
|
8
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { InternalServerErrorException } from "@nestjs/common";
|
|
2
|
+
|
|
2
3
|
import { IValidation, TypeGuardError } from "typia";
|
|
3
4
|
|
|
4
5
|
import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
|
|
6
|
+
import { TransformError } from "./TransformError";
|
|
5
7
|
|
|
6
8
|
export const get_path_and_stringify =
|
|
7
9
|
(method: string) =>
|
|
@@ -22,10 +24,7 @@ export const get_path_and_stringify =
|
|
|
22
24
|
const take =
|
|
23
25
|
(method: string) =>
|
|
24
26
|
<T>(functor?: IResponseBodyStringifier<T> | null) => {
|
|
25
|
-
if (functor === undefined)
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Error on nestia.core.${method}(): no stringify function provided.`,
|
|
28
|
-
);
|
|
27
|
+
if (functor === undefined) throw TransformError(method);
|
|
29
28
|
else if (functor === null) return JSON.stringify;
|
|
30
29
|
else if (functor.type === "stringify") return functor.stringify;
|
|
31
30
|
else if (functor.type === "assert") return assert(functor.assert);
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
|
|
2
3
|
import { IValidation, TypeGuardError } from "typia";
|
|
3
4
|
|
|
4
5
|
import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
|
|
6
|
+
import { TransformError } from "./TransformError";
|
|
5
7
|
|
|
6
8
|
export const validate_request_body =
|
|
7
9
|
(method: string) =>
|
|
8
10
|
<T>(validator?: IRequestBodyValidator<T>) => {
|
|
9
|
-
if (!validator)
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Error on nestia.core.${method}(): no transformer.`,
|
|
12
|
-
);
|
|
11
|
+
if (!validator) throw TransformError(method);
|
|
13
12
|
else if (validator.type === "assert") return assert(validator.assert);
|
|
14
13
|
else if (validator.type === "is") return is(validator.is);
|
|
15
14
|
else if (validator.type === "validate")
|
package/src/executable/core.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ArgumentParser } from "./internal/ArgumentParser";
|
|
3
|
+
import { CommandExecutor } from "./internal/CommandExecutor";
|
|
4
|
+
import { PackageManager } from "./internal/PackageManager";
|
|
5
|
+
import { PluginConfigurator } from "./internal/PluginConfigurator";
|
|
4
6
|
|
|
5
7
|
const USAGE = `Wrong command has been detected. Use like below:
|
|
6
8
|
|
|
@@ -20,22 +22,41 @@ function halt(desc: string): never {
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
async function setup(): Promise<void> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
console.log("----------------------------------------");
|
|
26
|
+
console.log(" Nestia Setup Wizard");
|
|
27
|
+
console.log("----------------------------------------");
|
|
28
|
+
|
|
29
|
+
// LOAD PACKAGE.JSON INFO
|
|
30
|
+
const pack: PackageManager = await PackageManager.mount();
|
|
31
|
+
|
|
32
|
+
// TAKE ARGUMENTS
|
|
33
|
+
const args: ArgumentParser.IArguments = await ArgumentParser.parse(pack);
|
|
34
|
+
|
|
35
|
+
// INSTALL TYPESCRIPT
|
|
36
|
+
pack.install({ dev: true, modulo: "typescript" });
|
|
37
|
+
args.project ??= (() => {
|
|
38
|
+
CommandExecutor.run("npx tsc --init", false);
|
|
39
|
+
return (args.project = "tsconfig.json");
|
|
40
|
+
})();
|
|
41
|
+
pack.install({ dev: true, modulo: "ts-node" });
|
|
42
|
+
|
|
43
|
+
// INSTALL COMPILER
|
|
44
|
+
pack.install({ dev: true, modulo: args.compiler });
|
|
45
|
+
if (args.compiler === "ts-patch") {
|
|
46
|
+
await pack.save((data) => {
|
|
47
|
+
data.scripts ??= {};
|
|
48
|
+
if (typeof data.scripts.prepare === "string")
|
|
49
|
+
data.scripts.prepare =
|
|
50
|
+
"ts-patch install && " + data.scripts.prepare;
|
|
51
|
+
else data.scripts.prepare = "ts-patch install";
|
|
52
|
+
});
|
|
53
|
+
CommandExecutor.run("npm run prepare", false);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// INSTALL AND CONFIGURE TYPIA
|
|
57
|
+
pack.install({ dev: false, modulo: "typia" });
|
|
58
|
+
pack.install({ dev: false, modulo: "@nestia/core" });
|
|
59
|
+
await PluginConfigurator.configure(pack, args);
|
|
39
60
|
}
|
|
40
61
|
|
|
41
62
|
async function main(): Promise<void> {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type CommanderModule from "commander";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import type * as InquirerModule from "inquirer";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
import { PackageManager } from "./PackageManager";
|
|
7
|
+
|
|
8
|
+
export namespace ArgumentParser {
|
|
9
|
+
export interface IArguments {
|
|
10
|
+
compiler: "ts-patch" | "ttypescript";
|
|
11
|
+
manager: "npm" | "pnpm" | "yarn";
|
|
12
|
+
project: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function parse(pack: PackageManager): Promise<IArguments> {
|
|
16
|
+
// INSTALL TEMPORARY PACKAGES
|
|
17
|
+
const newbie = {
|
|
18
|
+
commander: pack.install({
|
|
19
|
+
dev: true,
|
|
20
|
+
modulo: "commander",
|
|
21
|
+
version: "10.0.0",
|
|
22
|
+
silent: true,
|
|
23
|
+
}),
|
|
24
|
+
inquirer: pack.install({
|
|
25
|
+
dev: true,
|
|
26
|
+
modulo: "inquirer",
|
|
27
|
+
version: "8.2.5",
|
|
28
|
+
silent: true,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// TAKE OPTIONS
|
|
33
|
+
const output: IArguments | Error = await (async () => {
|
|
34
|
+
try {
|
|
35
|
+
return await _Parse(pack);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return error as Error;
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
|
|
41
|
+
// REMOVE TEMPORARY PACKAGES
|
|
42
|
+
if (newbie.commander) pack.erase({ modulo: "commander", silent: true });
|
|
43
|
+
if (newbie.inquirer) pack.erase({ modulo: "inquirer", silent: true });
|
|
44
|
+
|
|
45
|
+
// RETURNS
|
|
46
|
+
if (output instanceof Error) throw output;
|
|
47
|
+
return output;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function _Parse(pack: PackageManager): Promise<IArguments> {
|
|
51
|
+
// PREPARE ASSETS
|
|
52
|
+
const { createPromptModule }: typeof InquirerModule = await import(
|
|
53
|
+
path.join(pack.directory, "node_modules", "inquirer")
|
|
54
|
+
);
|
|
55
|
+
const { program }: typeof CommanderModule = await import(
|
|
56
|
+
path.join(pack.directory, "node_modules", "commander")
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
program.option("--compiler [compiler]", "compiler type");
|
|
60
|
+
program.option("--manager [manager", "package manager");
|
|
61
|
+
program.option("--project [project]", "tsconfig.json file location");
|
|
62
|
+
|
|
63
|
+
// INTERNAL PROCEDURES
|
|
64
|
+
const questioned = { value: false };
|
|
65
|
+
const action = (
|
|
66
|
+
closure: (options: Partial<IArguments>) => Promise<IArguments>,
|
|
67
|
+
) => {
|
|
68
|
+
return new Promise<IArguments>((resolve, reject) => {
|
|
69
|
+
program.action(async (options) => {
|
|
70
|
+
try {
|
|
71
|
+
resolve(await closure(options));
|
|
72
|
+
} catch (exp) {
|
|
73
|
+
reject(exp);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
program.parseAsync().catch(reject);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const select =
|
|
80
|
+
(name: string) =>
|
|
81
|
+
(message: string) =>
|
|
82
|
+
async <Choice extends string>(
|
|
83
|
+
choices: Choice[],
|
|
84
|
+
): Promise<Choice> => {
|
|
85
|
+
questioned.value = true;
|
|
86
|
+
return (
|
|
87
|
+
await createPromptModule()({
|
|
88
|
+
type: "list",
|
|
89
|
+
name: name,
|
|
90
|
+
message: message,
|
|
91
|
+
choices: choices,
|
|
92
|
+
})
|
|
93
|
+
)[name];
|
|
94
|
+
};
|
|
95
|
+
const configure = async () => {
|
|
96
|
+
const fileList: string[] = await (
|
|
97
|
+
await fs.promises.readdir(process.cwd())
|
|
98
|
+
).filter(
|
|
99
|
+
(str) =>
|
|
100
|
+
str.substring(0, 8) === "tsconfig" &&
|
|
101
|
+
str.substring(str.length - 5) === ".json",
|
|
102
|
+
);
|
|
103
|
+
if (fileList.length === 0) {
|
|
104
|
+
if (process.cwd() !== pack.directory)
|
|
105
|
+
throw new Error(`Unable to find "tsconfig.json" file.`);
|
|
106
|
+
return null;
|
|
107
|
+
} else if (fileList.length === 1) return fileList[0];
|
|
108
|
+
return select("tsconfig")("TS Config File")(fileList);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// DO CONSTRUCT
|
|
112
|
+
return action(async (options) => {
|
|
113
|
+
if (options.compiler === undefined) {
|
|
114
|
+
console.log(COMPILER_DESCRIPTION);
|
|
115
|
+
options.compiler = await select("compiler")(`Compiler`)(
|
|
116
|
+
pack.data.scripts?.build === "nest build"
|
|
117
|
+
? ["ts-patch" as const, "ttypescript" as const]
|
|
118
|
+
: ["ttypescript" as const, "ts-patch" as const],
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
options.manager ??= await select("manager")("Package Manager")([
|
|
122
|
+
"npm" as const,
|
|
123
|
+
"pnpm" as const,
|
|
124
|
+
"yarn" as const,
|
|
125
|
+
]);
|
|
126
|
+
pack.manager = options.manager;
|
|
127
|
+
options.project ??= await configure();
|
|
128
|
+
|
|
129
|
+
if (questioned.value) console.log("");
|
|
130
|
+
return options as IArguments;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const COMPILER_DESCRIPTION = [
|
|
136
|
+
`About compiler, if you adapt "ttypescript", you should use "ttsc" instead.`,
|
|
137
|
+
``,
|
|
138
|
+
`Otherwise, you choose "ts-patch", you can use the original "tsc" command.`,
|
|
139
|
+
`However, the "ts-patch" hacks "node_modules/typescript" source code.`,
|
|
140
|
+
`Also, whenever update "typescript", you've to run "npm run prepare" command.`,
|
|
141
|
+
``,
|
|
142
|
+
`By the way, when using "@nest/cli", you must just choose "ts-patch".`,
|
|
143
|
+
``,
|
|
144
|
+
].join("\n");
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import { CommandExecutor } from "./CommandExecutor";
|
|
5
|
+
|
|
6
|
+
export class PackageManager {
|
|
7
|
+
public manager: string = "npm";
|
|
8
|
+
public get file(): string {
|
|
9
|
+
return path.join(this.directory, "package.json");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public static async mount(): Promise<PackageManager> {
|
|
13
|
+
const location: string | null = await find(process.cwd());
|
|
14
|
+
if (location === null)
|
|
15
|
+
throw new Error(`Unable to find "package.json" file`);
|
|
16
|
+
|
|
17
|
+
return new PackageManager(
|
|
18
|
+
location,
|
|
19
|
+
await this.load(path.join(location, "package.json")),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async save(modifier: (data: Package.Data) => void): Promise<void> {
|
|
24
|
+
const content: string = await fs.promises.readFile(this.file, "utf8");
|
|
25
|
+
this.data = JSON.parse(content);
|
|
26
|
+
modifier(this.data);
|
|
27
|
+
|
|
28
|
+
return fs.promises.writeFile(
|
|
29
|
+
this.file,
|
|
30
|
+
JSON.stringify(this.data, null, 2),
|
|
31
|
+
"utf8",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public install(props: {
|
|
36
|
+
dev: boolean;
|
|
37
|
+
silent?: boolean;
|
|
38
|
+
modulo: string;
|
|
39
|
+
version?: string;
|
|
40
|
+
}): boolean {
|
|
41
|
+
const container = props.dev
|
|
42
|
+
? this.data.devDependencies
|
|
43
|
+
: this.data.dependencies;
|
|
44
|
+
if (
|
|
45
|
+
!!container?.[props.modulo] &&
|
|
46
|
+
fs.existsSync(
|
|
47
|
+
path.join(this.directory, "node_modules", props.modulo),
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
return false;
|
|
51
|
+
|
|
52
|
+
const middle: string =
|
|
53
|
+
this.manager === "yarn"
|
|
54
|
+
? `add${props.dev ? " -D" : ""}`
|
|
55
|
+
: `install ${props.dev ? "--save-dev" : "--save"}`;
|
|
56
|
+
CommandExecutor.run(
|
|
57
|
+
`${this.manager} ${middle} ${props.modulo}${
|
|
58
|
+
props.version ? `@${props.version}` : ""
|
|
59
|
+
}`,
|
|
60
|
+
!!props.silent,
|
|
61
|
+
);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public erase(props: { modulo: string; silent?: boolean }): void {
|
|
66
|
+
const middle: string = this.manager === "yarn" ? "remove" : "uninstall";
|
|
67
|
+
CommandExecutor.run(
|
|
68
|
+
`${this.manager} ${middle} ${props.modulo}`,
|
|
69
|
+
!!props.silent,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private constructor(
|
|
74
|
+
public readonly directory: string,
|
|
75
|
+
public data: Package.Data,
|
|
76
|
+
) {}
|
|
77
|
+
|
|
78
|
+
private static async load(file: string): Promise<Package.Data> {
|
|
79
|
+
const content: string = await fs.promises.readFile(file, "utf8");
|
|
80
|
+
return JSON.parse(content);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export namespace Package {
|
|
84
|
+
export interface Data {
|
|
85
|
+
scripts?: Record<string, string>;
|
|
86
|
+
dependencies?: Record<string, string>;
|
|
87
|
+
devDependencies?: Record<string, string>;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function find(
|
|
92
|
+
directory: string = process.cwd(),
|
|
93
|
+
depth: number = 0,
|
|
94
|
+
): Promise<string | null> {
|
|
95
|
+
const location: string = path.join(directory, "package.json");
|
|
96
|
+
if (fs.existsSync(location)) return directory;
|
|
97
|
+
else if (depth > 1) return null;
|
|
98
|
+
return find(path.join(directory, ".."), depth + 1);
|
|
99
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type Comment from "comment-json";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
import { ArgumentParser } from "./ArgumentParser";
|
|
6
|
+
import { PackageManager } from "./PackageManager";
|
|
7
|
+
|
|
8
|
+
export namespace PluginConfigurator {
|
|
9
|
+
export async function configure(
|
|
10
|
+
pack: PackageManager,
|
|
11
|
+
args: ArgumentParser.IArguments,
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
// INSTALL COMMENT-JSON
|
|
14
|
+
const installed: boolean = pack.install({
|
|
15
|
+
dev: true,
|
|
16
|
+
modulo: "comment-json",
|
|
17
|
+
version: "4.2.3",
|
|
18
|
+
silent: true,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// DO CONFIGURE
|
|
22
|
+
const error: Error | null = await (async () => {
|
|
23
|
+
try {
|
|
24
|
+
await _Configure(pack, args);
|
|
25
|
+
return null;
|
|
26
|
+
} catch (exp) {
|
|
27
|
+
return exp as Error;
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
|
|
31
|
+
// REMOVE IT
|
|
32
|
+
if (installed)
|
|
33
|
+
pack.erase({
|
|
34
|
+
modulo: "comment-json",
|
|
35
|
+
silent: true,
|
|
36
|
+
});
|
|
37
|
+
if (error !== null) throw error;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function _Configure(
|
|
41
|
+
pack: PackageManager,
|
|
42
|
+
args: ArgumentParser.IArguments,
|
|
43
|
+
): Promise<void> {
|
|
44
|
+
// GET COMPILER-OPTIONS
|
|
45
|
+
const Comment: typeof import("comment-json") = await import(
|
|
46
|
+
path.join(pack.directory, "node_modules", "comment-json")
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const config: Comment.CommentObject = Comment.parse(
|
|
50
|
+
await fs.promises.readFile(args.project!, "utf8"),
|
|
51
|
+
) as Comment.CommentObject;
|
|
52
|
+
const compilerOptions = config.compilerOptions as
|
|
53
|
+
| Comment.CommentObject
|
|
54
|
+
| undefined;
|
|
55
|
+
if (compilerOptions === undefined)
|
|
56
|
+
throw new Error(
|
|
57
|
+
`${args.project} file does not have "compilerOptions" property.`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// PREPARE PLUGINS
|
|
61
|
+
const plugins: Comment.CommentArray<Comment.CommentObject> = (() => {
|
|
62
|
+
const plugins = compilerOptions.plugins as
|
|
63
|
+
| Comment.CommentArray<Comment.CommentObject>
|
|
64
|
+
| undefined;
|
|
65
|
+
if (plugins === undefined)
|
|
66
|
+
return (compilerOptions.plugins = [] as any);
|
|
67
|
+
else if (!Array.isArray(plugins))
|
|
68
|
+
throw new Error(
|
|
69
|
+
`"plugins" property of ${args.project} must be array type.`,
|
|
70
|
+
);
|
|
71
|
+
return plugins;
|
|
72
|
+
})();
|
|
73
|
+
|
|
74
|
+
// CHECK WHETHER CONFIGURED
|
|
75
|
+
const strict: boolean = compilerOptions.strict === true;
|
|
76
|
+
const core: Comment.CommentObject | undefined = plugins.find(
|
|
77
|
+
(p) =>
|
|
78
|
+
typeof p === "object" &&
|
|
79
|
+
p !== null &&
|
|
80
|
+
p.transform === "@nestia/core/lib/transform",
|
|
81
|
+
);
|
|
82
|
+
const typia: Comment.CommentObject | undefined = plugins.find(
|
|
83
|
+
(p) =>
|
|
84
|
+
typeof p === "object" &&
|
|
85
|
+
p !== null &&
|
|
86
|
+
p.transform === "typia/lib/transform",
|
|
87
|
+
);
|
|
88
|
+
if (strict && !!core && !!typia) return;
|
|
89
|
+
|
|
90
|
+
// DO CONFIGURE
|
|
91
|
+
compilerOptions.strict = true;
|
|
92
|
+
if (core === undefined)
|
|
93
|
+
plugins.push(
|
|
94
|
+
Comment.parse(`{
|
|
95
|
+
"transform": "@nestia/core/lib/transform",
|
|
96
|
+
/**
|
|
97
|
+
* Validate request body.
|
|
98
|
+
*
|
|
99
|
+
* - "assert": Use typia.assert() function
|
|
100
|
+
* - "is": Use typia.is() function
|
|
101
|
+
* - "validate": Use typia.validate() function
|
|
102
|
+
*/
|
|
103
|
+
"validate": "assert",
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Validate JSON typed response body.
|
|
107
|
+
*
|
|
108
|
+
* - null: Just use JSON.stringify() function, without boosting
|
|
109
|
+
* - "stringify": Use typia.stringify() function, but dangerous
|
|
110
|
+
* - "assert": Use typia.assertStringify() function
|
|
111
|
+
* - "is": Use typia.isStringify() function
|
|
112
|
+
* - "validate": Use typia.validateStringify() function
|
|
113
|
+
*/
|
|
114
|
+
"stringify": "is"
|
|
115
|
+
}`) as Comment.CommentObject,
|
|
116
|
+
);
|
|
117
|
+
if (typia === undefined)
|
|
118
|
+
plugins.push(
|
|
119
|
+
Comment.parse(
|
|
120
|
+
`{ "transform": "typia/lib/transform" }`,
|
|
121
|
+
) as Comment.CommentObject,
|
|
122
|
+
);
|
|
123
|
+
await fs.promises.writeFile(
|
|
124
|
+
args.project!,
|
|
125
|
+
Comment.stringify(config, null, 2),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|