nestjs-starter-kit
Version:
NPM command to scaffold Nest Starter Kit
46 lines (39 loc) • 1.29 kB
JavaScript
import { execSync } from "child_process";
import chalk from "chalk";
const enteredDirName = process.argv[2];
if (!enteredDirName) {
console.log(chalk.red("Hyphenated project name is required."));
process.exit(-1);
}
/**
* Function to execute cli command synchronously
*
* @param {string} command - cli command
* @returns boolean
*/
function execCommand(command) {
try {
execSync(`${command}`, { stdio: "inherit" });
return true;
} catch (error) {
console.error(`Failed to execute command ${command}`, error);
return false;
}
}
const RUN_COMMAND = {
CLONE: `git clone https://github.com/latreon/nest-starter-kit ${enteredDirName}`,
INSTALL_DEPENDENCIES: `cd ${enteredDirName} && npm install`,
};
console.log(
chalk.green(`Creating ${enteredDirName} folder with the NestJS Starter Kit template code`)
);
if (!execCommand(RUN_COMMAND.CLONE)) process.exit(-1);
if (!execCommand(RUN_COMMAND.INSTALL_DEPENDENCIES)) {
console.error(chalk.yellow("Failed to install dependencies. Please do it manually."));
} else {
console.log(chalk.green("Installed the dependencies ✅"));
}
console.log(chalk.green("Successfully created 🎉!"));
console.log(chalk.blue("Happy coding 💻"));
process.exit(0);