Skip to content

Commit 46c6403

Browse files
committed
Add CLI utility for creating boilerplate project and update package.json with new bin command in create-nodejs-express-sequelize-mysql-api-boilerplate in @karinca/nodejs-express-sequelize-mysql-api-boilerplate
1 parent a9fd7d5 commit 46c6403

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

bin/cli.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
const { execSync } = require('child_process');
3+
4+
const runCommand = command => {
5+
try {
6+
execSync(`${command}`, { stdio: 'inherit' });
7+
} catch (e) {
8+
console.error('Failed to execute ${command}', e);
9+
return false;
10+
}
11+
return true;
12+
};
13+
14+
const repoName = process.argv[2];
15+
const gitCheckoutCommand = `git clone --depth 1 https://github.com/gulalicelik/nodejs-express-sequelize-mysql-api-boilerplate.git ${repoName}`;
16+
const installDepsCommand = `cd ${repoName} && npm install`;
17+
18+
console.log(`Cloning the repository with name ${repoName}`);
19+
const checkedOut = runCommand(gitCheckoutCommand);
20+
if (!checkedOut) process.exit(-1);
21+
22+
console.log(`Installing dependencies for ${repoName}`);
23+
const installedDeps = runCommand(installDepsCommand);
24+
if (!installedDeps) process.exit(-1);
25+
26+
console.log(
27+
'Congratulations! You are ready. Follow the following commands to start'
28+
);
29+
console.log(`cd ${repoName} && npm start`);

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "nodejs-express-sequelize-mysql-api-boilerplate",
2+
"name": "@karinca/nodejs-express-sequelize-mysql-api-boilerplate",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
@@ -10,6 +10,9 @@
1010
"start:prod": "pm2 start --env prod",
1111
"test": "echo \"Error: no test specified\" && exit 1"
1212
},
13+
"bin" : {
14+
"create-nodejs-express-sequelize-mysql-api-boilerplate" : "./bin/cli.js"
15+
},
1316
"repository": {
1417
"type": "git",
1518
"url": "git+https://github.com/gulalicelik/nodejs-express-sequelize-mysql-api-boilerplate.git"

0 commit comments

Comments
 (0)