create-nest-app
Version:
Create Nest App Starter
52 lines (41 loc) • 1.47 kB
JavaScript
const vorpal = require('vorpal')();
const { spawn, exec } = require('child_process');
const commandExists = require('command-exists');
const async = require("async");
const repo = 'https://github.com/Vivify-Ideas/nestjs-boilerplate.git';
async function checkCommandsExistence(commands) {
return new Promise((resolve, error) => {
commands.forEach((command, index) => {
commandExists(command, function(err, commandExists) {
if (!commandExists) {
error(new Error(`Not found command ${command}...`));
}
if (commandExists && index === commands.length - 1) {
resolve();
}
});
})
});
}
vorpal
.command('create <name>', 'Create Nest App')
.action(async (arguments) => {
const projectPath = `${__dirname}/${arguments.name}`;
vorpal.log(`Creating Nest application <${arguments.name}>...`);
await checkCommandsExistence([ 'git', 'npm', 'rm' ]);
await new Promise((resolve, error) => {
return async.series([
async.apply(exec, `git clone ${repo} ${arguments.name}`),
async.apply(exec, `rm -rf ${projectPath}/.git`),
async.apply(exec, `cp ${projectPath}/.env.example ${projectPath}/.env`),
async.apply(spawn, 'npm', ['install'], { cwd: projectPath }),
], (err, results) => {
resolve(results);
});
});
vorpal.ui.cancel();
});
vorpal
.show()
.parse(process.argv);