nestia 5.3.0 → 5.3.1
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 +2 -2
- package/bin/NestiaSetupWizard.js +1 -1
- package/bin/internal/PluginConfigurator.js +24 -24
- package/package.json +2 -2
- package/src/NestiaSetupWizard.ts +73 -73
- package/src/internal/CommandExecutor.ts +8 -8
- package/src/internal/FileRetriever.ts +22 -22
- package/src/internal/PackageManager.ts +72 -72
- package/src/internal/PluginConfigurator.ts +106 -106
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
|
18
18
|
- `@nestia/migrate`: migration from Swagger to NestJS
|
|
19
19
|
- `nestia`: just CLI (command line interface) tool
|
|
20
20
|
|
|
21
|
-
>
|
|
21
|
+
> [!NOTE]
|
|
22
22
|
>
|
|
23
23
|
> - **Only one line** required, with pure TypeScript type
|
|
24
24
|
> - Enhance performance **30x** up
|
|
@@ -59,7 +59,7 @@ Check out the document in the [website](https://nestia.io/docs/):
|
|
|
59
59
|
- [TypedRoute](https://nestia.io/docs/core/TypedRoute/)
|
|
60
60
|
- [TypedBody](https://nestia.io/docs/core/TypedBody/)
|
|
61
61
|
- [TypedParam](https://nestia.io/docs/core/TypedParam/)
|
|
62
|
-
- [TypedQuery](https://nestia.io/docs/core/
|
|
62
|
+
- [TypedQuery](https://nestia.io/docs/core/TypedRoute/)
|
|
63
63
|
- [TypedHeaders](https://nestia.io/docs/core/TypedHeaders/)
|
|
64
64
|
- [TypedException](https://nestia.io/docs/core/TypedException/)
|
|
65
65
|
- Generators
|
package/bin/NestiaSetupWizard.js
CHANGED
|
@@ -35,7 +35,7 @@ var NestiaSetupWizard;
|
|
|
35
35
|
// INSTALL TYPESCRIPT COMPILERS
|
|
36
36
|
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
37
37
|
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
38
|
-
pack.install({ dev: true, modulo: "typescript", version: "5.
|
|
38
|
+
pack.install({ dev: true, modulo: "typescript", version: "5.5.2" });
|
|
39
39
|
(_a = args.project) !== null && _a !== void 0 ? _a : (args.project = (() => {
|
|
40
40
|
const runner = pack.manager === "npm" ? "npx" : pack.manager;
|
|
41
41
|
CommandExecutor_1.CommandExecutor.run(`${runner} tsc --init`);
|
|
@@ -54,30 +54,30 @@ var PluginConfigurator;
|
|
|
54
54
|
compilerOptions.experimentalDecorators = true;
|
|
55
55
|
compilerOptions.emitDecoratorMetadata = true;
|
|
56
56
|
if (core === undefined)
|
|
57
|
-
plugins.push(comment_json_1.default.parse(`{
|
|
58
|
-
"transform": "@nestia/core/lib/transform",
|
|
59
|
-
/**
|
|
60
|
-
* Validate request body.
|
|
61
|
-
*
|
|
62
|
-
* - "assert": Use typia.assert() function
|
|
63
|
-
* - "is": Use typia.is() function
|
|
64
|
-
* - "validate": Use typia.validate() function
|
|
65
|
-
* - "assertEquals": Use typia.assertEquals() function
|
|
66
|
-
* - "equals": Use typia.equals() function
|
|
67
|
-
* - "validateEquals": Use typia.validateEquals() function
|
|
68
|
-
*/
|
|
69
|
-
"validate": "assert",
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Validate JSON typed response body.
|
|
73
|
-
*
|
|
74
|
-
* - "assert": Use typia.assertStringify() function
|
|
75
|
-
* - "is": Use typia.isStringify() function
|
|
76
|
-
* - "validate": Use typia.validateStringify() function
|
|
77
|
-
* - "stringify": Use typia.stringify() function, but dangerous
|
|
78
|
-
* - null: Just use JSON.stringify() function, without boosting
|
|
79
|
-
*/
|
|
80
|
-
"stringify": "assert"
|
|
57
|
+
plugins.push(comment_json_1.default.parse(`{
|
|
58
|
+
"transform": "@nestia/core/lib/transform",
|
|
59
|
+
/**
|
|
60
|
+
* Validate request body.
|
|
61
|
+
*
|
|
62
|
+
* - "assert": Use typia.assert() function
|
|
63
|
+
* - "is": Use typia.is() function
|
|
64
|
+
* - "validate": Use typia.validate() function
|
|
65
|
+
* - "assertEquals": Use typia.assertEquals() function
|
|
66
|
+
* - "equals": Use typia.equals() function
|
|
67
|
+
* - "validateEquals": Use typia.validateEquals() function
|
|
68
|
+
*/
|
|
69
|
+
"validate": "assert",
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Validate JSON typed response body.
|
|
73
|
+
*
|
|
74
|
+
* - "assert": Use typia.assertStringify() function
|
|
75
|
+
* - "is": Use typia.isStringify() function
|
|
76
|
+
* - "validate": Use typia.validateStringify() function
|
|
77
|
+
* - "stringify": Use typia.stringify() function, but dangerous
|
|
78
|
+
* - null: Just use JSON.stringify() function, without boosting
|
|
79
|
+
*/
|
|
80
|
+
"stringify": "assert"
|
|
81
81
|
}`));
|
|
82
82
|
if (typia === undefined)
|
|
83
83
|
plugins.push(comment_json_1.default.parse(`{ "transform": "typia/lib/transform" }`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestia",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "Nestia CLI tool",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@types/inquirer": "^9.0.3",
|
|
42
42
|
"@types/node": "^18.11.16",
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
|
-
"typescript": "^5.
|
|
44
|
+
"typescript": "^5.5.2"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"bin",
|
package/src/NestiaSetupWizard.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { ArgumentParser } from "./internal/ArgumentParser";
|
|
2
|
-
import { CommandExecutor } from "./internal/CommandExecutor";
|
|
3
|
-
import { PackageManager } from "./internal/PackageManager";
|
|
4
|
-
import { PluginConfigurator } from "./internal/PluginConfigurator";
|
|
5
|
-
|
|
6
|
-
export namespace NestiaSetupWizard {
|
|
7
|
-
export async function setup(): Promise<void> {
|
|
8
|
-
console.log("----------------------------------------");
|
|
9
|
-
console.log(" Nestia Setup Wizard");
|
|
10
|
-
console.log("----------------------------------------");
|
|
11
|
-
|
|
12
|
-
// PREPARE ASSETS
|
|
13
|
-
const pack: PackageManager = await PackageManager.mount();
|
|
14
|
-
const args: ArgumentParser.IArguments = await ArgumentParser.parse(pack);
|
|
15
|
-
|
|
16
|
-
// INSTALL NESTIA
|
|
17
|
-
pack.install({ dev: false, modulo: "@nestia/core", version: "latest" });
|
|
18
|
-
pack.install({ dev: false, modulo: "@nestia/e2e", version: "latest" });
|
|
19
|
-
pack.install({ dev: false, modulo: "@nestia/fetcher", version: "latest" });
|
|
20
|
-
pack.install({ dev: true, modulo: "@nestia/sdk", version: "latest" });
|
|
21
|
-
pack.install({ dev: true, modulo: "nestia", version: "latest" });
|
|
22
|
-
pack.install({ dev: false, modulo: "typia" });
|
|
23
|
-
|
|
24
|
-
// INSTALL TYPESCRIPT COMPILERS
|
|
25
|
-
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
26
|
-
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
27
|
-
pack.install({ dev: true, modulo: "typescript", version: "5.
|
|
28
|
-
args.project ??= (() => {
|
|
29
|
-
const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
|
|
30
|
-
CommandExecutor.run(`${runner} tsc --init`);
|
|
31
|
-
return (args.project = "tsconfig.json");
|
|
32
|
-
})();
|
|
33
|
-
|
|
34
|
-
// SETUP TRANSFORMER
|
|
35
|
-
await pack.save((data) => {
|
|
36
|
-
// COMPOSE PREPARE COMMAND
|
|
37
|
-
data.scripts ??= {};
|
|
38
|
-
if (
|
|
39
|
-
typeof data.scripts.prepare === "string" &&
|
|
40
|
-
data.scripts.prepare.trim().length
|
|
41
|
-
) {
|
|
42
|
-
if (
|
|
43
|
-
data.scripts.prepare.indexOf("ts-patch install") === -1 &&
|
|
44
|
-
data.scripts.prepare.indexOf("typia patch") === -1
|
|
45
|
-
)
|
|
46
|
-
data.scripts.prepare =
|
|
47
|
-
"ts-patch install && typia patch && " + data.scripts.prepare;
|
|
48
|
-
else if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
49
|
-
data.scripts.prepare = "ts-patch install && " + data.scripts.prepare;
|
|
50
|
-
else if (data.scripts.prepare.indexOf("typia patch") === -1)
|
|
51
|
-
data.scripts.prepare = data.scripts.prepare.replace(
|
|
52
|
-
"ts-patch install",
|
|
53
|
-
"ts-patch install && typia patch",
|
|
54
|
-
);
|
|
55
|
-
} else data.scripts.prepare = "ts-patch install && typia patch";
|
|
56
|
-
|
|
57
|
-
// FOR OLDER VERSIONS
|
|
58
|
-
if (typeof data.scripts.postinstall === "string") {
|
|
59
|
-
data.scripts.postinstall = data.scripts.postinstall
|
|
60
|
-
.split("&&")
|
|
61
|
-
.map((str) => str.trim())
|
|
62
|
-
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
63
|
-
.join(" && ");
|
|
64
|
-
if (data.scripts.postinstall.length === 0)
|
|
65
|
-
delete data.scripts.postinstall;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
69
|
-
|
|
70
|
-
// CONFIGURE PLUGIN
|
|
71
|
-
await PluginConfigurator.configure(args);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
import { ArgumentParser } from "./internal/ArgumentParser";
|
|
2
|
+
import { CommandExecutor } from "./internal/CommandExecutor";
|
|
3
|
+
import { PackageManager } from "./internal/PackageManager";
|
|
4
|
+
import { PluginConfigurator } from "./internal/PluginConfigurator";
|
|
5
|
+
|
|
6
|
+
export namespace NestiaSetupWizard {
|
|
7
|
+
export async function setup(): Promise<void> {
|
|
8
|
+
console.log("----------------------------------------");
|
|
9
|
+
console.log(" Nestia Setup Wizard");
|
|
10
|
+
console.log("----------------------------------------");
|
|
11
|
+
|
|
12
|
+
// PREPARE ASSETS
|
|
13
|
+
const pack: PackageManager = await PackageManager.mount();
|
|
14
|
+
const args: ArgumentParser.IArguments = await ArgumentParser.parse(pack);
|
|
15
|
+
|
|
16
|
+
// INSTALL NESTIA
|
|
17
|
+
pack.install({ dev: false, modulo: "@nestia/core", version: "latest" });
|
|
18
|
+
pack.install({ dev: false, modulo: "@nestia/e2e", version: "latest" });
|
|
19
|
+
pack.install({ dev: false, modulo: "@nestia/fetcher", version: "latest" });
|
|
20
|
+
pack.install({ dev: true, modulo: "@nestia/sdk", version: "latest" });
|
|
21
|
+
pack.install({ dev: true, modulo: "nestia", version: "latest" });
|
|
22
|
+
pack.install({ dev: false, modulo: "typia" });
|
|
23
|
+
|
|
24
|
+
// INSTALL TYPESCRIPT COMPILERS
|
|
25
|
+
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
26
|
+
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
27
|
+
pack.install({ dev: true, modulo: "typescript", version: "5.5.2" });
|
|
28
|
+
args.project ??= (() => {
|
|
29
|
+
const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
|
|
30
|
+
CommandExecutor.run(`${runner} tsc --init`);
|
|
31
|
+
return (args.project = "tsconfig.json");
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
// SETUP TRANSFORMER
|
|
35
|
+
await pack.save((data) => {
|
|
36
|
+
// COMPOSE PREPARE COMMAND
|
|
37
|
+
data.scripts ??= {};
|
|
38
|
+
if (
|
|
39
|
+
typeof data.scripts.prepare === "string" &&
|
|
40
|
+
data.scripts.prepare.trim().length
|
|
41
|
+
) {
|
|
42
|
+
if (
|
|
43
|
+
data.scripts.prepare.indexOf("ts-patch install") === -1 &&
|
|
44
|
+
data.scripts.prepare.indexOf("typia patch") === -1
|
|
45
|
+
)
|
|
46
|
+
data.scripts.prepare =
|
|
47
|
+
"ts-patch install && typia patch && " + data.scripts.prepare;
|
|
48
|
+
else if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
49
|
+
data.scripts.prepare = "ts-patch install && " + data.scripts.prepare;
|
|
50
|
+
else if (data.scripts.prepare.indexOf("typia patch") === -1)
|
|
51
|
+
data.scripts.prepare = data.scripts.prepare.replace(
|
|
52
|
+
"ts-patch install",
|
|
53
|
+
"ts-patch install && typia patch",
|
|
54
|
+
);
|
|
55
|
+
} else data.scripts.prepare = "ts-patch install && typia patch";
|
|
56
|
+
|
|
57
|
+
// FOR OLDER VERSIONS
|
|
58
|
+
if (typeof data.scripts.postinstall === "string") {
|
|
59
|
+
data.scripts.postinstall = data.scripts.postinstall
|
|
60
|
+
.split("&&")
|
|
61
|
+
.map((str) => str.trim())
|
|
62
|
+
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
63
|
+
.join(" && ");
|
|
64
|
+
if (data.scripts.postinstall.length === 0)
|
|
65
|
+
delete data.scripts.postinstall;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
69
|
+
|
|
70
|
+
// CONFIGURE PLUGIN
|
|
71
|
+
await PluginConfigurator.configure(args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
|
|
3
|
-
export namespace CommandExecutor {
|
|
4
|
-
export function run(str: string): void {
|
|
5
|
-
console.log(`\n$ ${str}`);
|
|
6
|
-
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
-
}
|
|
8
|
-
}
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
|
|
3
|
+
export namespace CommandExecutor {
|
|
4
|
+
export function run(str: string): void {
|
|
5
|
+
console.log(`\n$ ${str}`);
|
|
6
|
+
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
export namespace FileRetriever {
|
|
5
|
-
export const directory =
|
|
6
|
-
(name: string) =>
|
|
7
|
-
(dir: string, depth: number = 0): string | null => {
|
|
8
|
-
const location: string = path.join(dir, name);
|
|
9
|
-
if (fs.existsSync(location)) return dir;
|
|
10
|
-
else if (depth > 2) return null;
|
|
11
|
-
return directory(name)(path.join(dir, ".."), depth + 1);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const file =
|
|
15
|
-
(name: string) =>
|
|
16
|
-
(directory: string, depth: number = 0): string | null => {
|
|
17
|
-
const location: string = path.join(directory, name);
|
|
18
|
-
if (fs.existsSync(location)) return location;
|
|
19
|
-
else if (depth > 2) return null;
|
|
20
|
-
return file(name)(path.join(directory, ".."), depth + 1);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export namespace FileRetriever {
|
|
5
|
+
export const directory =
|
|
6
|
+
(name: string) =>
|
|
7
|
+
(dir: string, depth: number = 0): string | null => {
|
|
8
|
+
const location: string = path.join(dir, name);
|
|
9
|
+
if (fs.existsSync(location)) return dir;
|
|
10
|
+
else if (depth > 2) return null;
|
|
11
|
+
return directory(name)(path.join(dir, ".."), depth + 1);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const file =
|
|
15
|
+
(name: string) =>
|
|
16
|
+
(directory: string, depth: number = 0): string | null => {
|
|
17
|
+
const location: string = path.join(directory, name);
|
|
18
|
+
if (fs.existsSync(location)) return location;
|
|
19
|
+
else if (depth > 2) return null;
|
|
20
|
+
return file(name)(path.join(directory, ".."), depth + 1);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
import { CommandExecutor } from "./CommandExecutor";
|
|
5
|
-
import { FileRetriever } from "./FileRetriever";
|
|
6
|
-
|
|
7
|
-
export class PackageManager {
|
|
8
|
-
public manager: string = "npm";
|
|
9
|
-
public get file(): string {
|
|
10
|
-
return path.join(this.directory, "package.json");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public static async mount(): Promise<PackageManager> {
|
|
14
|
-
const location: string | null = await FileRetriever.directory(
|
|
15
|
-
"package.json",
|
|
16
|
-
)(process.cwd());
|
|
17
|
-
if (location === null)
|
|
18
|
-
throw new Error(`Unable to find "package.json" file`);
|
|
19
|
-
|
|
20
|
-
return new PackageManager(
|
|
21
|
-
location,
|
|
22
|
-
await this.load(path.join(location, "package.json")),
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async save(modifier: (data: Package.Data) => void): Promise<void> {
|
|
27
|
-
const content: string = await fs.promises.readFile(this.file, "utf8");
|
|
28
|
-
this.data = JSON.parse(content);
|
|
29
|
-
modifier(this.data);
|
|
30
|
-
|
|
31
|
-
return fs.promises.writeFile(
|
|
32
|
-
this.file,
|
|
33
|
-
JSON.stringify(this.data, null, 2),
|
|
34
|
-
"utf8",
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public install(props: {
|
|
39
|
-
dev: boolean;
|
|
40
|
-
modulo: string;
|
|
41
|
-
version?: `latest` | `next` | `${number}.${number}.${number}`;
|
|
42
|
-
force?: boolean;
|
|
43
|
-
}): boolean {
|
|
44
|
-
const symbol: string =
|
|
45
|
-
this.manager === "yarn"
|
|
46
|
-
? `add${props.dev ? " -D" : ""}`
|
|
47
|
-
: `install ${props.dev ? "--save-dev" : "--save"}`;
|
|
48
|
-
CommandExecutor.run(
|
|
49
|
-
`${this.manager} ${symbol}${props.force === true ? " --force" : ""} ${
|
|
50
|
-
props.modulo
|
|
51
|
-
}${props.version ? `@${props.version}` : ""}`,
|
|
52
|
-
);
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private constructor(
|
|
57
|
-
public readonly directory: string,
|
|
58
|
-
public data: Package.Data,
|
|
59
|
-
) {}
|
|
60
|
-
|
|
61
|
-
private static async load(file: string): Promise<Package.Data> {
|
|
62
|
-
const content: string = await fs.promises.readFile(file, "utf8");
|
|
63
|
-
return JSON.parse(content);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export namespace Package {
|
|
67
|
-
export interface Data {
|
|
68
|
-
scripts?: Record<string, string>;
|
|
69
|
-
dependencies?: Record<string, string>;
|
|
70
|
-
devDependencies?: Record<string, string>;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import { CommandExecutor } from "./CommandExecutor";
|
|
5
|
+
import { FileRetriever } from "./FileRetriever";
|
|
6
|
+
|
|
7
|
+
export class PackageManager {
|
|
8
|
+
public manager: string = "npm";
|
|
9
|
+
public get file(): string {
|
|
10
|
+
return path.join(this.directory, "package.json");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public static async mount(): Promise<PackageManager> {
|
|
14
|
+
const location: string | null = await FileRetriever.directory(
|
|
15
|
+
"package.json",
|
|
16
|
+
)(process.cwd());
|
|
17
|
+
if (location === null)
|
|
18
|
+
throw new Error(`Unable to find "package.json" file`);
|
|
19
|
+
|
|
20
|
+
return new PackageManager(
|
|
21
|
+
location,
|
|
22
|
+
await this.load(path.join(location, "package.json")),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async save(modifier: (data: Package.Data) => void): Promise<void> {
|
|
27
|
+
const content: string = await fs.promises.readFile(this.file, "utf8");
|
|
28
|
+
this.data = JSON.parse(content);
|
|
29
|
+
modifier(this.data);
|
|
30
|
+
|
|
31
|
+
return fs.promises.writeFile(
|
|
32
|
+
this.file,
|
|
33
|
+
JSON.stringify(this.data, null, 2),
|
|
34
|
+
"utf8",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public install(props: {
|
|
39
|
+
dev: boolean;
|
|
40
|
+
modulo: string;
|
|
41
|
+
version?: `latest` | `next` | `${number}.${number}.${number}`;
|
|
42
|
+
force?: boolean;
|
|
43
|
+
}): boolean {
|
|
44
|
+
const symbol: string =
|
|
45
|
+
this.manager === "yarn"
|
|
46
|
+
? `add${props.dev ? " -D" : ""}`
|
|
47
|
+
: `install ${props.dev ? "--save-dev" : "--save"}`;
|
|
48
|
+
CommandExecutor.run(
|
|
49
|
+
`${this.manager} ${symbol}${props.force === true ? " --force" : ""} ${
|
|
50
|
+
props.modulo
|
|
51
|
+
}${props.version ? `@${props.version}` : ""}`,
|
|
52
|
+
);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private constructor(
|
|
57
|
+
public readonly directory: string,
|
|
58
|
+
public data: Package.Data,
|
|
59
|
+
) {}
|
|
60
|
+
|
|
61
|
+
private static async load(file: string): Promise<Package.Data> {
|
|
62
|
+
const content: string = await fs.promises.readFile(file, "utf8");
|
|
63
|
+
return JSON.parse(content);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export namespace Package {
|
|
67
|
+
export interface Data {
|
|
68
|
+
scripts?: Record<string, string>;
|
|
69
|
+
dependencies?: Record<string, string>;
|
|
70
|
+
devDependencies?: Record<string, string>;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import comments from "comment-json";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
import { ArgumentParser } from "./ArgumentParser";
|
|
5
|
-
|
|
6
|
-
export namespace PluginConfigurator {
|
|
7
|
-
export async function configure(
|
|
8
|
-
args: ArgumentParser.IArguments,
|
|
9
|
-
): Promise<void> {
|
|
10
|
-
// GET COMPILER-OPTIONS
|
|
11
|
-
const config: comments.CommentObject = comments.parse(
|
|
12
|
-
await fs.promises.readFile(args.project!, "utf8"),
|
|
13
|
-
) as comments.CommentObject;
|
|
14
|
-
const compilerOptions: comments.CommentObject | undefined =
|
|
15
|
-
config.compilerOptions as comments.CommentObject | undefined;
|
|
16
|
-
if (compilerOptions === undefined)
|
|
17
|
-
throw new Error(
|
|
18
|
-
`${args.project} file does not have "compilerOptions" property.`,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
// PREPARE PLUGINS
|
|
22
|
-
const plugins: comments.CommentArray<comments.CommentObject> = (() => {
|
|
23
|
-
const plugins = compilerOptions.plugins as
|
|
24
|
-
| comments.CommentArray<comments.CommentObject>
|
|
25
|
-
| undefined;
|
|
26
|
-
if (plugins === undefined) return (compilerOptions.plugins = [] as any);
|
|
27
|
-
else if (!Array.isArray(plugins))
|
|
28
|
-
throw new Error(
|
|
29
|
-
`"plugins" property of ${args.project} must be array type.`,
|
|
30
|
-
);
|
|
31
|
-
return plugins;
|
|
32
|
-
})();
|
|
33
|
-
|
|
34
|
-
// CHECK WHETHER CONFIGURED
|
|
35
|
-
const strict: boolean | undefined = compilerOptions.strict as
|
|
36
|
-
| boolean
|
|
37
|
-
| undefined;
|
|
38
|
-
const strictNullChecks: boolean | undefined =
|
|
39
|
-
compilerOptions.strictNullChecks as boolean | undefined;
|
|
40
|
-
const core: comments.CommentObject | undefined = plugins.find(
|
|
41
|
-
(p) =>
|
|
42
|
-
typeof p === "object" &&
|
|
43
|
-
p !== null &&
|
|
44
|
-
p.transform === "@nestia/core/lib/transform",
|
|
45
|
-
);
|
|
46
|
-
const typia: comments.CommentObject | undefined = plugins.find(
|
|
47
|
-
(p) =>
|
|
48
|
-
typeof p === "object" &&
|
|
49
|
-
p !== null &&
|
|
50
|
-
p.transform === "typia/lib/transform",
|
|
51
|
-
);
|
|
52
|
-
if (
|
|
53
|
-
strictNullChecks !== false &&
|
|
54
|
-
(strict === true || strictNullChecks === true) &&
|
|
55
|
-
core !== undefined &&
|
|
56
|
-
typia !== undefined
|
|
57
|
-
)
|
|
58
|
-
return;
|
|
59
|
-
|
|
60
|
-
// DO CONFIGURE
|
|
61
|
-
compilerOptions.strictNullChecks = true;
|
|
62
|
-
if (strict === undefined && strictNullChecks === undefined)
|
|
63
|
-
compilerOptions.strict = true;
|
|
64
|
-
compilerOptions.experimentalDecorators = true;
|
|
65
|
-
compilerOptions.emitDecoratorMetadata = true;
|
|
66
|
-
|
|
67
|
-
if (core === undefined)
|
|
68
|
-
plugins.push(
|
|
69
|
-
comments.parse(`{
|
|
70
|
-
"transform": "@nestia/core/lib/transform",
|
|
71
|
-
/**
|
|
72
|
-
* Validate request body.
|
|
73
|
-
*
|
|
74
|
-
* - "assert": Use typia.assert() function
|
|
75
|
-
* - "is": Use typia.is() function
|
|
76
|
-
* - "validate": Use typia.validate() function
|
|
77
|
-
* - "assertEquals": Use typia.assertEquals() function
|
|
78
|
-
* - "equals": Use typia.equals() function
|
|
79
|
-
* - "validateEquals": Use typia.validateEquals() function
|
|
80
|
-
*/
|
|
81
|
-
"validate": "assert",
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Validate JSON typed response body.
|
|
85
|
-
*
|
|
86
|
-
* - "assert": Use typia.assertStringify() function
|
|
87
|
-
* - "is": Use typia.isStringify() function
|
|
88
|
-
* - "validate": Use typia.validateStringify() function
|
|
89
|
-
* - "stringify": Use typia.stringify() function, but dangerous
|
|
90
|
-
* - null: Just use JSON.stringify() function, without boosting
|
|
91
|
-
*/
|
|
92
|
-
"stringify": "assert"
|
|
93
|
-
}`) as comments.CommentObject,
|
|
94
|
-
);
|
|
95
|
-
if (typia === undefined)
|
|
96
|
-
plugins.push(
|
|
97
|
-
comments.parse(
|
|
98
|
-
`{ "transform": "typia/lib/transform" }`,
|
|
99
|
-
) as comments.CommentObject,
|
|
100
|
-
);
|
|
101
|
-
await fs.promises.writeFile(
|
|
102
|
-
args.project!,
|
|
103
|
-
comments.stringify(config, null, 2),
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
import comments from "comment-json";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
import { ArgumentParser } from "./ArgumentParser";
|
|
5
|
+
|
|
6
|
+
export namespace PluginConfigurator {
|
|
7
|
+
export async function configure(
|
|
8
|
+
args: ArgumentParser.IArguments,
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
// GET COMPILER-OPTIONS
|
|
11
|
+
const config: comments.CommentObject = comments.parse(
|
|
12
|
+
await fs.promises.readFile(args.project!, "utf8"),
|
|
13
|
+
) as comments.CommentObject;
|
|
14
|
+
const compilerOptions: comments.CommentObject | undefined =
|
|
15
|
+
config.compilerOptions as comments.CommentObject | undefined;
|
|
16
|
+
if (compilerOptions === undefined)
|
|
17
|
+
throw new Error(
|
|
18
|
+
`${args.project} file does not have "compilerOptions" property.`,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// PREPARE PLUGINS
|
|
22
|
+
const plugins: comments.CommentArray<comments.CommentObject> = (() => {
|
|
23
|
+
const plugins = compilerOptions.plugins as
|
|
24
|
+
| comments.CommentArray<comments.CommentObject>
|
|
25
|
+
| undefined;
|
|
26
|
+
if (plugins === undefined) return (compilerOptions.plugins = [] as any);
|
|
27
|
+
else if (!Array.isArray(plugins))
|
|
28
|
+
throw new Error(
|
|
29
|
+
`"plugins" property of ${args.project} must be array type.`,
|
|
30
|
+
);
|
|
31
|
+
return plugins;
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
// CHECK WHETHER CONFIGURED
|
|
35
|
+
const strict: boolean | undefined = compilerOptions.strict as
|
|
36
|
+
| boolean
|
|
37
|
+
| undefined;
|
|
38
|
+
const strictNullChecks: boolean | undefined =
|
|
39
|
+
compilerOptions.strictNullChecks as boolean | undefined;
|
|
40
|
+
const core: comments.CommentObject | undefined = plugins.find(
|
|
41
|
+
(p) =>
|
|
42
|
+
typeof p === "object" &&
|
|
43
|
+
p !== null &&
|
|
44
|
+
p.transform === "@nestia/core/lib/transform",
|
|
45
|
+
);
|
|
46
|
+
const typia: comments.CommentObject | undefined = plugins.find(
|
|
47
|
+
(p) =>
|
|
48
|
+
typeof p === "object" &&
|
|
49
|
+
p !== null &&
|
|
50
|
+
p.transform === "typia/lib/transform",
|
|
51
|
+
);
|
|
52
|
+
if (
|
|
53
|
+
strictNullChecks !== false &&
|
|
54
|
+
(strict === true || strictNullChecks === true) &&
|
|
55
|
+
core !== undefined &&
|
|
56
|
+
typia !== undefined
|
|
57
|
+
)
|
|
58
|
+
return;
|
|
59
|
+
|
|
60
|
+
// DO CONFIGURE
|
|
61
|
+
compilerOptions.strictNullChecks = true;
|
|
62
|
+
if (strict === undefined && strictNullChecks === undefined)
|
|
63
|
+
compilerOptions.strict = true;
|
|
64
|
+
compilerOptions.experimentalDecorators = true;
|
|
65
|
+
compilerOptions.emitDecoratorMetadata = true;
|
|
66
|
+
|
|
67
|
+
if (core === undefined)
|
|
68
|
+
plugins.push(
|
|
69
|
+
comments.parse(`{
|
|
70
|
+
"transform": "@nestia/core/lib/transform",
|
|
71
|
+
/**
|
|
72
|
+
* Validate request body.
|
|
73
|
+
*
|
|
74
|
+
* - "assert": Use typia.assert() function
|
|
75
|
+
* - "is": Use typia.is() function
|
|
76
|
+
* - "validate": Use typia.validate() function
|
|
77
|
+
* - "assertEquals": Use typia.assertEquals() function
|
|
78
|
+
* - "equals": Use typia.equals() function
|
|
79
|
+
* - "validateEquals": Use typia.validateEquals() function
|
|
80
|
+
*/
|
|
81
|
+
"validate": "assert",
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validate JSON typed response body.
|
|
85
|
+
*
|
|
86
|
+
* - "assert": Use typia.assertStringify() function
|
|
87
|
+
* - "is": Use typia.isStringify() function
|
|
88
|
+
* - "validate": Use typia.validateStringify() function
|
|
89
|
+
* - "stringify": Use typia.stringify() function, but dangerous
|
|
90
|
+
* - null: Just use JSON.stringify() function, without boosting
|
|
91
|
+
*/
|
|
92
|
+
"stringify": "assert"
|
|
93
|
+
}`) as comments.CommentObject,
|
|
94
|
+
);
|
|
95
|
+
if (typia === undefined)
|
|
96
|
+
plugins.push(
|
|
97
|
+
comments.parse(
|
|
98
|
+
`{ "transform": "typia/lib/transform" }`,
|
|
99
|
+
) as comments.CommentObject,
|
|
100
|
+
);
|
|
101
|
+
await fs.promises.writeFile(
|
|
102
|
+
args.project!,
|
|
103
|
+
comments.stringify(config, null, 2),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|