nestia 11.0.0-dev.20260312 → 11.0.0-dev.20260313
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/package.json +3 -3
- package/src/NestiaSetupWizard.ts +90 -90
- package/src/NestiaStarter.ts +41 -41
- package/src/NestiaTemplate.ts +37 -37
- package/src/internal/ArgumentParser.ts +123 -123
- package/src/internal/CommandExecutor.ts +8 -8
- package/src/internal/FileRetriever.ts +22 -22
- package/src/internal/PackageManager.ts +91 -91
- package/src/internal/PluginConfigurator.ts +125 -125
- package/bin/NestiaSetupWizard.d.ts +0 -3
- package/bin/NestiaSetupWizard.js +0 -98
- package/bin/NestiaSetupWizard.js.map +0 -1
- package/bin/NestiaStarter.d.ts +0 -3
- package/bin/NestiaStarter.js +0 -49
- package/bin/NestiaStarter.js.map +0 -1
- package/bin/NestiaTemplate.d.ts +0 -3
- package/bin/NestiaTemplate.js +0 -46
- package/bin/NestiaTemplate.js.map +0 -1
- package/bin/index.d.ts +0 -4
- package/bin/index.js +0 -107
- package/bin/index.js.map +0 -1
- package/bin/internal/ArgumentParser.d.ts +0 -9
- package/bin/internal/ArgumentParser.js +0 -106
- package/bin/internal/ArgumentParser.js.map +0 -1
- package/bin/internal/CommandExecutor.d.ts +0 -3
- package/bin/internal/CommandExecutor.js +0 -16
- package/bin/internal/CommandExecutor.js.map +0 -1
- package/bin/internal/FileRetriever.d.ts +0 -4
- package/bin/internal/FileRetriever.js +0 -28
- package/bin/internal/FileRetriever.js.map +0 -1
- package/bin/internal/PackageManager.d.ts +0 -25
- package/bin/internal/PackageManager.js +0 -76
- package/bin/internal/PackageManager.js.map +0 -1
- package/bin/internal/PluginConfigurator.d.ts +0 -4
- package/bin/internal/PluginConfigurator.js +0 -99
- package/bin/internal/PluginConfigurator.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestia",
|
|
3
|
-
"version": "11.0.0-dev.
|
|
3
|
+
"version": "11.0.0-dev.20260313",
|
|
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/
|
|
48
|
-
"@nestia/
|
|
47
|
+
"@nestia/sdk": "^11.0.0-dev.20260313",
|
|
48
|
+
"@nestia/core": "^11.0.0-dev.20260313"
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
51
|
"bin",
|
package/src/NestiaSetupWizard.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/NestiaStarter.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/NestiaTemplate.ts
CHANGED
|
@@ -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
|
+
}
|