@nestia/core 1.0.18 → 1.0.19

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.
@@ -1,92 +0,0 @@
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
- silent?: boolean;
41
- modulo: string;
42
- version?: string;
43
- }): boolean {
44
- const container = props.dev
45
- ? this.data.devDependencies
46
- : this.data.dependencies;
47
- if (
48
- !!container?.[props.modulo] &&
49
- FileRetriever.file(path.join("node_modules", props.modulo))(
50
- this.directory,
51
- ) !== null
52
- )
53
- return false;
54
-
55
- const middle: string =
56
- this.manager === "yarn"
57
- ? `add${props.dev ? " -D" : ""}`
58
- : `install ${props.dev ? "--save-dev" : "--save"}`;
59
- CommandExecutor.run(
60
- `${this.manager} ${middle} ${props.modulo}${
61
- props.version ? `@${props.version}` : ""
62
- }`,
63
- !!props.silent,
64
- );
65
- return true;
66
- }
67
-
68
- public erase(props: { modulo: string; silent?: boolean }): void {
69
- const middle: string = this.manager === "yarn" ? "remove" : "uninstall";
70
- CommandExecutor.run(
71
- `${this.manager} ${middle} ${props.modulo}`,
72
- !!props.silent,
73
- );
74
- }
75
-
76
- private constructor(
77
- public readonly directory: string,
78
- public data: Package.Data,
79
- ) {}
80
-
81
- private static async load(file: string): Promise<Package.Data> {
82
- const content: string = await fs.promises.readFile(file, "utf8");
83
- return JSON.parse(content);
84
- }
85
- }
86
- export namespace Package {
87
- export interface Data {
88
- scripts?: Record<string, string>;
89
- dependencies?: Record<string, string>;
90
- devDependencies?: Record<string, string>;
91
- }
92
- }
@@ -1,130 +0,0 @@
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 { FileRetriever } from "./FileRetriever";
7
- import { PackageManager } from "./PackageManager";
8
-
9
- export namespace PluginConfigurator {
10
- export async function configure(
11
- pack: PackageManager,
12
- args: ArgumentParser.IArguments,
13
- ): Promise<void> {
14
- // INSTALL COMMENT-JSON
15
- const installed: boolean = pack.install({
16
- dev: true,
17
- modulo: "comment-json",
18
- version: "4.2.3",
19
- silent: true,
20
- });
21
-
22
- // DO CONFIGURE
23
- const error: Error | null = await (async () => {
24
- try {
25
- await _Configure(pack, args);
26
- return null;
27
- } catch (exp) {
28
- return exp as Error;
29
- }
30
- })();
31
-
32
- // REMOVE IT
33
- if (installed)
34
- pack.erase({
35
- modulo: "comment-json",
36
- silent: true,
37
- });
38
- if (error !== null) throw error;
39
- }
40
-
41
- async function _Configure(
42
- pack: PackageManager,
43
- args: ArgumentParser.IArguments,
44
- ): Promise<void> {
45
- // GET COMPILER-OPTIONS
46
- const Comment: typeof import("comment-json") =
47
- await FileRetriever.require(
48
- path.join("node_modules", "comment-json"),
49
- )(pack.directory);
50
-
51
- const config: Comment.CommentObject = Comment.parse(
52
- await fs.promises.readFile(args.project!, "utf8"),
53
- ) as Comment.CommentObject;
54
- const compilerOptions = config.compilerOptions as
55
- | Comment.CommentObject
56
- | undefined;
57
- if (compilerOptions === undefined)
58
- throw new Error(
59
- `${args.project} file does not have "compilerOptions" property.`,
60
- );
61
-
62
- // PREPARE PLUGINS
63
- const plugins: Comment.CommentArray<Comment.CommentObject> = (() => {
64
- const plugins = compilerOptions.plugins as
65
- | Comment.CommentArray<Comment.CommentObject>
66
- | undefined;
67
- if (plugins === undefined)
68
- return (compilerOptions.plugins = [] as any);
69
- else if (!Array.isArray(plugins))
70
- throw new Error(
71
- `"plugins" property of ${args.project} must be array type.`,
72
- );
73
- return plugins;
74
- })();
75
-
76
- // CHECK WHETHER CONFIGURED
77
- const strict: boolean = compilerOptions.strict === true;
78
- const core: Comment.CommentObject | undefined = plugins.find(
79
- (p) =>
80
- typeof p === "object" &&
81
- p !== null &&
82
- p.transform === "@nestia/core/lib/transform",
83
- );
84
- const typia: Comment.CommentObject | undefined = plugins.find(
85
- (p) =>
86
- typeof p === "object" &&
87
- p !== null &&
88
- p.transform === "typia/lib/transform",
89
- );
90
- if (strict && !!core && !!typia) return;
91
-
92
- // DO CONFIGURE
93
- compilerOptions.strict = true;
94
- if (core === undefined)
95
- plugins.push(
96
- Comment.parse(`{
97
- "transform": "@nestia/core/lib/transform",
98
- /**
99
- * Validate request body.
100
- *
101
- * - "assert": Use typia.assert() function
102
- * - "is": Use typia.is() function
103
- * - "validate": Use typia.validate() function
104
- */
105
- "validate": "assert",
106
-
107
- /**
108
- * Validate JSON typed response body.
109
- *
110
- * - "assert": Use typia.assertStringify() function
111
- * - "is": Use typia.isStringify() function
112
- * - "validate": Use typia.validateStringify() function
113
- * - "stringify": Use typia.stringify() function, but dangerous
114
- * - null: Just use JSON.stringify() function, without boosting
115
- */
116
- "stringify": "assert"
117
- }`) as Comment.CommentObject,
118
- );
119
- if (typia === undefined)
120
- plugins.push(
121
- Comment.parse(
122
- `{ "transform": "typia/lib/transform" }`,
123
- ) as Comment.CommentObject,
124
- );
125
- await fs.promises.writeFile(
126
- args.project!,
127
- Comment.stringify(config, null, 2),
128
- );
129
- }
130
- }