@expressots/cli 1.0.0 → 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/LICENSE.md +21 -0
- package/bin/cli.d.ts +2 -0
- package/bin/cli.js +16 -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 +3 -5
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 expressots
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/cli.d.ts
ADDED
package/bin/cli.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const helpers_1 = require("yargs/helpers");
|
|
9
|
+
const new_1 = require("./new");
|
|
10
|
+
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
11
|
+
.example("$0 new <project-name>", "Create a new Expresso TS project")
|
|
12
|
+
.command((0, new_1.createProject)())
|
|
13
|
+
.demandCommand(1, "You need at least one command before moving on")
|
|
14
|
+
.epilog("For more information, visit https://expresso-ts.com")
|
|
15
|
+
.help()
|
|
16
|
+
.parse();
|
|
@@ -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",
|
|
@@ -37,11 +37,9 @@
|
|
|
37
37
|
"build": "npm run clean && tsc -p tsconfig.json && chmod +x ./bin/cli.js",
|
|
38
38
|
"clean": "rimraf ./bin",
|
|
39
39
|
"lint": "eslint .eslintrc.js --ext .ts,.tsx,.js,.jsx .",
|
|
40
|
-
"release": "release-it"
|
|
40
|
+
"release": "release-it",
|
|
41
|
+
"prepare": "husky install"
|
|
41
42
|
},
|
|
42
|
-
"files": [
|
|
43
|
-
"bin/cli.js"
|
|
44
|
-
],
|
|
45
43
|
"dependencies": {
|
|
46
44
|
"chalk-animation": "^1",
|
|
47
45
|
"cli-progress": "^3.11.2",
|