UNPKG

@ou-imdt/create

Version:

Command line tool to create team boilerplate.

45 lines (40 loc) 1.47 kB
const process = require('process') const ora = require('ora') const path = require('path') const execa = require('execa') const alert = require('cli-alerts') const copy = require('copy-template-dir') const { green: g, yellow: y, dim: d } = require('chalk') const spinner = ora({ text: '' }) const templateVars = require('./template-vars') const questions = require('./questions') module.exports = async () => { const promptResponses = await questions() const userVars = await templateVars() const outDir = promptResponses.name const inDirPath = path.join(__dirname, `../boilerplate/${promptResponses.template}`) const outDirPath = path.join(process.cwd(), outDir) const vars = { ...userVars, ...promptResponses } copy(inDirPath, outDirPath, vars, async err => { if (err) throw err if (vars.installDeps) { spinner.start(`${y(`Installing dependencies`)}`) process.chdir(outDirPath) await execa(`npm`, [`install`]) spinner.succeed(`${g(`Dependencies`)} installed!`) } else { spinner.succeed( `${g('Project created successfully!')} To install dependencies manually, run ${y( `npm install` )} in your project directory.` ) } alert({ type: `success`, name: `ALL DONE!`, msg: `\n\n Enter your project directory using ${y(`cd ./${outDir}`)}.\n Run ${y( `npm start` )} to start the dev server.\n Stuck? Head over to the IMD Chat!` }) }) }