@expressots/cli 1.0.1 → 1.0.2
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 +2 -0
- package/bin/new/index.d.ts +1 -0
- package/bin/new/index.js +17 -0
- package/bin/new/project-cli.d.ts +4 -0
- package/bin/new/project-cli.js +21 -0
- package/bin/new/project-ui.d.ts +2 -0
- package/bin/new/project-ui.js +135 -0
- package/package.json +1 -4
package/bin/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./project-cli";
|
package/bin/new/index.js
ADDED
|
@@ -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("./project-cli"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProject = void 0;
|
|
4
|
+
const project_ui_1 = require("./project-ui");
|
|
5
|
+
const createProject = () => {
|
|
6
|
+
return {
|
|
7
|
+
command: "new [project-name]",
|
|
8
|
+
describe: "Create a new Expresso TS project",
|
|
9
|
+
builder: (yargs) => {
|
|
10
|
+
yargs.positional("project-name", {
|
|
11
|
+
describe: "The name of the project",
|
|
12
|
+
type: "string",
|
|
13
|
+
});
|
|
14
|
+
return yargs;
|
|
15
|
+
},
|
|
16
|
+
handler: async ({ projectName }) => {
|
|
17
|
+
return await (0, project_ui_1.projectForm)(projectName);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.createProject = createProject;
|
|
@@ -0,0 +1,135 @@
|
|
|
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.projectForm = void 0;
|
|
7
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const degit_1 = __importDefault(require("degit"));
|
|
10
|
+
const child_process_1 = require("child_process");
|
|
11
|
+
const cli_progress_1 = require("cli-progress");
|
|
12
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
async function packageManagerInstall({ packageManager, directory, progressBar, }) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const isWindows = process.platform === "win32";
|
|
17
|
+
const command = isWindows ? `${packageManager}.cmd` : packageManager;
|
|
18
|
+
//const args = isWindows ? [packageManager, "install"] : ["install"];
|
|
19
|
+
const installProcess = (0, child_process_1.spawn)(command, ["install"], {
|
|
20
|
+
cwd: directory,
|
|
21
|
+
});
|
|
22
|
+
installProcess.stdout.on("data", (data) => {
|
|
23
|
+
progressBar.increment(5, {
|
|
24
|
+
doing: `${data.toString().trim()}`,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
installProcess.on("close", (code) => {
|
|
28
|
+
if (code === 0) {
|
|
29
|
+
resolve("Installation Done!");
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
reject(new Error(`npm install exited with code ${code}`));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async function checkIfPackageManagerExists(packageManager) {
|
|
38
|
+
try {
|
|
39
|
+
(0, child_process_1.execSync)(`${packageManager} --version`);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch (_) {
|
|
43
|
+
throw new Error(`Package manager ${packageManager} is not installed`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Change the package.json name to the user's project name
|
|
47
|
+
function changePackageName({ directory, name, }) {
|
|
48
|
+
// Get the absolute path of the input directory parameter
|
|
49
|
+
const absDirPath = node_path_1.default.resolve(directory);
|
|
50
|
+
// Load the package.json file
|
|
51
|
+
const packageJsonPath = node_path_1.default.join(absDirPath, "package.json");
|
|
52
|
+
const fileContents = node_fs_1.default.readFileSync(packageJsonPath, "utf-8");
|
|
53
|
+
const packageJson = JSON.parse(fileContents);
|
|
54
|
+
// Change the name
|
|
55
|
+
packageJson.name = name;
|
|
56
|
+
// Save the package.json file
|
|
57
|
+
node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
58
|
+
}
|
|
59
|
+
const projectForm = async (projectName) => {
|
|
60
|
+
const answer = await inquirer_1.default.prompt([
|
|
61
|
+
{
|
|
62
|
+
type: "input",
|
|
63
|
+
name: "name",
|
|
64
|
+
message: "Project name",
|
|
65
|
+
default: projectName,
|
|
66
|
+
transformer: (input) => {
|
|
67
|
+
return chalk_1.default.yellow(chalk_1.default.bold(input));
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "list",
|
|
72
|
+
name: "packageManager",
|
|
73
|
+
message: "Package manager",
|
|
74
|
+
choices: ["npm", "yarn", "pnpm"],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: "list",
|
|
78
|
+
name: "template",
|
|
79
|
+
message: "Select a template",
|
|
80
|
+
choices: [
|
|
81
|
+
"Non-Opinionated :: A simple ExpressoTS project.",
|
|
82
|
+
"Opinionated :: A complete ExpressoTS project with an opinionated structure and features.",
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "confirm",
|
|
87
|
+
name: "confirm",
|
|
88
|
+
message: "Do you want to create this project?",
|
|
89
|
+
default: true,
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
// Hashmap of templates and their directories
|
|
93
|
+
const templates = {
|
|
94
|
+
"Non-Opinionated": "non_opinionated",
|
|
95
|
+
"Opinionated": "opinionated",
|
|
96
|
+
};
|
|
97
|
+
if (answer.confirm) {
|
|
98
|
+
// Check if the package manager exists
|
|
99
|
+
await checkIfPackageManagerExists(answer.packageManager).catch((err) => {
|
|
100
|
+
console.log(chalk_1.default.red(err.message));
|
|
101
|
+
process.exit(1);
|
|
102
|
+
});
|
|
103
|
+
const progressBar = new cli_progress_1.SingleBar({
|
|
104
|
+
format: "Progress |" + chalk_1.default.green("{bar}") + "| {percentage}% || {doing}",
|
|
105
|
+
hideCursor: true,
|
|
106
|
+
}, cli_progress_1.Presets.shades_classic);
|
|
107
|
+
progressBar.start(100, 0, {
|
|
108
|
+
doing: "Cloning project",
|
|
109
|
+
});
|
|
110
|
+
const [_, template] = answer.template.match(/(.*) ::/);
|
|
111
|
+
const emitter = (0, degit_1.default)(`expressots/expressots/templates/${templates[template]}`);
|
|
112
|
+
await emitter.clone(answer.name);
|
|
113
|
+
progressBar.update(50, {
|
|
114
|
+
doing: "Installing dependencies",
|
|
115
|
+
});
|
|
116
|
+
// Run the package manager install in the directory
|
|
117
|
+
await packageManagerInstall({
|
|
118
|
+
packageManager: answer.packageManager,
|
|
119
|
+
directory: answer.name,
|
|
120
|
+
progressBar,
|
|
121
|
+
});
|
|
122
|
+
progressBar.update(90);
|
|
123
|
+
changePackageName({
|
|
124
|
+
directory: answer.name,
|
|
125
|
+
name: answer.name,
|
|
126
|
+
});
|
|
127
|
+
progressBar.update(100);
|
|
128
|
+
progressBar.stop();
|
|
129
|
+
console.log(chalk_1.default.green("Project created successfully!"));
|
|
130
|
+
console.log("Run the following commands to start the project:");
|
|
131
|
+
console.log(chalk_1.default.bold(`cd ${answer.name}`));
|
|
132
|
+
console.log(chalk_1.default.bold(`${answer.packageManager} start`));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
exports.projectForm = projectForm;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,9 +40,6 @@
|
|
|
40
40
|
"release": "release-it",
|
|
41
41
|
"prepare": "husky install"
|
|
42
42
|
},
|
|
43
|
-
"files": [
|
|
44
|
-
"bin/cli.js"
|
|
45
|
-
],
|
|
46
43
|
"dependencies": {
|
|
47
44
|
"chalk-animation": "^1",
|
|
48
45
|
"cli-progress": "^3.11.2",
|