nestia 4.0.11-dev.20230410 → 4.0.11-dev.20230411
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/bin/internal/ArgumentParser.js +8 -31
- package/bin/internal/ArgumentParser.js.map +1 -1
- package/bin/internal/PluginConfigurator.js +5 -28
- package/bin/internal/PluginConfigurator.js.map +1 -1
- package/package.json +4 -3
- package/src/NestiaSetupWizard.ts +48 -0
- package/src/NestiaStarter.ts +44 -0
- package/src/index.ts +74 -0
- package/src/internal/ArgumentParser.ts +114 -0
- package/src/internal/CommandExecutor.ts +8 -0
- package/src/internal/FileRetriever.ts +22 -0
- package/src/internal/PackageManager.ts +72 -0
- package/src/internal/PluginConfigurator.ts +89 -0
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -36,22 +13,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
13
|
};
|
|
37
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
15
|
exports.ArgumentParser = void 0;
|
|
16
|
+
const commander_1 = __importDefault(require("commander"));
|
|
39
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
40
19
|
var ArgumentParser;
|
|
41
20
|
(function (ArgumentParser) {
|
|
42
21
|
function parse(pack) {
|
|
43
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
23
|
// PREPARE ASSETS
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
command.option("--manager [manager", "package manager");
|
|
49
|
-
command.option("--project [project]", "tsconfig.json file location");
|
|
24
|
+
commander_1.default.program.option("--compiler [compiler]", "compiler type");
|
|
25
|
+
commander_1.default.program.option("--manager [manager", "package manager");
|
|
26
|
+
commander_1.default.program.option("--project [project]", "tsconfig.json file location");
|
|
50
27
|
// INTERNAL PROCEDURES
|
|
51
28
|
const questioned = { value: false };
|
|
52
29
|
const action = (closure) => {
|
|
53
30
|
return new Promise((resolve, reject) => {
|
|
54
|
-
|
|
31
|
+
commander_1.default.program.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
55
32
|
try {
|
|
56
33
|
resolve(yield closure(options));
|
|
57
34
|
}
|
|
@@ -59,12 +36,12 @@ var ArgumentParser;
|
|
|
59
36
|
reject(exp);
|
|
60
37
|
}
|
|
61
38
|
}));
|
|
62
|
-
|
|
39
|
+
commander_1.default.program.parseAsync().catch(reject);
|
|
63
40
|
});
|
|
64
41
|
};
|
|
65
42
|
const select = (name) => (message) => (choices) => __awaiter(this, void 0, void 0, function* () {
|
|
66
43
|
questioned.value = true;
|
|
67
|
-
return (yield
|
|
44
|
+
return (yield inquirer_1.default.createPromptModule()({
|
|
68
45
|
type: "list",
|
|
69
46
|
name: name,
|
|
70
47
|
message: message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArgumentParser.js","sourceRoot":"","sources":["../../src/internal/ArgumentParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ArgumentParser.js","sourceRoot":"","sources":["../../src/internal/ArgumentParser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAkC;AAClC,4CAAoB;AACpB,wDAAgC;AAIhC,IAAiB,cAAc,CAgG9B;AAhGD,WAAiB,cAAc;IAO3B,SAAsB,KAAK,CAAC,IAAoB;;YAC5C,iBAAiB;YACjB,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAAC;YACnE,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC;YAClE,mBAAS,CAAC,OAAO,CAAC,MAAM,CACpB,qBAAqB,EACrB,6BAA6B,CAChC,CAAC;YAEF,sBAAsB;YACtB,MAAM,UAAU,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,CACX,OAA8D,EAChE,EAAE;gBACA,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC/C,mBAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAO,OAAO,EAAE,EAAE;wBACvC,IAAI;4BACA,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;yBACnC;wBAAC,OAAO,GAAG,EAAE;4BACV,MAAM,CAAC,GAAG,CAAC,CAAC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B,oBAAK,QAwF1B,CAAA;AACL,CAAC,EAhGgB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAgG9B;AAED,MAAM,oBAAoB,GAAG;IACzB,4EAA4E;IAC5E,EAAE;IACF,2EAA2E;IAC3E,sEAAsE;IACtE,8EAA8E;IAC9E,EAAE;IACF,sEAAsE;IACtE,EAAE;CACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -36,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
13
|
};
|
|
37
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
15
|
exports.PluginConfigurator = void 0;
|
|
16
|
+
const comment_json_1 = __importDefault(require("comment-json"));
|
|
39
17
|
const fs_1 = __importDefault(require("fs"));
|
|
40
18
|
var PluginConfigurator;
|
|
41
19
|
(function (PluginConfigurator) {
|
|
42
20
|
function configure(args) {
|
|
43
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
22
|
// GET COMPILER-OPTIONS
|
|
45
|
-
const
|
|
46
|
-
const config = comments.parse(yield fs_1.default.promises.readFile(args.project, "utf8"));
|
|
23
|
+
const config = comment_json_1.default.parse(yield fs_1.default.promises.readFile(args.project, "utf8"));
|
|
47
24
|
const compilerOptions = config.compilerOptions;
|
|
48
25
|
if (compilerOptions === undefined)
|
|
49
26
|
throw new Error(`${args.project} file does not have "compilerOptions" property.`);
|
|
@@ -69,7 +46,7 @@ var PluginConfigurator;
|
|
|
69
46
|
// DO CONFIGURE
|
|
70
47
|
compilerOptions.strict = true;
|
|
71
48
|
if (core === undefined)
|
|
72
|
-
plugins.push(
|
|
49
|
+
plugins.push(comment_json_1.default.parse(`{
|
|
73
50
|
"transform": "@nestia/core/lib/transform",
|
|
74
51
|
/**
|
|
75
52
|
* Validate request body.
|
|
@@ -92,8 +69,8 @@ var PluginConfigurator;
|
|
|
92
69
|
"stringify": "assert"
|
|
93
70
|
}`));
|
|
94
71
|
if (typia === undefined)
|
|
95
|
-
plugins.push(
|
|
96
|
-
yield fs_1.default.promises.writeFile(args.project,
|
|
72
|
+
plugins.push(comment_json_1.default.parse(`{ "transform": "typia/lib/transform" }`));
|
|
73
|
+
yield fs_1.default.promises.writeFile(args.project, comment_json_1.default.stringify(config, null, 2));
|
|
97
74
|
});
|
|
98
75
|
}
|
|
99
76
|
PluginConfigurator.configure = configure;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginConfigurator.js","sourceRoot":"","sources":["../../src/internal/PluginConfigurator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PluginConfigurator.js","sourceRoot":"","sources":["../../src/internal/PluginConfigurator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAAoC;AACpC,4CAAoB;AAIpB,IAAiB,kBAAkB,CAmFlC;AAnFD,WAAiB,kBAAkB;IAC/B,SAAsB,SAAS,CAC3B,IAA+B;;YAE/B,uBAAuB;YACvB,MAAM,MAAM,GAA2B,sBAAQ,CAAC,KAAK,CACjD,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAQ,EAAE,MAAM,CAAC,CAC1B,CAAC;YAC5B,MAAM,eAAe,GACjB,MAAM,CAAC,eAAqD,CAAC;YACjE,IAAI,eAAe,KAAK,SAAS;gBAC7B,MAAM,IAAI,KAAK,CACX,GAAG,IAAI,CAAC,OAAO,iDAAiD,CACnE,CAAC;YAEN,kBAAkB;YAClB,MAAM,OAAO,GAAkD,CAAC,GAAG,EAAE;gBACjE,MAAM,OAAO,GAAG,eAAe,CAAC,OAEjB,CAAC;gBAChB,IAAI,OAAO,KAAK,SAAS;oBACrB,OAAO,CAAC,eAAe,CAAC,OAAO,GAAG,EAAS,CAAC,CAAC;qBAC5C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;oBAC5B,MAAM,IAAI,KAAK,CACX,yBAAyB,IAAI,CAAC,OAAO,sBAAsB,CAC9D,CAAC;gBACN,OAAO,OAAO,CAAC;YACnB,CAAC,CAAC,EAAE,CAAC;YAEL,2BAA2B;YAC3B,MAAM,MAAM,GAAY,eAAe,CAAC,MAAM,KAAK,IAAI,CAAC;YACxD,MAAM,IAAI,GAAuC,OAAO,CAAC,IAAI,CACzD,CAAC,CAAC,EAAE,EAAE,CACF,OAAO,CAAC,KAAK,QAAQ;gBACrB,CAAC,KAAK,IAAI;gBACV,CAAC,CAAC,SAAS,KAAK,4BAA4B,CACnD,CAAC;YACF,MAAM,KAAK,GAAuC,OAAO,CAAC,IAAI,CAC1D,CAAC,CAAC,EAAE,EAAE,CACF,OAAO,CAAC,KAAK,QAAQ;gBACrB,CAAC,KAAK,IAAI;gBACV,CAAC,CAAC,SAAS,KAAK,qBAAqB,CAC5C,CAAC;YACF,IAAI,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK;gBAAE,OAAO;YAExC,eAAe;YACf,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC;YAC9B,IAAI,IAAI,KAAK,SAAS;gBAClB,OAAO,CAAC,IAAI,CACR,sBAAQ,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;kBAqBb,CAA2B,CAChC,CAAC;YACN,IAAI,KAAK,KAAK,SAAS;gBACnB,OAAO,CAAC,IAAI,CACR,sBAAQ,CAAC,KAAK,CACV,wCAAwC,CACjB,CAC9B,CAAC;YACN,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CACvB,IAAI,CAAC,OAAQ,EACb,sBAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CACtC,CAAC;QACN,CAAC;KAAA;IAjFqB,4BAAS,YAiF9B,CAAA;AACL,CAAC,EAnFgB,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAmFlC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestia",
|
|
3
|
-
"version": "4.0.11-dev.
|
|
4
|
-
"description": "Nestia CLI",
|
|
3
|
+
"version": "4.0.11-dev.20230411",
|
|
4
|
+
"description": "Nestia CLI tool",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"nestia": "bin/index.js"
|
|
@@ -43,8 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"bin",
|
|
46
|
+
"src",
|
|
46
47
|
"README.md",
|
|
47
48
|
"LICENSE",
|
|
48
|
-
"package
|
|
49
|
+
"package.json"
|
|
49
50
|
]
|
|
50
51
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
// LOAD PACKAGE.JSON INFO
|
|
13
|
+
const pack: PackageManager = await PackageManager.mount();
|
|
14
|
+
|
|
15
|
+
// TAKE ARGUMENTS
|
|
16
|
+
const args: ArgumentParser.IArguments = await ArgumentParser.parse(
|
|
17
|
+
pack,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// INSTALL TYPESCRIPT
|
|
21
|
+
pack.install({ dev: true, modulo: "typescript", version: "4.9.5" });
|
|
22
|
+
args.project ??= (() => {
|
|
23
|
+
CommandExecutor.run("npx tsc --init", false);
|
|
24
|
+
return (args.project = "tsconfig.json");
|
|
25
|
+
})();
|
|
26
|
+
pack.install({ dev: true, modulo: "ts-node" });
|
|
27
|
+
|
|
28
|
+
// INSTALL COMPILER
|
|
29
|
+
pack.install({ dev: true, modulo: args.compiler });
|
|
30
|
+
if (args.compiler === "ts-patch") {
|
|
31
|
+
await pack.save((data) => {
|
|
32
|
+
data.scripts ??= {};
|
|
33
|
+
if (typeof data.scripts.prepare === "string")
|
|
34
|
+
data.scripts.prepare =
|
|
35
|
+
"ts-patch install && " + data.scripts.prepare;
|
|
36
|
+
else data.scripts.prepare = "ts-patch install";
|
|
37
|
+
});
|
|
38
|
+
CommandExecutor.run("npm run prepare", false);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// INSTALL AND CONFIGURE TYPIA
|
|
42
|
+
pack.install({ dev: false, modulo: "typia" });
|
|
43
|
+
pack.install({ dev: false, modulo: "@nestia/core" });
|
|
44
|
+
pack.install({ dev: true, modulo: "@nestia/sdk" });
|
|
45
|
+
pack.install({ dev: true, modulo: "nestia" });
|
|
46
|
+
await PluginConfigurator.configure(args);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
export namespace NestiaStarter {
|
|
5
|
+
export const start =
|
|
6
|
+
(halter: (msg?: string) => never) =>
|
|
7
|
+
async (argv: string[]): Promise<void> => {
|
|
8
|
+
// VALIDATION
|
|
9
|
+
const dest: string | undefined = argv[0];
|
|
10
|
+
const manager: string = argv[1] ?? "npm";
|
|
11
|
+
|
|
12
|
+
if (dest === undefined) halter();
|
|
13
|
+
else if (fs.existsSync(dest) === true)
|
|
14
|
+
halter("The target directory already exists.");
|
|
15
|
+
|
|
16
|
+
console.log("-----------------------------------------");
|
|
17
|
+
console.log(" Nestia Starter Kit");
|
|
18
|
+
console.log("-----------------------------------------");
|
|
19
|
+
|
|
20
|
+
// COPY PROJECTS
|
|
21
|
+
execute(
|
|
22
|
+
`git clone https://github.com/samchon/nestia-template ${dest}`,
|
|
23
|
+
);
|
|
24
|
+
console.log(`cd "${dest}"`);
|
|
25
|
+
process.chdir(dest);
|
|
26
|
+
|
|
27
|
+
// INSTALL DEPENDENCIES
|
|
28
|
+
execute(`${manager} install`);
|
|
29
|
+
|
|
30
|
+
// BUILD TYPESCRIPT
|
|
31
|
+
execute("npm run build");
|
|
32
|
+
|
|
33
|
+
// DO TEST
|
|
34
|
+
execute("npm run test");
|
|
35
|
+
|
|
36
|
+
// REMOVE .GIT DIRECTORY
|
|
37
|
+
cp.execSync("npx rimraf .git");
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function execute(command: string): void {
|
|
41
|
+
console.log(command);
|
|
42
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
3
|
+
|
|
4
|
+
npx nestia [command] [options?]
|
|
5
|
+
|
|
6
|
+
1. npx nestia start <directory> --manager (npm|pnpm|yarn)
|
|
7
|
+
- npx nestia start project
|
|
8
|
+
- npx nestia start project --manager pnpm
|
|
9
|
+
2. npx nestia setup \\
|
|
10
|
+
--compiler (ttypescript|ts-patch) \\
|
|
11
|
+
--manager (npm|pnpm|yarn) \\
|
|
12
|
+
--project {tsconfig.json file path}
|
|
13
|
+
- npx nestia setup
|
|
14
|
+
- npx nestia setup --compiler ttypescript
|
|
15
|
+
- npx nestia setup --compiler ts-patch
|
|
16
|
+
- npx nestia setup --manager pnpm
|
|
17
|
+
3. npx nestia dependencies --manager (npm|pnpm|yarn)
|
|
18
|
+
- npx nestia dependencies
|
|
19
|
+
- npx nestia dependencies --manager yarn
|
|
20
|
+
4. npx nestia init
|
|
21
|
+
5. npx nestia sdk <input> --out <output>
|
|
22
|
+
- npx nestia sdk # when "nestia.config.ts" be configured
|
|
23
|
+
- npx nestia sdk src/controllers --out src/api
|
|
24
|
+
- npx nestia sdk src/**/*.controller.ts --out src/api
|
|
25
|
+
6. npx nestia swagger <input> --out <output>
|
|
26
|
+
- npx nestia swagger # when "nestia.config.ts" be configured
|
|
27
|
+
- npx nestia swagger src/controllers --out src/api
|
|
28
|
+
- npx nestia swagger src/**/*.controller.ts --out src/api
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
function halt(desc: string): never {
|
|
32
|
+
console.error(desc);
|
|
33
|
+
process.exit(-1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function main(): Promise<void> {
|
|
37
|
+
const type: string | undefined = process.argv[2];
|
|
38
|
+
const argv: string[] = process.argv.slice(3);
|
|
39
|
+
|
|
40
|
+
if (type === "start") {
|
|
41
|
+
await (
|
|
42
|
+
await import("./NestiaStarter")
|
|
43
|
+
).NestiaStarter.start((msg) => halt(msg ?? USAGE))(argv);
|
|
44
|
+
} else if (type === "setup") {
|
|
45
|
+
try {
|
|
46
|
+
await import("comment-json");
|
|
47
|
+
await import("inquirer");
|
|
48
|
+
await import("commander");
|
|
49
|
+
} catch {
|
|
50
|
+
halt(
|
|
51
|
+
`nestia has not been installed. Run "npm i -D nestia" before.`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
await (await import("./NestiaSetupWizard")).NestiaSetupWizard.setup();
|
|
55
|
+
} else if (
|
|
56
|
+
type === "dependencies" ||
|
|
57
|
+
type === "init" ||
|
|
58
|
+
type === "sdk" ||
|
|
59
|
+
type === "swagger"
|
|
60
|
+
) {
|
|
61
|
+
try {
|
|
62
|
+
require.resolve("@nestia/sdk/lib/executable/sdk");
|
|
63
|
+
} catch {
|
|
64
|
+
halt(
|
|
65
|
+
`@nestia/sdk has not been installed. Run "npx nestia setup" before.`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
await import("@nestia/sdk/lib/executable/sdk");
|
|
69
|
+
} else halt(USAGE);
|
|
70
|
+
}
|
|
71
|
+
main().catch((exp) => {
|
|
72
|
+
console.log(exp.message);
|
|
73
|
+
process.exit(-1);
|
|
74
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import commander from "commander";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
|
|
5
|
+
import { PackageManager } from "./PackageManager";
|
|
6
|
+
|
|
7
|
+
export namespace ArgumentParser {
|
|
8
|
+
export interface IArguments {
|
|
9
|
+
compiler: "ts-patch" | "ttypescript";
|
|
10
|
+
manager: "npm" | "pnpm" | "yarn";
|
|
11
|
+
project: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function parse(pack: PackageManager): Promise<IArguments> {
|
|
15
|
+
// PREPARE ASSETS
|
|
16
|
+
commander.program.option("--compiler [compiler]", "compiler type");
|
|
17
|
+
commander.program.option("--manager [manager", "package manager");
|
|
18
|
+
commander.program.option(
|
|
19
|
+
"--project [project]",
|
|
20
|
+
"tsconfig.json file location",
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// INTERNAL PROCEDURES
|
|
24
|
+
const questioned = { value: false };
|
|
25
|
+
const action = (
|
|
26
|
+
closure: (options: Partial<IArguments>) => Promise<IArguments>,
|
|
27
|
+
) => {
|
|
28
|
+
return new Promise<IArguments>((resolve, reject) => {
|
|
29
|
+
commander.program.action(async (options) => {
|
|
30
|
+
try {
|
|
31
|
+
resolve(await closure(options));
|
|
32
|
+
} catch (exp) {
|
|
33
|
+
reject(exp);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
commander.program.parseAsync().catch(reject);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const select =
|
|
40
|
+
(name: string) =>
|
|
41
|
+
(message: string) =>
|
|
42
|
+
async <Choice extends string>(
|
|
43
|
+
choices: Choice[],
|
|
44
|
+
): Promise<Choice> => {
|
|
45
|
+
questioned.value = true;
|
|
46
|
+
return (
|
|
47
|
+
await inquirer.createPromptModule()({
|
|
48
|
+
type: "list",
|
|
49
|
+
name: name,
|
|
50
|
+
message: message,
|
|
51
|
+
choices: choices,
|
|
52
|
+
})
|
|
53
|
+
)[name];
|
|
54
|
+
};
|
|
55
|
+
const configure = async () => {
|
|
56
|
+
const fileList: string[] = await (
|
|
57
|
+
await fs.promises.readdir(process.cwd())
|
|
58
|
+
)
|
|
59
|
+
.filter(
|
|
60
|
+
(str) =>
|
|
61
|
+
str.substring(0, 8) === "tsconfig" &&
|
|
62
|
+
str.substring(str.length - 5) === ".json",
|
|
63
|
+
)
|
|
64
|
+
.sort((x, y) =>
|
|
65
|
+
x === "tsconfig.json"
|
|
66
|
+
? -1
|
|
67
|
+
: y === "tsconfig.json"
|
|
68
|
+
? 1
|
|
69
|
+
: x < y
|
|
70
|
+
? -1
|
|
71
|
+
: 1,
|
|
72
|
+
);
|
|
73
|
+
if (fileList.length === 0) {
|
|
74
|
+
if (process.cwd() !== pack.directory)
|
|
75
|
+
throw new Error(`Unable to find "tsconfig.json" file.`);
|
|
76
|
+
return null;
|
|
77
|
+
} else if (fileList.length === 1) return fileList[0];
|
|
78
|
+
return select("tsconfig")("TS Config File")(fileList);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// DO CONSTRUCT
|
|
82
|
+
return action(async (options) => {
|
|
83
|
+
if (options.compiler === undefined) {
|
|
84
|
+
console.log(COMPILER_DESCRIPTION);
|
|
85
|
+
options.compiler = await select("compiler")(`Compiler`)(
|
|
86
|
+
pack.data.scripts?.build === "nest build"
|
|
87
|
+
? ["ts-patch" as const, "ttypescript" as const]
|
|
88
|
+
: ["ttypescript" as const, "ts-patch" as const],
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
options.manager ??= await select("manager")("Package Manager")([
|
|
92
|
+
"npm" as const,
|
|
93
|
+
"pnpm" as const,
|
|
94
|
+
"yarn" as const,
|
|
95
|
+
]);
|
|
96
|
+
pack.manager = options.manager;
|
|
97
|
+
options.project ??= await configure();
|
|
98
|
+
|
|
99
|
+
if (questioned.value) console.log("");
|
|
100
|
+
return options as IArguments;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const COMPILER_DESCRIPTION = [
|
|
106
|
+
`About compiler, if you adapt "ttypescript", you should use "ttsc" instead.`,
|
|
107
|
+
``,
|
|
108
|
+
`Otherwise, you choose "ts-patch", you can use the original "tsc" command.`,
|
|
109
|
+
`However, the "ts-patch" hacks "node_modules/typescript" source code.`,
|
|
110
|
+
`Also, whenever update "typescript", you've to run "npm run prepare" command.`,
|
|
111
|
+
``,
|
|
112
|
+
`By the way, when using "@nest/cli", you must just choose "ts-patch".`,
|
|
113
|
+
``,
|
|
114
|
+
].join("\n");
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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?: string;
|
|
42
|
+
}): boolean {
|
|
43
|
+
const middle: string =
|
|
44
|
+
this.manager === "yarn"
|
|
45
|
+
? `add${props.dev ? " -D" : ""}`
|
|
46
|
+
: `install ${props.dev ? "--save-dev" : "--save"}`;
|
|
47
|
+
CommandExecutor.run(
|
|
48
|
+
`${this.manager} ${middle} ${props.modulo}${
|
|
49
|
+
props.version ? `@${props.version}` : ""
|
|
50
|
+
}`,
|
|
51
|
+
true,
|
|
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
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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)
|
|
27
|
+
return (compilerOptions.plugins = [] as any);
|
|
28
|
+
else if (!Array.isArray(plugins))
|
|
29
|
+
throw new Error(
|
|
30
|
+
`"plugins" property of ${args.project} must be array type.`,
|
|
31
|
+
);
|
|
32
|
+
return plugins;
|
|
33
|
+
})();
|
|
34
|
+
|
|
35
|
+
// CHECK WHETHER CONFIGURED
|
|
36
|
+
const strict: boolean = compilerOptions.strict === true;
|
|
37
|
+
const core: comments.CommentObject | undefined = plugins.find(
|
|
38
|
+
(p) =>
|
|
39
|
+
typeof p === "object" &&
|
|
40
|
+
p !== null &&
|
|
41
|
+
p.transform === "@nestia/core/lib/transform",
|
|
42
|
+
);
|
|
43
|
+
const typia: comments.CommentObject | undefined = plugins.find(
|
|
44
|
+
(p) =>
|
|
45
|
+
typeof p === "object" &&
|
|
46
|
+
p !== null &&
|
|
47
|
+
p.transform === "typia/lib/transform",
|
|
48
|
+
);
|
|
49
|
+
if (strict && !!core && !!typia) return;
|
|
50
|
+
|
|
51
|
+
// DO CONFIGURE
|
|
52
|
+
compilerOptions.strict = true;
|
|
53
|
+
if (core === undefined)
|
|
54
|
+
plugins.push(
|
|
55
|
+
comments.parse(`{
|
|
56
|
+
"transform": "@nestia/core/lib/transform",
|
|
57
|
+
/**
|
|
58
|
+
* Validate request body.
|
|
59
|
+
*
|
|
60
|
+
* - "assert": Use typia.assert() function
|
|
61
|
+
* - "is": Use typia.is() function
|
|
62
|
+
* - "validate": Use typia.validate() function
|
|
63
|
+
*/
|
|
64
|
+
"validate": "assert",
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Validate JSON typed response body.
|
|
68
|
+
*
|
|
69
|
+
* - "assert": Use typia.assertStringify() function
|
|
70
|
+
* - "is": Use typia.isStringify() function
|
|
71
|
+
* - "validate": Use typia.validateStringify() function
|
|
72
|
+
* - "stringify": Use typia.stringify() function, but dangerous
|
|
73
|
+
* - null: Just use JSON.stringify() function, without boosting
|
|
74
|
+
*/
|
|
75
|
+
"stringify": "assert"
|
|
76
|
+
}`) as comments.CommentObject,
|
|
77
|
+
);
|
|
78
|
+
if (typia === undefined)
|
|
79
|
+
plugins.push(
|
|
80
|
+
comments.parse(
|
|
81
|
+
`{ "transform": "typia/lib/transform" }`,
|
|
82
|
+
) as comments.CommentObject,
|
|
83
|
+
);
|
|
84
|
+
await fs.promises.writeFile(
|
|
85
|
+
args.project!,
|
|
86
|
+
comments.stringify(config, null, 2),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|