@expressots/cli 1.11.1 → 3.0.0-beta.1
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.d.ts +5 -1
- package/bin/cli.js +9 -1
- package/bin/commands/project.commands.js +4 -15
- package/bin/generate/templates/nonopinionated/module.tpl +1 -2
- package/bin/generate/templates/opinionated/controller-service-delete.tpl +6 -14
- package/bin/generate/templates/opinionated/controller-service-get.tpl +7 -15
- package/bin/generate/templates/opinionated/controller-service-patch.tpl +7 -17
- package/bin/generate/templates/opinionated/controller-service-post.tpl +7 -14
- package/bin/generate/templates/opinionated/controller-service-put.tpl +7 -17
- package/bin/generate/templates/opinionated/controller-service.tpl +1 -2
- package/bin/generate/templates/opinionated/module-service.tpl +1 -2
- package/bin/generate/templates/opinionated/module.tpl +1 -2
- package/bin/generate/utils/command-utils.d.ts +1 -1
- package/bin/generate/utils/command-utils.js +12 -12
- package/bin/generate/utils/nonopininated-cmd.d.ts +1 -1
- package/bin/generate/utils/nonopininated-cmd.js +12 -12
- package/bin/generate/utils/opinionated-cmd.d.ts +1 -1
- package/bin/generate/utils/opinionated-cmd.js +12 -12
- package/bin/generate/utils/string-utils.d.ts +36 -0
- package/bin/generate/utils/string-utils.js +71 -0
- package/bin/help/form.js +6 -2
- package/bin/index.d.ts +0 -1
- package/bin/index.js +0 -1
- package/bin/info/form.js +3 -13
- package/bin/new/form.js +37 -21
- package/bin/providers/add/cli.d.ts +1 -0
- package/bin/providers/add/cli.js +27 -4
- package/bin/providers/add/form.d.ts +2 -1
- package/bin/providers/add/form.js +72 -39
- package/bin/providers/create/form.js +1 -1
- 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/{@types → scripts}/index.js +1 -1
- package/bin/utils/add-module-to-container.js +16 -11
- package/bin/utils/compiler.d.ts +1 -1
- package/package.json +19 -20
- package/bin/@types/config.d.ts +0 -39
- package/bin/@types/config.js +0 -2
- package/bin/@types/index.d.ts +0 -1
- package/bin/app.container.d.ts +0 -1
- package/bin/app.container.js +0 -8
- package/bin/commands/__tests__/project.commands.spec.d.ts +0 -1
- package/bin/commands/__tests__/project.commands.spec.js +0 -8
- package/bin/types.d.ts +0 -1
- package/bin/types.js +0 -17
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.anyCaseToLowerCase = exports.anyCaseToUpperCase = exports.anyCaseToSnakeCase = exports.anyCaseToPascalCase = exports.anyCaseToKebabCase = exports.anyCaseToCamelCase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to camelCase.
|
|
6
|
+
* @param str - The input string to be converted.
|
|
7
|
+
* @returns The converted string in camelCase.
|
|
8
|
+
*/
|
|
9
|
+
function anyCaseToCamelCase(str) {
|
|
10
|
+
return str
|
|
11
|
+
.replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
|
12
|
+
.replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
exports.anyCaseToCamelCase = anyCaseToCamelCase;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to kebab-case.
|
|
17
|
+
* @param str - The input string to be converted.
|
|
18
|
+
* @returns The converted string in kebab-case.
|
|
19
|
+
*/
|
|
20
|
+
function anyCaseToKebabCase(str) {
|
|
21
|
+
return str
|
|
22
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2") // Convert camelCase and PascalCase to kebab-case
|
|
23
|
+
.replace(/_/g, "-") // Convert snake_case to kebab-case
|
|
24
|
+
.toLowerCase(); // Ensure all characters are lowercase
|
|
25
|
+
}
|
|
26
|
+
exports.anyCaseToKebabCase = anyCaseToKebabCase;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to PascalCase.
|
|
29
|
+
* @param str - The input string to be converted.
|
|
30
|
+
* @returns The converted string in PascalCase.
|
|
31
|
+
*/
|
|
32
|
+
function anyCaseToPascalCase(str) {
|
|
33
|
+
return str
|
|
34
|
+
.replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
|
35
|
+
.replace(/^[a-z]/, (char) => char.toUpperCase());
|
|
36
|
+
}
|
|
37
|
+
exports.anyCaseToPascalCase = anyCaseToPascalCase;
|
|
38
|
+
/**
|
|
39
|
+
* Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to snake_case.
|
|
40
|
+
* @param str - The input string to be converted.
|
|
41
|
+
* @returns The converted string in snake_case.
|
|
42
|
+
*/
|
|
43
|
+
function anyCaseToSnakeCase(str) {
|
|
44
|
+
return str
|
|
45
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
46
|
+
.replace(/[-]+/g, "_")
|
|
47
|
+
.toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
exports.anyCaseToSnakeCase = anyCaseToSnakeCase;
|
|
50
|
+
/**
|
|
51
|
+
* Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to UPPER CASE.
|
|
52
|
+
* @param str - The input string to be converted.
|
|
53
|
+
* @returns The converted string in UPPER CASE.
|
|
54
|
+
*/
|
|
55
|
+
function anyCaseToUpperCase(str) {
|
|
56
|
+
return str
|
|
57
|
+
.replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
|
58
|
+
.toUpperCase();
|
|
59
|
+
}
|
|
60
|
+
exports.anyCaseToUpperCase = anyCaseToUpperCase;
|
|
61
|
+
/**
|
|
62
|
+
* Converts a string from any case (camelCase, PascalCase, kebab-case, snake_case) to lower case.
|
|
63
|
+
* @param str - The input string to be converted.
|
|
64
|
+
* @returns The converted string in lower case.
|
|
65
|
+
*/
|
|
66
|
+
function anyCaseToLowerCase(str) {
|
|
67
|
+
return str
|
|
68
|
+
.replace(/[-_]+(.)?/g, (_, char) => (char ? char.toLowerCase() : ""))
|
|
69
|
+
.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
exports.anyCaseToLowerCase = anyCaseToLowerCase;
|
package/bin/help/form.js
CHANGED
|
@@ -15,11 +15,15 @@ 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", "g p", "Generate internal provider"], [
|
|
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"], [
|
|
23
|
+
"provider",
|
|
24
|
+
"add",
|
|
25
|
+
"Add provider to the project. Use -d to add as dev dependency",
|
|
26
|
+
], ["provider", "remove", "Remove provider from the project"], ["provider", "create", "Create external provider"], ["module", "g mo", "Generate a module"], ["middleware", "g mi", "Generate a middleware"]);
|
|
23
27
|
console.log(chalk_1.default.bold.white("ExpressoTS:", `${chalk_1.default.green("Resources List")}`));
|
|
24
28
|
console.log(chalk_1.default.whiteBright(table.toString()));
|
|
25
29
|
console.log(chalk_1.default.bold.white(`📝 More info: ${chalk_1.default.green("https://doc.expresso-ts.com/docs/category/cli")}`));
|
package/bin/index.d.ts
CHANGED
package/bin/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
17
|
__exportStar(require("./generate"), exports);
|
|
19
18
|
__exportStar(require("./utils"), exports);
|
|
20
19
|
__exportStar(require("./new"), exports);
|
package/bin/info/form.js
CHANGED
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.infoForm = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const cli_1 = require("../cli");
|
|
11
12
|
const cli_ui_1 = require("../utils/cli-ui");
|
|
12
|
-
const axios_1 = __importDefault(require("axios"));
|
|
13
13
|
function getInfosFromPackage() {
|
|
14
14
|
try {
|
|
15
15
|
// Get the absolute path of the input directory parameter
|
|
@@ -33,16 +33,6 @@ const infoForm = () => {
|
|
|
33
33
|
console.log(chalk_1.default.green("System information:"));
|
|
34
34
|
console.log(chalk_1.default.white(`\tOS Version: ${os_1.default.version()}`));
|
|
35
35
|
console.log(chalk_1.default.white(`\tNodeJS version: ${process.version}`));
|
|
36
|
-
|
|
36
|
+
(0, cli_ui_1.printSuccess)("CLI version:", cli_1.BUNDLE_VERSION);
|
|
37
37
|
};
|
|
38
38
|
exports.infoForm = infoForm;
|
|
39
|
-
async function currentCLIVersion() {
|
|
40
|
-
try {
|
|
41
|
-
const response = await axios_1.default.get("https://api.github.com/repos/expressots/expressots-cli/releases");
|
|
42
|
-
const latestRelease = `v${response.data[0].tag_name}`;
|
|
43
|
-
(0, cli_ui_1.printSuccess)("CLI version:", latestRelease);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
(0, cli_ui_1.printError)("Error:", error.message);
|
|
47
|
-
}
|
|
48
|
-
}
|
package/bin/new/form.js
CHANGED
|
@@ -14,48 +14,64 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
14
14
|
const center_text_1 = require("../utils/center-text");
|
|
15
15
|
const cli_ui_1 = require("../utils/cli-ui");
|
|
16
16
|
const change_package_info_1 = require("../utils/change-package-info");
|
|
17
|
+
const cli_1 = require("../cli");
|
|
17
18
|
async function packageManagerInstall({ packageManager, directory, progressBar, }) {
|
|
19
|
+
const command = process.platform === "win32" ? `${packageManager}.cmd` : packageManager;
|
|
20
|
+
const args = ["install", "--prefer-offline", "--silent"];
|
|
21
|
+
if (packageManager === "yarn") {
|
|
22
|
+
args.push("--ignore-engines");
|
|
23
|
+
args.splice(args.indexOf("--prefer-offline"), 1);
|
|
24
|
+
}
|
|
18
25
|
return new Promise((resolve, reject) => {
|
|
19
|
-
const
|
|
20
|
-
const command = isWindows
|
|
21
|
-
? `${packageManager}.cmd`
|
|
22
|
-
: packageManager;
|
|
23
|
-
const installProcess = (0, node_child_process_1.spawn)(command, ["install", "--prefer-offline"], {
|
|
26
|
+
const installProcess = (0, node_child_process_1.spawn)(command, args, {
|
|
24
27
|
cwd: directory,
|
|
25
28
|
shell: true,
|
|
26
29
|
timeout: 600000,
|
|
27
30
|
});
|
|
28
|
-
//
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// Simulate incremental progress
|
|
32
|
+
let progress = 0;
|
|
33
|
+
const interval = setInterval(() => {
|
|
34
|
+
if (progress < 90) {
|
|
35
|
+
progress += 5;
|
|
36
|
+
progressBar.update(progress);
|
|
37
|
+
}
|
|
38
|
+
}, 1000);
|
|
39
|
+
// Handle stdout for meaningful output or progress feedback
|
|
34
40
|
installProcess.stdout?.on("data", (data) => {
|
|
35
41
|
const output = data.toString().trim();
|
|
36
|
-
|
|
42
|
+
// Remove all data from || to the end of the line
|
|
43
|
+
const cleanedOutput = output.replace(/\|\|.*$/g, "");
|
|
44
|
+
// Match and handle npm-specific progress
|
|
45
|
+
const npmProgressMatch = cleanedOutput.match(/\[(\d+)\/(\d+)\] (?:npm )?([\w\s]+)\.{3}/);
|
|
37
46
|
if (npmProgressMatch) {
|
|
38
47
|
const [, current, total, task] = npmProgressMatch;
|
|
39
|
-
|
|
48
|
+
progress = Math.round((parseInt(current) / parseInt(total)) * 100);
|
|
40
49
|
progressBar.update(progress, { doing: task });
|
|
41
50
|
}
|
|
42
51
|
else {
|
|
43
|
-
|
|
52
|
+
// Update "task" without changing the progress
|
|
53
|
+
progressBar.update(progress, { doing: cleanedOutput });
|
|
44
54
|
}
|
|
45
55
|
});
|
|
56
|
+
// Handle errors
|
|
57
|
+
installProcess.on("error", (error) => {
|
|
58
|
+
clearInterval(interval); // Stop interval on error
|
|
59
|
+
progressBar.stop();
|
|
60
|
+
reject(new Error(`Failed to start subprocess: ${error.message}`));
|
|
61
|
+
});
|
|
62
|
+
// Finalize progress on close
|
|
46
63
|
installProcess.on("close", (code) => {
|
|
47
|
-
|
|
64
|
+
clearInterval(interval); // Stop interval when the process ends
|
|
48
65
|
if (code === 0) {
|
|
66
|
+
progressBar.update(100, { doing: "Complete!" }); // Finalize progress
|
|
67
|
+
progressBar.stop();
|
|
49
68
|
resolve("Installation Done!");
|
|
50
69
|
}
|
|
51
70
|
else {
|
|
71
|
+
progressBar.stop();
|
|
52
72
|
reject(new Error(`${packageManager} install exited with code ${code}`));
|
|
53
73
|
}
|
|
54
74
|
});
|
|
55
|
-
installTimeout = setTimeout(() => {
|
|
56
|
-
installProcess.kill("SIGKILL");
|
|
57
|
-
reject(new Error("Installation took too long. Aborted!"));
|
|
58
|
-
}, 600000);
|
|
59
75
|
});
|
|
60
76
|
}
|
|
61
77
|
async function checkIfPackageManagerExists(packageManager) {
|
|
@@ -164,8 +180,9 @@ const projectForm = async (projectName, args) => {
|
|
|
164
180
|
doing: "Cloning project",
|
|
165
181
|
});
|
|
166
182
|
const [_, template] = answer.template.match(/(.*) ::/);
|
|
183
|
+
const repo = `expressots/templates/${templates[template]}#${cli_1.BUNDLE_VERSION}`;
|
|
167
184
|
try {
|
|
168
|
-
const emitter = (0, degit_1.default)(`expressots/
|
|
185
|
+
const emitter = (0, degit_1.default)(`expressots/templates/${templates[template]}`);
|
|
169
186
|
await emitter.clone(answer.name);
|
|
170
187
|
}
|
|
171
188
|
catch (err) {
|
|
@@ -186,7 +203,6 @@ const projectForm = async (projectName, args) => {
|
|
|
186
203
|
directory: answer.name,
|
|
187
204
|
name: projectName,
|
|
188
205
|
});
|
|
189
|
-
renameEnvFile(answer.name);
|
|
190
206
|
progressBar.update(100);
|
|
191
207
|
progressBar.stop();
|
|
192
208
|
console.log("\n");
|
package/bin/providers/add/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addProviderCMD = void 0;
|
|
3
|
+
exports.removeProviderCMD = exports.addProviderCMD = void 0;
|
|
4
4
|
const form_1 = require("./form");
|
|
5
5
|
const addProviderCMD = () => {
|
|
6
6
|
return {
|
|
@@ -15,14 +15,37 @@ const addProviderCMD = () => {
|
|
|
15
15
|
.option("version", {
|
|
16
16
|
describe: "The provider version to be installed",
|
|
17
17
|
type: "string",
|
|
18
|
-
default:
|
|
18
|
+
default: false,
|
|
19
19
|
alias: "v",
|
|
20
|
+
})
|
|
21
|
+
.option("dev", {
|
|
22
|
+
describe: "Add provider as a dev dependency",
|
|
23
|
+
type: "boolean",
|
|
24
|
+
default: false,
|
|
25
|
+
alias: "d",
|
|
20
26
|
});
|
|
21
27
|
return yargs;
|
|
22
28
|
},
|
|
23
|
-
handler: async ({ provider, version }) => {
|
|
24
|
-
await (0, form_1.
|
|
29
|
+
handler: async ({ provider, version, dev }) => {
|
|
30
|
+
await (0, form_1.addProvider)(provider, version, dev);
|
|
25
31
|
},
|
|
26
32
|
};
|
|
27
33
|
};
|
|
28
34
|
exports.addProviderCMD = addProviderCMD;
|
|
35
|
+
const removeProviderCMD = () => {
|
|
36
|
+
return {
|
|
37
|
+
command: "remove <provider>",
|
|
38
|
+
describe: "Remove provider from the project.",
|
|
39
|
+
builder: (yargs) => {
|
|
40
|
+
yargs.positional("provider", {
|
|
41
|
+
describe: "The provider to be removed from the project",
|
|
42
|
+
type: "string",
|
|
43
|
+
});
|
|
44
|
+
return yargs;
|
|
45
|
+
},
|
|
46
|
+
handler: async ({ provider: packageName }) => {
|
|
47
|
+
await (0, form_1.removeProvider)(packageName);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.removeProviderCMD = removeProviderCMD;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function addProvider(packageName: string, version?: string, isDevDependency?: boolean): Promise<void>;
|
|
2
|
+
export declare function removeProvider(packageName: string): Promise<void>;
|
|
@@ -3,66 +3,99 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.removeProvider = exports.addProvider = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const node_child_process_1 = require("node:child_process");
|
|
9
9
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
10
|
const node_process_1 = require("node:process");
|
|
11
11
|
const cli_ui_1 = require("../../utils/cli-ui");
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const PACKAGE_MANAGERS = {
|
|
13
|
+
npm: {
|
|
14
|
+
install: "install",
|
|
15
|
+
addDev: "install --save-dev",
|
|
16
|
+
remove: "uninstall",
|
|
17
|
+
},
|
|
18
|
+
yarn: {
|
|
19
|
+
install: "add",
|
|
20
|
+
addDev: "add --dev",
|
|
21
|
+
remove: "remove",
|
|
22
|
+
},
|
|
23
|
+
pnpm: {
|
|
24
|
+
install: "add",
|
|
25
|
+
addDev: "add --save-dev",
|
|
26
|
+
remove: "remove",
|
|
27
|
+
},
|
|
14
28
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
? "pnpm"
|
|
23
|
-
: null;
|
|
24
|
-
if (packageManager) {
|
|
25
|
-
console.log(`Installing ${provider} provider ...`);
|
|
26
|
-
const currentVersion = version === "latest" ? "" : `@${version}`;
|
|
27
|
-
await execProcess({
|
|
28
|
-
commandArg: packageManager,
|
|
29
|
-
args: ["add", `${provider}${currentVersion}`, "--prefer-offline"],
|
|
30
|
-
directory: process.cwd(),
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
(0, cli_ui_1.printError)("No package manager found in the project", "install-provider");
|
|
35
|
-
return;
|
|
29
|
+
function detectPackageManager() {
|
|
30
|
+
const lockFiles = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
31
|
+
const managers = Object.keys(PACKAGE_MANAGERS);
|
|
32
|
+
for (let i = 0; i < lockFiles.length; i++) {
|
|
33
|
+
if (node_fs_1.default.existsSync(lockFiles[i])) {
|
|
34
|
+
return managers[i];
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
|
+
return null;
|
|
37
38
|
}
|
|
38
|
-
async function execProcess({
|
|
39
|
+
async function execProcess({ command, args, directory, }) {
|
|
39
40
|
return new Promise((resolve, reject) => {
|
|
40
41
|
const isWindows = process.platform === "win32";
|
|
41
|
-
const
|
|
42
|
-
const
|
|
42
|
+
const execCommand = isWindows ? `${command}.cmd` : command;
|
|
43
|
+
const processRunner = (0, node_child_process_1.spawn)(execCommand, args, {
|
|
43
44
|
cwd: directory,
|
|
44
45
|
shell: true,
|
|
45
46
|
});
|
|
46
|
-
console.log(chalk_1.default.bold.blue(`Executing: ${
|
|
47
|
+
console.log(chalk_1.default.bold.blue(`Executing: ${command} ${args.join(" ")}`));
|
|
47
48
|
console.log(chalk_1.default.yellow("-------------------------------------------------"));
|
|
48
|
-
|
|
49
|
-
console.log(chalk_1.default.green(data.toString().trim()));
|
|
49
|
+
processRunner.stdout.on("data", (data) => {
|
|
50
|
+
console.log(chalk_1.default.green(data.toString().trim()));
|
|
50
51
|
});
|
|
51
|
-
|
|
52
|
-
console.error(chalk_1.default.red(data.toString().trim()));
|
|
52
|
+
processRunner.stderr.on("data", (data) => {
|
|
53
|
+
console.error(chalk_1.default.red(data.toString().trim()));
|
|
53
54
|
});
|
|
54
|
-
|
|
55
|
+
processRunner.on("close", (code) => {
|
|
55
56
|
if (code === 0) {
|
|
56
|
-
console.log(chalk_1.default.bold.green("
|
|
57
|
-
|
|
58
|
-
resolve("Installation Done!");
|
|
57
|
+
console.log(chalk_1.default.bold.green("Operation completed successfully!\n"));
|
|
58
|
+
resolve();
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
console.error(chalk_1.default.bold.red(
|
|
62
|
-
|
|
63
|
-
reject(new Error(`Command ${command} ${args.join(" ")} exited with code ${code}`));
|
|
61
|
+
console.error(chalk_1.default.bold.red(`Command failed with exit code ${code}`));
|
|
62
|
+
reject(new Error(`Command failed with exit code ${code}`));
|
|
64
63
|
(0, node_process_1.exit)(1);
|
|
65
64
|
}
|
|
66
65
|
});
|
|
67
66
|
});
|
|
68
67
|
}
|
|
68
|
+
async function addProvider(packageName, version, isDevDependency = false) {
|
|
69
|
+
const packageManager = detectPackageManager();
|
|
70
|
+
if (!packageManager) {
|
|
71
|
+
(0, cli_ui_1.printError)("No package manager found in the project", "add-package");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const pkgManagerConfig = PACKAGE_MANAGERS[packageManager];
|
|
75
|
+
const command = isDevDependency
|
|
76
|
+
? pkgManagerConfig.addDev
|
|
77
|
+
: pkgManagerConfig.install;
|
|
78
|
+
const versionSuffix = version && version !== "latest" ? `@${version}` : "";
|
|
79
|
+
console.log(`${isDevDependency ? "Adding devDependency" : "Installing"} ${packageName}...`);
|
|
80
|
+
await execProcess({
|
|
81
|
+
command: packageManager,
|
|
82
|
+
args: [...command.split(" "), `${packageName}${versionSuffix}`],
|
|
83
|
+
directory: process.cwd(),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.addProvider = addProvider;
|
|
87
|
+
async function removeProvider(packageName) {
|
|
88
|
+
const packageManager = detectPackageManager();
|
|
89
|
+
if (!packageManager) {
|
|
90
|
+
(0, cli_ui_1.printError)("No package manager found in the project", "remove-package");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const command = PACKAGE_MANAGERS[packageManager].remove;
|
|
94
|
+
console.log(`Removing ${packageName}...`);
|
|
95
|
+
await execProcess({
|
|
96
|
+
command: packageManager,
|
|
97
|
+
args: [...command.split(" "), packageName],
|
|
98
|
+
directory: process.cwd(),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.removeProvider = removeProvider;
|
|
@@ -39,7 +39,7 @@ const createExternalProvider = async (provider) => {
|
|
|
39
39
|
]);
|
|
40
40
|
}
|
|
41
41
|
try {
|
|
42
|
-
const emitter = (0, degit_1.default)(`expressots/
|
|
42
|
+
const emitter = (0, degit_1.default)(`expressots/templates/provider`);
|
|
43
43
|
await emitter.clone(providerInfo.providerName);
|
|
44
44
|
(0, change_package_info_1.changePackageName)({
|
|
45
45
|
directory: providerInfo.providerName,
|
|
@@ -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";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./cli"), exports);
|