@expressots/cli 1.11.0 → 1.12.0
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/cli.js +2 -1
- package/bin/commands/project.commands.js +24 -8
- package/bin/help/form.js +2 -2
- package/bin/scripts/cli.d.ts +3 -0
- package/bin/scripts/cli.js +24 -0
- package/bin/scripts/form.d.ts +1 -0
- package/bin/scripts/form.js +107 -0
- package/bin/scripts/index.d.ts +1 -0
- package/bin/scripts/index.js +17 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ const new_1 = require("./new");
|
|
|
16
16
|
const providers_1 = require("./providers");
|
|
17
17
|
const cli_2 = require("./providers/create/cli");
|
|
18
18
|
const cli_ui_1 = require("./utils/cli-ui");
|
|
19
|
+
const scripts_1 = require("./scripts");
|
|
19
20
|
process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n`);
|
|
20
21
|
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
21
22
|
.scriptName("expressots")
|
|
@@ -26,6 +27,7 @@ process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n
|
|
|
26
27
|
.command((0, cli_2.createExternalProviderCMD)())
|
|
27
28
|
.command((0, providers_1.addProviderCMD)())
|
|
28
29
|
.command((0, generate_1.generateProject)())
|
|
30
|
+
.command((0, scripts_1.scriptsCommand)())
|
|
29
31
|
.command((0, info_1.infoProject)())
|
|
30
32
|
.command((0, cli_1.helpCommand)())
|
|
31
33
|
.demandCommand(1, "You need at least one command before moving on")
|
|
@@ -33,7 +35,6 @@ process_1.stdout.write(`\n${[chalk_1.default.bold.green("🐎 Expressots")]}\n\n
|
|
|
33
35
|
.fail((msg, err, yargs) => {
|
|
34
36
|
if (msg) {
|
|
35
37
|
if (msg.includes("Unknown argument")) {
|
|
36
|
-
// Get the command name
|
|
37
38
|
const command = process.argv[2];
|
|
38
39
|
if (command === "run") {
|
|
39
40
|
(0, cli_ui_1.printError)(`The "run" command has been removed. Use "dev", "prod" or "build" instead.`, "expressots help");
|
|
@@ -34,11 +34,26 @@ const path_1 = __importStar(require("path"));
|
|
|
34
34
|
const cli_ui_1 = require("../utils/cli-ui");
|
|
35
35
|
const compiler_1 = __importDefault(require("../utils/compiler"));
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Helper function to load and extract outDir from tsconfig.build.json
|
|
38
38
|
*/
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
39
|
+
function getOutDir() {
|
|
40
|
+
const tsconfigBuildPath = (0, path_1.join)(process.cwd(), "tsconfig.build.json");
|
|
41
|
+
if (!(0, fs_1.existsSync)(tsconfigBuildPath)) {
|
|
42
|
+
(0, cli_ui_1.printError)("Cannot find tsconfig.build.json. Please create one in the root directory", "tsconfig-build-path");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const tsconfig = JSON.parse((0, fs_1.readFileSync)(tsconfigBuildPath, "utf-8"));
|
|
46
|
+
const outDir = tsconfig.compilerOptions.outDir;
|
|
47
|
+
if (!outDir) {
|
|
48
|
+
(0, cli_ui_1.printError)("Cannot find outDir in tsconfig.build.json. Please provide an outDir.", "tsconfig-build-path");
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
if (!(0, fs_1.existsSync)(outDir)) {
|
|
52
|
+
(0, fs_1.mkdirSync)(outDir, { recursive: true });
|
|
53
|
+
(0, cli_ui_1.printSuccess)(`Created outDir: ${outDir}`, "outdir-creation");
|
|
54
|
+
}
|
|
55
|
+
return outDir;
|
|
56
|
+
}
|
|
42
57
|
/**
|
|
43
58
|
* Load the configuration from the compiler
|
|
44
59
|
* @param compiler The compiler to load the configuration from
|
|
@@ -123,7 +138,7 @@ function execCmd(command, args, cwd = process.cwd()) {
|
|
|
123
138
|
/**
|
|
124
139
|
* Helper function to clean the dist directory
|
|
125
140
|
*/
|
|
126
|
-
const cleanDist = async () => {
|
|
141
|
+
const cleanDist = async (outDir) => {
|
|
127
142
|
await fs_1.promises.rm(outDir, { recursive: true, force: true });
|
|
128
143
|
(0, cli_ui_1.printSuccess)(`Clean ${outDir} directory`, "clean-dist");
|
|
129
144
|
};
|
|
@@ -137,7 +152,7 @@ const compileTypescript = async () => {
|
|
|
137
152
|
/**
|
|
138
153
|
* Helper function to copy files to the dist directory
|
|
139
154
|
*/
|
|
140
|
-
const copyFiles = async () => {
|
|
155
|
+
const copyFiles = async (outDir) => {
|
|
141
156
|
const { opinionated } = await compiler_1.default.loadConfig();
|
|
142
157
|
let filesToCopy = [];
|
|
143
158
|
if (opinionated) {
|
|
@@ -168,6 +183,7 @@ const clearScreen = () => {
|
|
|
168
183
|
*/
|
|
169
184
|
const runCommand = async ({ command, }) => {
|
|
170
185
|
const { opinionated } = await compiler_1.default.loadConfig();
|
|
186
|
+
const outDir = getOutDir();
|
|
171
187
|
try {
|
|
172
188
|
switch (command) {
|
|
173
189
|
case "dev":
|
|
@@ -178,9 +194,9 @@ const runCommand = async ({ command, }) => {
|
|
|
178
194
|
(0, cli_ui_1.printError)("Cannot build project. Please provide an outDir in tsconfig.build.json", "build-command");
|
|
179
195
|
process.exit(1);
|
|
180
196
|
}
|
|
181
|
-
await cleanDist();
|
|
197
|
+
await cleanDist(outDir);
|
|
182
198
|
await compileTypescript();
|
|
183
|
-
await copyFiles();
|
|
199
|
+
await copyFiles(outDir);
|
|
184
200
|
break;
|
|
185
201
|
case "prod": {
|
|
186
202
|
if (!outDir) {
|
package/bin/help/form.js
CHANGED
|
@@ -15,11 +15,11 @@ const helpForm = async () => {
|
|
|
15
15
|
],
|
|
16
16
|
colWidths: [15, 15, 60],
|
|
17
17
|
});
|
|
18
|
-
table.push(["new project", "new", "Generate a new project"], ["info", "i", "Provides project information"], ["resources", "r", "Displays cli commands and resources"], ["help", "h", "Show command help"], [
|
|
18
|
+
table.push(["new project", "new", "Generate a new project"], ["info", "i", "Provides project information"], ["resources", "r", "Displays cli commands and resources"], ["scripts", "scripts", "Run scripts list or specific scripts"], ["help", "h", "Show command help"], [
|
|
19
19
|
"service",
|
|
20
20
|
"g s",
|
|
21
21
|
"Generate a service [controller, usecase, dto, module]",
|
|
22
|
-
], ["controller", "g c", "Generate a controller"], ["usecase", "g u", "Generate a usecase"], ["dto", "g d", "Generate a dto"], ["entity", "g e", "Generate an entity"], ["provider", "add", "Add provider to the project"], ["provider", "create", "Create
|
|
22
|
+
], ["controller", "g c", "Generate a controller"], ["usecase", "g u", "Generate a usecase"], ["dto", "g d", "Generate a dto"], ["entity", "g e", "Generate an entity"], ["provider", "g p", "Generate internal provider"], ["provider", "add", "Add external provider to the project"], ["provider", "create", "Create external provider"], ["module", "g mo", "Generate a module"], ["middleware", "g mi", "Generate a middleware"]);
|
|
23
23
|
console.log(chalk_1.default.bold.white("ExpressoTS:", `${chalk_1.default.green("Resources List")}`));
|
|
24
24
|
console.log(chalk_1.default.whiteBright(table.toString()));
|
|
25
25
|
console.log(chalk_1.default.bold.white(`📝 More info: ${chalk_1.default.green("https://doc.expresso-ts.com/docs/category/cli")}`));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scriptsCommand = void 0;
|
|
4
|
+
const form_1 = require("./form");
|
|
5
|
+
const scriptsCommand = () => {
|
|
6
|
+
return {
|
|
7
|
+
command: "scripts [scripts..]",
|
|
8
|
+
describe: "Run scripts list or specific scripts",
|
|
9
|
+
builder: (yargs) => {
|
|
10
|
+
return yargs.positional("scripts", {
|
|
11
|
+
describe: "The names of the scripts to run",
|
|
12
|
+
type: "string",
|
|
13
|
+
array: true,
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
handler: async (argv) => {
|
|
17
|
+
const scripts = Array.isArray(argv.scripts)
|
|
18
|
+
? argv.scripts.filter((script) => typeof script === "string")
|
|
19
|
+
: [];
|
|
20
|
+
await (0, form_1.scriptsForm)(scripts);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.scriptsCommand = scriptsCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const scriptsForm: (scriptArgs?: string[]) => Promise<void>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.scriptsForm = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const cli_ui_1 = require("../utils/cli-ui");
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const packageJsonPath = path_1.default.join(cwd, "package.json");
|
|
14
|
+
function readPackageJson() {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
(0, cli_ui_1.printError)(`Error reading package.json`, "scripts-command");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function listScripts(packageJson) {
|
|
24
|
+
const scripts = packageJson.scripts || {};
|
|
25
|
+
if (Object.keys(scripts).length === 0) {
|
|
26
|
+
(0, cli_ui_1.printWarning)("No scripts found in package.json", "scripts-command");
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
return scripts;
|
|
30
|
+
}
|
|
31
|
+
async function promptUserToSelectScripts(scripts) {
|
|
32
|
+
const scriptChoices = Object.keys(scripts).map((key) => ({
|
|
33
|
+
name: `${key}`,
|
|
34
|
+
value: key,
|
|
35
|
+
}));
|
|
36
|
+
let selectionOrder = [];
|
|
37
|
+
const answers = await inquirer_1.default.prompt([
|
|
38
|
+
{
|
|
39
|
+
type: "checkbox",
|
|
40
|
+
name: "selectedScripts",
|
|
41
|
+
message: "Select scripts to run:",
|
|
42
|
+
choices: scriptChoices,
|
|
43
|
+
filter: (selected) => {
|
|
44
|
+
selectionOrder = selected;
|
|
45
|
+
return selected;
|
|
46
|
+
},
|
|
47
|
+
loop: false,
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
return answers;
|
|
51
|
+
}
|
|
52
|
+
function executeScripts(scripts, selectedScripts, runner) {
|
|
53
|
+
selectedScripts.forEach((script) => {
|
|
54
|
+
console.log(`Running ${script}...`);
|
|
55
|
+
try {
|
|
56
|
+
const command = `${runner} run ${script}`;
|
|
57
|
+
const options = {
|
|
58
|
+
stdio: "inherit",
|
|
59
|
+
env: { ...process.env },
|
|
60
|
+
};
|
|
61
|
+
(0, child_process_1.execSync)(command, options);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
(0, cli_ui_1.printWarning)(`Command ${script} cancelled or failed - ${e}`, "scripts-command");
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
process.stdin.on("keypress", (ch, key) => {
|
|
69
|
+
if (key && key.name === "escape") {
|
|
70
|
+
console.log("Exiting...");
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const scriptsForm = async (scriptArgs = []) => {
|
|
75
|
+
const packageJson = readPackageJson();
|
|
76
|
+
const scripts = listScripts(packageJson);
|
|
77
|
+
const runner = fs_1.default.existsSync("package-lock.json")
|
|
78
|
+
? "npm"
|
|
79
|
+
: fs_1.default.existsSync("yarn.lock")
|
|
80
|
+
? "yarn"
|
|
81
|
+
: fs_1.default.existsSync("pnpm-lock.yaml")
|
|
82
|
+
? "pnpm"
|
|
83
|
+
: null;
|
|
84
|
+
if (!runner) {
|
|
85
|
+
(0, cli_ui_1.printError)("No package manager found! Please ensure you have npm, yarn, or pnpm installed.", "scripts-command");
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
if (scriptArgs.length > 0) {
|
|
89
|
+
const validScripts = scriptArgs.filter((script) => scripts[script]);
|
|
90
|
+
const invalidScripts = scriptArgs.filter((script) => !scripts[script]);
|
|
91
|
+
if (invalidScripts.length > 0) {
|
|
92
|
+
console.error(`Scripts not found in package.json: ${invalidScripts.join(", ")}`);
|
|
93
|
+
}
|
|
94
|
+
if (validScripts.length > 0) {
|
|
95
|
+
executeScripts(scripts, validScripts, runner);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const { selectedScripts } = await promptUserToSelectScripts(scripts);
|
|
100
|
+
if (selectedScripts.length === 0) {
|
|
101
|
+
console.log("No scripts selected.");
|
|
102
|
+
process.exit(0);
|
|
103
|
+
}
|
|
104
|
+
executeScripts(scripts, selectedScripts, runner);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.scriptsForm = scriptsForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cli";
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cli"), exports);
|