nestia 11.0.0-dev.20260313-4 → 11.0.0-dev.20260316

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.
@@ -61,31 +61,31 @@ var PluginConfigurator;
61
61
  compilerOptions.experimentalDecorators = true;
62
62
  compilerOptions.emitDecoratorMetadata = true;
63
63
  if (core === undefined)
64
- plugins.push(comment_json_1.default.parse(`{
65
- "transform": "@nestia/core/lib/transform",
66
- /**
67
- * Validate request body.
68
- *
69
- * - "assert": Use typia.assert() function
70
- * - "is": Use typia.is() function
71
- * - "validate": Use typia.validate() function
72
- * - "assertEquals": Use typia.assertEquals() function
73
- * - "equals": Use typia.equals() function
74
- * - "validateEquals": Use typia.validateEquals() function
75
- */
76
- "validate": "validate",
77
-
78
- /**
79
- * Validate JSON typed response body.
80
- *
81
- * - "assert": Use typia.assertStringify() function
82
- * - "is": Use typia.isStringify() function
83
- * - "validate": Use typia.validateStringify() function
84
- * - "validate.log": typia.validateStringify(), but do not throw and just log it
85
- * - "stringify": Use typia.stringify() function, but dangerous
86
- * - null: Just use JSON.stringify() function, without boosting
87
- */
88
- "stringify": "assert"
64
+ plugins.push(comment_json_1.default.parse(`{
65
+ "transform": "@nestia/core/lib/transform",
66
+ /**
67
+ * Validate request body.
68
+ *
69
+ * - "assert": Use typia.assert() function
70
+ * - "is": Use typia.is() function
71
+ * - "validate": Use typia.validate() function
72
+ * - "assertEquals": Use typia.assertEquals() function
73
+ * - "equals": Use typia.equals() function
74
+ * - "validateEquals": Use typia.validateEquals() function
75
+ */
76
+ "validate": "validate",
77
+
78
+ /**
79
+ * Validate JSON typed response body.
80
+ *
81
+ * - "assert": Use typia.assertStringify() function
82
+ * - "is": Use typia.isStringify() function
83
+ * - "validate": Use typia.validateStringify() function
84
+ * - "validate.log": typia.validateStringify(), but do not throw and just log it
85
+ * - "stringify": Use typia.stringify() function, but dangerous
86
+ * - null: Just use JSON.stringify() function, without boosting
87
+ */
88
+ "stringify": "assert"
89
89
  }`));
90
90
  if (swagger === undefined && args.runtime === true)
91
91
  plugins.push(comment_json_1.default.parse(`{ "transform": "@nestia/sdk/lib/transform" }`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "11.0.0-dev.20260313-4",
3
+ "version": "11.0.0-dev.20260316",
4
4
  "description": "Nestia CLI tool",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -44,8 +44,8 @@
44
44
  "rimraf": "^6.1.3",
45
45
  "ts-node": "^10.9.2",
46
46
  "typescript": "~5.9.3",
47
- "@nestia/sdk": "^11.0.0-dev.20260313-4",
48
- "@nestia/core": "^11.0.0-dev.20260313-4"
47
+ "@nestia/core": "^11.0.0-dev.20260316",
48
+ "@nestia/sdk": "^11.0.0-dev.20260316"
49
49
  },
50
50
  "files": [
51
51
  "bin",
@@ -1,90 +1,90 @@
1
- import fs from "fs";
2
-
3
- import { ArgumentParser } from "./internal/ArgumentParser";
4
- import { CommandExecutor } from "./internal/CommandExecutor";
5
- import { PackageManager } from "./internal/PackageManager";
6
- import { PluginConfigurator } from "./internal/PluginConfigurator";
7
-
8
- export namespace NestiaSetupWizard {
9
- export async function setup(): Promise<void> {
10
- console.log("----------------------------------------");
11
- console.log(" Nestia Setup Wizard");
12
- console.log("----------------------------------------");
13
-
14
- // PREPARE ASSETS
15
- const pack: PackageManager = await PackageManager.mount();
16
- const args: ArgumentParser.IArguments = await ArgumentParser.parse(pack);
17
-
18
- // INSTALL NESTIA
19
- pack.install({ dev: false, modulo: "@nestia/core", version: "latest" });
20
- pack.install({ dev: false, modulo: "@nestia/e2e", version: "latest" });
21
- pack.install({ dev: false, modulo: "@nestia/fetcher", version: "latest" });
22
- pack.install({
23
- dev: args.runtime === false,
24
- modulo: "@nestia/sdk",
25
- version: "latest",
26
- });
27
- pack.install({ dev: true, modulo: "@nestia/benchmark", version: "latest" });
28
- pack.install({ dev: true, modulo: "nestia", version: "latest" });
29
- pack.install({ dev: false, modulo: "typia", version: "latest" });
30
-
31
- // INSTALL TYPESCRIPT COMPILERS
32
- pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
33
- pack.install({ dev: true, modulo: "ts-node", version: "latest" });
34
- pack.install({
35
- dev: true,
36
- modulo: "typescript",
37
- version: await getTypeScriptVersion(),
38
- });
39
- args.project ??= (() => {
40
- const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
41
- CommandExecutor.run(`${runner} tsc --init`);
42
- return (args.project = "tsconfig.json");
43
- })();
44
-
45
- // SETUP TRANSFORMER
46
- await pack.save((data) => {
47
- // COMPOSE PREPARE COMMAND
48
- data.scripts ??= {};
49
- if (
50
- typeof data.scripts.prepare === "string" &&
51
- data.scripts.prepare.trim().length !== 0
52
- ) {
53
- if (data.scripts.prepare.includes("ts-patch install") === false)
54
- data.scripts.prepare = "ts-patch install && " + data.scripts.prepare;
55
- } else data.scripts.prepare = "ts-patch install";
56
-
57
- // NO MORE "typia patch" REQUIRED
58
- data.scripts.prepare = data.scripts.prepare
59
- .split("&&")
60
- .map((str) => str.trim())
61
- .filter((str) => str !== "typia patch")
62
- .join(" && ");
63
-
64
- // FOR OLDER VERSIONS
65
- if (typeof data.scripts.postinstall === "string") {
66
- data.scripts.postinstall = data.scripts.postinstall
67
- .split("&&")
68
- .map((str) => str.trim())
69
- .filter((str) => str.indexOf("ts-patch install") === -1)
70
- .join(" && ");
71
- if (data.scripts.postinstall.length === 0)
72
- delete data.scripts.postinstall;
73
- }
74
- });
75
- CommandExecutor.run(`${pack.manager} run prepare`);
76
-
77
- // CONFIGURE PLUGIN
78
- await PluginConfigurator.configure(args);
79
- }
80
-
81
- const getTypeScriptVersion = async (): Promise<string> => {
82
- const content: string = await fs.promises.readFile(
83
- `${__dirname}/../package.json`,
84
- "utf-8",
85
- );
86
- const json: { devDependencies: { typescript: string } } =
87
- JSON.parse(content);
88
- return json.devDependencies.typescript;
89
- };
90
- }
1
+ import fs from "fs";
2
+
3
+ import { ArgumentParser } from "./internal/ArgumentParser";
4
+ import { CommandExecutor } from "./internal/CommandExecutor";
5
+ import { PackageManager } from "./internal/PackageManager";
6
+ import { PluginConfigurator } from "./internal/PluginConfigurator";
7
+
8
+ export namespace NestiaSetupWizard {
9
+ export async function setup(): Promise<void> {
10
+ console.log("----------------------------------------");
11
+ console.log(" Nestia Setup Wizard");
12
+ console.log("----------------------------------------");
13
+
14
+ // PREPARE ASSETS
15
+ const pack: PackageManager = await PackageManager.mount();
16
+ const args: ArgumentParser.IArguments = await ArgumentParser.parse(pack);
17
+
18
+ // INSTALL NESTIA
19
+ pack.install({ dev: false, modulo: "@nestia/core", version: "latest" });
20
+ pack.install({ dev: false, modulo: "@nestia/e2e", version: "latest" });
21
+ pack.install({ dev: false, modulo: "@nestia/fetcher", version: "latest" });
22
+ pack.install({
23
+ dev: args.runtime === false,
24
+ modulo: "@nestia/sdk",
25
+ version: "latest",
26
+ });
27
+ pack.install({ dev: true, modulo: "@nestia/benchmark", version: "latest" });
28
+ pack.install({ dev: true, modulo: "nestia", version: "latest" });
29
+ pack.install({ dev: false, modulo: "typia", version: "latest" });
30
+
31
+ // INSTALL TYPESCRIPT COMPILERS
32
+ pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
33
+ pack.install({ dev: true, modulo: "ts-node", version: "latest" });
34
+ pack.install({
35
+ dev: true,
36
+ modulo: "typescript",
37
+ version: await getTypeScriptVersion(),
38
+ });
39
+ args.project ??= (() => {
40
+ const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
41
+ CommandExecutor.run(`${runner} tsc --init`);
42
+ return (args.project = "tsconfig.json");
43
+ })();
44
+
45
+ // SETUP TRANSFORMER
46
+ await pack.save((data) => {
47
+ // COMPOSE PREPARE COMMAND
48
+ data.scripts ??= {};
49
+ if (
50
+ typeof data.scripts.prepare === "string" &&
51
+ data.scripts.prepare.trim().length !== 0
52
+ ) {
53
+ if (data.scripts.prepare.includes("ts-patch install") === false)
54
+ data.scripts.prepare = "ts-patch install && " + data.scripts.prepare;
55
+ } else data.scripts.prepare = "ts-patch install";
56
+
57
+ // NO MORE "typia patch" REQUIRED
58
+ data.scripts.prepare = data.scripts.prepare
59
+ .split("&&")
60
+ .map((str) => str.trim())
61
+ .filter((str) => str !== "typia patch")
62
+ .join(" && ");
63
+
64
+ // FOR OLDER VERSIONS
65
+ if (typeof data.scripts.postinstall === "string") {
66
+ data.scripts.postinstall = data.scripts.postinstall
67
+ .split("&&")
68
+ .map((str) => str.trim())
69
+ .filter((str) => str.indexOf("ts-patch install") === -1)
70
+ .join(" && ");
71
+ if (data.scripts.postinstall.length === 0)
72
+ delete data.scripts.postinstall;
73
+ }
74
+ });
75
+ CommandExecutor.run(`${pack.manager} run prepare`);
76
+
77
+ // CONFIGURE PLUGIN
78
+ await PluginConfigurator.configure(args);
79
+ }
80
+
81
+ const getTypeScriptVersion = async (): Promise<string> => {
82
+ const content: string = await fs.promises.readFile(
83
+ `${__dirname}/../package.json`,
84
+ "utf-8",
85
+ );
86
+ const json: { devDependencies: { typescript: string } } =
87
+ JSON.parse(content);
88
+ return json.devDependencies.typescript;
89
+ };
90
+ }
@@ -1,41 +1,41 @@
1
- import cp from "child_process";
2
- import fs from "fs";
3
-
4
- export namespace NestiaStarter {
5
- export const clone =
6
- (halter: (msg?: string) => never) =>
7
- async (argv: string[]): Promise<void> => {
8
- // VALIDATION
9
- const dest: string | undefined = argv[0];
10
- if (dest === undefined) halter();
11
- else if (fs.existsSync(dest) === true)
12
- halter("The target directory already exists.");
13
-
14
- console.log("-----------------------------------------");
15
- console.log(" Nestia Starter Kit");
16
- console.log("-----------------------------------------");
17
-
18
- // COPY PROJECTS
19
- execute(`git clone https://github.com/samchon/nestia-template ${dest}`);
20
- console.log(`cd "${dest}"`);
21
- process.chdir(dest);
22
-
23
- // INSTALL DEPENDENCIES
24
- execute("npm install");
25
-
26
- // BUILD TYPESCRIPT
27
- execute("npm run build");
28
-
29
- // DO TEST
30
- execute("npm run test");
31
-
32
- // REMOVE .GIT DIRECTORY
33
- cp.execSync("npx rimraf .git");
34
- cp.execSync("npx rimraf .github/dependabot.yml");
35
- };
36
-
37
- function execute(command: string): void {
38
- console.log(`\n$ ${command}`);
39
- cp.execSync(command, { stdio: "inherit" });
40
- }
41
- }
1
+ import cp from "child_process";
2
+ import fs from "fs";
3
+
4
+ export namespace NestiaStarter {
5
+ export const clone =
6
+ (halter: (msg?: string) => never) =>
7
+ async (argv: string[]): Promise<void> => {
8
+ // VALIDATION
9
+ const dest: string | undefined = argv[0];
10
+ if (dest === undefined) halter();
11
+ else if (fs.existsSync(dest) === true)
12
+ halter("The target directory already exists.");
13
+
14
+ console.log("-----------------------------------------");
15
+ console.log(" Nestia Starter Kit");
16
+ console.log("-----------------------------------------");
17
+
18
+ // COPY PROJECTS
19
+ execute(`git clone https://github.com/samchon/nestia-template ${dest}`);
20
+ console.log(`cd "${dest}"`);
21
+ process.chdir(dest);
22
+
23
+ // INSTALL DEPENDENCIES
24
+ execute("npm install");
25
+
26
+ // BUILD TYPESCRIPT
27
+ execute("npm run build");
28
+
29
+ // DO TEST
30
+ execute("npm run test");
31
+
32
+ // REMOVE .GIT DIRECTORY
33
+ cp.execSync("npx rimraf .git");
34
+ cp.execSync("npx rimraf .github/dependabot.yml");
35
+ };
36
+
37
+ function execute(command: string): void {
38
+ console.log(`\n$ ${command}`);
39
+ cp.execSync(command, { stdio: "inherit" });
40
+ }
41
+ }
@@ -1,37 +1,37 @@
1
- import cp from "child_process";
2
- import fs from "fs";
3
-
4
- export namespace NestiaTemplate {
5
- export const clone =
6
- (halter: (msg?: string) => never) =>
7
- async (argv: string[]): Promise<void> => {
8
- // VALIDATION
9
- const dest: string | undefined = argv[0];
10
- if (dest === undefined) halter();
11
- else if (fs.existsSync(dest) === true)
12
- halter("The target directory already exists.");
13
-
14
- console.log("-----------------------------------------");
15
- console.log(" Nestia Template Kit");
16
- console.log("-----------------------------------------");
17
-
18
- // COPY PROJECTS
19
- execute(`git clone https://github.com/samchon/backend ${dest}`);
20
- console.log(`cd "${dest}"`);
21
- process.chdir(dest);
22
-
23
- // INSTALL DEPENDENCIES
24
- execute("npm install");
25
-
26
- // BUILD TYPESCRIPT
27
- execute("npm run build");
28
-
29
- // REMOVE .GIT DIRECTORY
30
- cp.execSync("npx rimraf .git");
31
- };
32
-
33
- function execute(command: string): void {
34
- console.log(`\n$ ${command}`);
35
- cp.execSync(command, { stdio: "inherit" });
36
- }
37
- }
1
+ import cp from "child_process";
2
+ import fs from "fs";
3
+
4
+ export namespace NestiaTemplate {
5
+ export const clone =
6
+ (halter: (msg?: string) => never) =>
7
+ async (argv: string[]): Promise<void> => {
8
+ // VALIDATION
9
+ const dest: string | undefined = argv[0];
10
+ if (dest === undefined) halter();
11
+ else if (fs.existsSync(dest) === true)
12
+ halter("The target directory already exists.");
13
+
14
+ console.log("-----------------------------------------");
15
+ console.log(" Nestia Template Kit");
16
+ console.log("-----------------------------------------");
17
+
18
+ // COPY PROJECTS
19
+ execute(`git clone https://github.com/samchon/backend ${dest}`);
20
+ console.log(`cd "${dest}"`);
21
+ process.chdir(dest);
22
+
23
+ // INSTALL DEPENDENCIES
24
+ execute("npm install");
25
+
26
+ // BUILD TYPESCRIPT
27
+ execute("npm run build");
28
+
29
+ // REMOVE .GIT DIRECTORY
30
+ cp.execSync("npx rimraf .git");
31
+ };
32
+
33
+ function execute(command: string): void {
34
+ console.log(`\n$ ${command}`);
35
+ cp.execSync(command, { stdio: "inherit" });
36
+ }
37
+ }
@@ -1,123 +1,123 @@
1
- import commander from "commander";
2
- import fs from "fs";
3
- import inquirer from "inquirer";
4
- import { DetectResult, detect } from "package-manager-detector";
5
-
6
- import { PackageManager } from "./PackageManager";
7
-
8
- export namespace ArgumentParser {
9
- export interface IArguments {
10
- manager: "npm" | "pnpm" | "yarn" | "bun";
11
- project: string | null;
12
- runtime: boolean;
13
- }
14
-
15
- export async function parse(pack: PackageManager): Promise<IArguments> {
16
- // PREPARE ASSETS
17
- commander.program.option("--manager [manager]", "package manager");
18
- commander.program.option(
19
- "--project [project]",
20
- "tsconfig.json file location",
21
- );
22
- commander.program.option(
23
- "--runtime [boolean]",
24
- "transform runtime swagger",
25
- );
26
-
27
- // INTERNAL PROCEDURES
28
- const questioned = { value: false };
29
- const action = (
30
- closure: (options: Partial<IArguments>) => Promise<IArguments>,
31
- ) => {
32
- return new Promise<IArguments>((resolve, reject) => {
33
- commander.program.action(async (options) => {
34
- try {
35
- resolve(await closure(options));
36
- } catch (exp) {
37
- reject(exp);
38
- }
39
- });
40
- commander.program.parseAsync().catch(reject);
41
- });
42
- };
43
- const select =
44
- (name: string) =>
45
- (message: string) =>
46
- async <Choice extends string>(
47
- choices: Choice[],
48
- filter?: (value: string) => Choice,
49
- ): Promise<Choice> => {
50
- questioned.value = true;
51
- return (
52
- await inquirer.createPromptModule()({
53
- type: "list",
54
- name: name,
55
- message: message,
56
- choices: choices,
57
- filter,
58
- })
59
- )[name];
60
- };
61
- const configure = async () => {
62
- const fileList: string[] = await (
63
- await fs.promises.readdir(process.cwd())
64
- )
65
- .filter(
66
- (str) =>
67
- str.substring(0, 8) === "tsconfig" &&
68
- str.substring(str.length - 5) === ".json",
69
- )
70
- .sort((x, y) =>
71
- x === "tsconfig.json"
72
- ? -1
73
- : y === "tsconfig.json"
74
- ? 1
75
- : x < y
76
- ? -1
77
- : 1,
78
- );
79
- if (fileList.length === 0) {
80
- if (process.cwd() !== pack.directory)
81
- throw new Error(`Unable to find "tsconfig.json" file.`);
82
- return null;
83
- } else if (fileList.length === 1) return fileList[0];
84
- return select("tsconfig")("TS Config File")(fileList);
85
- };
86
-
87
- // DO CONSTRUCT
88
- return action(async (options) => {
89
- options.manager ??=
90
- (await detectManager()) ??
91
- (await select("manager")("Package Manager")(
92
- [
93
- "npm" as const,
94
- "pnpm" as const,
95
- "yarn (berry is not supported)" as "yarn",
96
- "bun" as const,
97
- ],
98
- (value) => value.split(" ")[0] as "yarn",
99
- ));
100
- pack.manager = options.manager;
101
- options.project ??= await configure();
102
- options.runtime =
103
- ((options.runtime as string | undefined) ??
104
- (await select("runtime")("Transform Runtime Swagger")([
105
- "true",
106
- "false",
107
- ]))) !== "false";
108
-
109
- if (questioned.value) console.log("");
110
- return options as IArguments;
111
- });
112
- }
113
-
114
- const detectManager = async (): Promise<
115
- "npm" | "pnpm" | "yarn" | "bun" | null
116
- > => {
117
- const result: DetectResult | null = await detect({ cwd: process.cwd() });
118
- if (result?.name === "npm")
119
- return null; // NPM case is still selectable
120
- else if (result?.name === "deno") return null; // Deno case is not supported
121
- return result?.name ?? null;
122
- };
123
- }
1
+ import commander from "commander";
2
+ import fs from "fs";
3
+ import inquirer from "inquirer";
4
+ import { DetectResult, detect } from "package-manager-detector";
5
+
6
+ import { PackageManager } from "./PackageManager";
7
+
8
+ export namespace ArgumentParser {
9
+ export interface IArguments {
10
+ manager: "npm" | "pnpm" | "yarn" | "bun";
11
+ project: string | null;
12
+ runtime: boolean;
13
+ }
14
+
15
+ export async function parse(pack: PackageManager): Promise<IArguments> {
16
+ // PREPARE ASSETS
17
+ commander.program.option("--manager [manager]", "package manager");
18
+ commander.program.option(
19
+ "--project [project]",
20
+ "tsconfig.json file location",
21
+ );
22
+ commander.program.option(
23
+ "--runtime [boolean]",
24
+ "transform runtime swagger",
25
+ );
26
+
27
+ // INTERNAL PROCEDURES
28
+ const questioned = { value: false };
29
+ const action = (
30
+ closure: (options: Partial<IArguments>) => Promise<IArguments>,
31
+ ) => {
32
+ return new Promise<IArguments>((resolve, reject) => {
33
+ commander.program.action(async (options) => {
34
+ try {
35
+ resolve(await closure(options));
36
+ } catch (exp) {
37
+ reject(exp);
38
+ }
39
+ });
40
+ commander.program.parseAsync().catch(reject);
41
+ });
42
+ };
43
+ const select =
44
+ (name: string) =>
45
+ (message: string) =>
46
+ async <Choice extends string>(
47
+ choices: Choice[],
48
+ filter?: (value: string) => Choice,
49
+ ): Promise<Choice> => {
50
+ questioned.value = true;
51
+ return (
52
+ await inquirer.createPromptModule()({
53
+ type: "list",
54
+ name: name,
55
+ message: message,
56
+ choices: choices,
57
+ filter,
58
+ })
59
+ )[name];
60
+ };
61
+ const configure = async () => {
62
+ const fileList: string[] = await (
63
+ await fs.promises.readdir(process.cwd())
64
+ )
65
+ .filter(
66
+ (str) =>
67
+ str.substring(0, 8) === "tsconfig" &&
68
+ str.substring(str.length - 5) === ".json",
69
+ )
70
+ .sort((x, y) =>
71
+ x === "tsconfig.json"
72
+ ? -1
73
+ : y === "tsconfig.json"
74
+ ? 1
75
+ : x < y
76
+ ? -1
77
+ : 1,
78
+ );
79
+ if (fileList.length === 0) {
80
+ if (process.cwd() !== pack.directory)
81
+ throw new Error(`Unable to find "tsconfig.json" file.`);
82
+ return null;
83
+ } else if (fileList.length === 1) return fileList[0];
84
+ return select("tsconfig")("TS Config File")(fileList);
85
+ };
86
+
87
+ // DO CONSTRUCT
88
+ return action(async (options) => {
89
+ options.manager ??=
90
+ (await detectManager()) ??
91
+ (await select("manager")("Package Manager")(
92
+ [
93
+ "npm" as const,
94
+ "pnpm" as const,
95
+ "yarn (berry is not supported)" as "yarn",
96
+ "bun" as const,
97
+ ],
98
+ (value) => value.split(" ")[0] as "yarn",
99
+ ));
100
+ pack.manager = options.manager;
101
+ options.project ??= await configure();
102
+ options.runtime =
103
+ ((options.runtime as string | undefined) ??
104
+ (await select("runtime")("Transform Runtime Swagger")([
105
+ "true",
106
+ "false",
107
+ ]))) !== "false";
108
+
109
+ if (questioned.value) console.log("");
110
+ return options as IArguments;
111
+ });
112
+ }
113
+
114
+ const detectManager = async (): Promise<
115
+ "npm" | "pnpm" | "yarn" | "bun" | null
116
+ > => {
117
+ const result: DetectResult | null = await detect({ cwd: process.cwd() });
118
+ if (result?.name === "npm")
119
+ return null; // NPM case is still selectable
120
+ else if (result?.name === "deno") return null; // Deno case is not supported
121
+ return result?.name ?? null;
122
+ };
123
+ }
@@ -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,91 +1,91 @@
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: Manager = "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?:
42
- | `latest`
43
- | `next`
44
- | `^${number}.${number}.${number}`
45
- | (string & {});
46
- force?: boolean;
47
- }): boolean {
48
- const middle: string = [
49
- installCmdTable[this.manager],
50
- props.dev ? devOptionTable[this.manager] : "",
51
- ]
52
- .filter((str) => !!str.length)
53
- .join(" ");
54
- const modulo: string = `${props.modulo}${props.version ? `@${props.version}` : ""}`;
55
- CommandExecutor.run([this.manager, middle, modulo].join(" "));
56
- return true;
57
- }
58
-
59
- private constructor(
60
- public readonly directory: string,
61
- public data: Package.Data,
62
- ) {}
63
-
64
- private static async load(file: string): Promise<Package.Data> {
65
- const content: string = await fs.promises.readFile(file, "utf8");
66
- return JSON.parse(content);
67
- }
68
- }
69
- export namespace Package {
70
- export interface Data {
71
- scripts?: Record<string, string>;
72
- dependencies?: Record<string, string>;
73
- devDependencies?: Record<string, string>;
74
- }
75
- }
76
-
77
- type Manager = "npm" | "pnpm" | "yarn" | "bun";
78
-
79
- const installCmdTable = {
80
- npm: "i",
81
- pnpm: "add",
82
- yarn: "add",
83
- bun: "add",
84
- } as const satisfies Record<Manager, string>;
85
-
86
- const devOptionTable = {
87
- npm: "-D",
88
- pnpm: "-D",
89
- yarn: "-D",
90
- bun: "-d",
91
- } as const satisfies Record<Manager, string>;
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: Manager = "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?:
42
+ | `latest`
43
+ | `next`
44
+ | `^${number}.${number}.${number}`
45
+ | (string & {});
46
+ force?: boolean;
47
+ }): boolean {
48
+ const middle: string = [
49
+ installCmdTable[this.manager],
50
+ props.dev ? devOptionTable[this.manager] : "",
51
+ ]
52
+ .filter((str) => !!str.length)
53
+ .join(" ");
54
+ const modulo: string = `${props.modulo}${props.version ? `@${props.version}` : ""}`;
55
+ CommandExecutor.run([this.manager, middle, modulo].join(" "));
56
+ return true;
57
+ }
58
+
59
+ private constructor(
60
+ public readonly directory: string,
61
+ public data: Package.Data,
62
+ ) {}
63
+
64
+ private static async load(file: string): Promise<Package.Data> {
65
+ const content: string = await fs.promises.readFile(file, "utf8");
66
+ return JSON.parse(content);
67
+ }
68
+ }
69
+ export namespace Package {
70
+ export interface Data {
71
+ scripts?: Record<string, string>;
72
+ dependencies?: Record<string, string>;
73
+ devDependencies?: Record<string, string>;
74
+ }
75
+ }
76
+
77
+ type Manager = "npm" | "pnpm" | "yarn" | "bun";
78
+
79
+ const installCmdTable = {
80
+ npm: "i",
81
+ pnpm: "add",
82
+ yarn: "add",
83
+ bun: "add",
84
+ } as const satisfies Record<Manager, string>;
85
+
86
+ const devOptionTable = {
87
+ npm: "-D",
88
+ pnpm: "-D",
89
+ yarn: "-D",
90
+ bun: "-d",
91
+ } as const satisfies Record<Manager, string>;
@@ -1,125 +1,125 @@
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 skipLibCheck: boolean | undefined = compilerOptions.skipLibCheck as
41
- | boolean
42
- | undefined;
43
- const core: comments.CommentObject | undefined = plugins.find(
44
- (p) =>
45
- typeof p === "object" &&
46
- p !== null &&
47
- p.transform === "@nestia/core/lib/transform",
48
- );
49
- const typia: comments.CommentObject | undefined = plugins.find(
50
- (p) =>
51
- typeof p === "object" &&
52
- p !== null &&
53
- p.transform === "typia/lib/transform",
54
- );
55
- const swagger: comments.CommentObject | undefined = plugins.find(
56
- (p) =>
57
- typeof p === "object" &&
58
- p !== null &&
59
- p.transform === "@nestia/sdk/lib/transform",
60
- );
61
- if (
62
- strictNullChecks !== false &&
63
- (strict === true || strictNullChecks === true) &&
64
- core !== undefined &&
65
- typia !== undefined &&
66
- swagger !== undefined &&
67
- skipLibCheck === true
68
- )
69
- return;
70
-
71
- // DO CONFIGURE
72
- compilerOptions.skipLibCheck = true;
73
- compilerOptions.strictNullChecks = true;
74
- if (strict === undefined && strictNullChecks === undefined)
75
- compilerOptions.strict = true;
76
- compilerOptions.experimentalDecorators = true;
77
- compilerOptions.emitDecoratorMetadata = true;
78
-
79
- if (core === undefined)
80
- plugins.push(
81
- comments.parse(`{
82
- "transform": "@nestia/core/lib/transform",
83
- /**
84
- * Validate request body.
85
- *
86
- * - "assert": Use typia.assert() function
87
- * - "is": Use typia.is() function
88
- * - "validate": Use typia.validate() function
89
- * - "assertEquals": Use typia.assertEquals() function
90
- * - "equals": Use typia.equals() function
91
- * - "validateEquals": Use typia.validateEquals() function
92
- */
93
- "validate": "validate",
94
-
95
- /**
96
- * Validate JSON typed response body.
97
- *
98
- * - "assert": Use typia.assertStringify() function
99
- * - "is": Use typia.isStringify() function
100
- * - "validate": Use typia.validateStringify() function
101
- * - "validate.log": typia.validateStringify(), but do not throw and just log it
102
- * - "stringify": Use typia.stringify() function, but dangerous
103
- * - null: Just use JSON.stringify() function, without boosting
104
- */
105
- "stringify": "assert"
106
- }`) as comments.CommentObject,
107
- );
108
- if (swagger === undefined && args.runtime === true)
109
- plugins.push(
110
- comments.parse(
111
- `{ "transform": "@nestia/sdk/lib/transform" }`,
112
- ) as comments.CommentObject,
113
- );
114
- if (typia === undefined)
115
- plugins.push(
116
- comments.parse(
117
- `{ "transform": "typia/lib/transform" }`,
118
- ) as comments.CommentObject,
119
- );
120
- await fs.promises.writeFile(
121
- args.project!,
122
- comments.stringify(config, null, 2),
123
- );
124
- }
125
- }
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 skipLibCheck: boolean | undefined = compilerOptions.skipLibCheck as
41
+ | boolean
42
+ | undefined;
43
+ const core: comments.CommentObject | undefined = plugins.find(
44
+ (p) =>
45
+ typeof p === "object" &&
46
+ p !== null &&
47
+ p.transform === "@nestia/core/lib/transform",
48
+ );
49
+ const typia: comments.CommentObject | undefined = plugins.find(
50
+ (p) =>
51
+ typeof p === "object" &&
52
+ p !== null &&
53
+ p.transform === "typia/lib/transform",
54
+ );
55
+ const swagger: comments.CommentObject | undefined = plugins.find(
56
+ (p) =>
57
+ typeof p === "object" &&
58
+ p !== null &&
59
+ p.transform === "@nestia/sdk/lib/transform",
60
+ );
61
+ if (
62
+ strictNullChecks !== false &&
63
+ (strict === true || strictNullChecks === true) &&
64
+ core !== undefined &&
65
+ typia !== undefined &&
66
+ swagger !== undefined &&
67
+ skipLibCheck === true
68
+ )
69
+ return;
70
+
71
+ // DO CONFIGURE
72
+ compilerOptions.skipLibCheck = true;
73
+ compilerOptions.strictNullChecks = true;
74
+ if (strict === undefined && strictNullChecks === undefined)
75
+ compilerOptions.strict = true;
76
+ compilerOptions.experimentalDecorators = true;
77
+ compilerOptions.emitDecoratorMetadata = true;
78
+
79
+ if (core === undefined)
80
+ plugins.push(
81
+ comments.parse(`{
82
+ "transform": "@nestia/core/lib/transform",
83
+ /**
84
+ * Validate request body.
85
+ *
86
+ * - "assert": Use typia.assert() function
87
+ * - "is": Use typia.is() function
88
+ * - "validate": Use typia.validate() function
89
+ * - "assertEquals": Use typia.assertEquals() function
90
+ * - "equals": Use typia.equals() function
91
+ * - "validateEquals": Use typia.validateEquals() function
92
+ */
93
+ "validate": "validate",
94
+
95
+ /**
96
+ * Validate JSON typed response body.
97
+ *
98
+ * - "assert": Use typia.assertStringify() function
99
+ * - "is": Use typia.isStringify() function
100
+ * - "validate": Use typia.validateStringify() function
101
+ * - "validate.log": typia.validateStringify(), but do not throw and just log it
102
+ * - "stringify": Use typia.stringify() function, but dangerous
103
+ * - null: Just use JSON.stringify() function, without boosting
104
+ */
105
+ "stringify": "assert"
106
+ }`) as comments.CommentObject,
107
+ );
108
+ if (swagger === undefined && args.runtime === true)
109
+ plugins.push(
110
+ comments.parse(
111
+ `{ "transform": "@nestia/sdk/lib/transform" }`,
112
+ ) as comments.CommentObject,
113
+ );
114
+ if (typia === undefined)
115
+ plugins.push(
116
+ comments.parse(
117
+ `{ "transform": "typia/lib/transform" }`,
118
+ ) as comments.CommentObject,
119
+ );
120
+ await fs.promises.writeFile(
121
+ args.project!,
122
+ comments.stringify(config, null, 2),
123
+ );
124
+ }
125
+ }