UNPKG

firestudio

Version:

CLI for developing apps with NextJS and Firebase

49 lines (41 loc) 1.39 kB
const execa = require('execa') const Promise = require('promise') const messages = require('../messages') const output = require('./output') module.exports = function install(opts) { const projectName = opts.projectName const projectPath = opts.projectPath const packages = opts.packages || [] if (packages.length === 0) { console.log('Missing packages in `install`, try running again.') process.exit(1) } const installCmd = 'npm' const installArgs = getInstallArgs(installCmd, packages) console.log(messages.installing(packages)) process.chdir(projectPath) return new Promise(function(resolve, reject) { const stopInstallSpinner = output.wait('Installing modules') execa(installCmd, installArgs) .then(function() { // Confirm that all dependencies were installed return execa(installCmd, ['install']) }) .then(function() { stopInstallSpinner() output.success(`Installed dependencies for ${projectName}`) resolve() }) .catch(function() { stopInstallSpinner() console.log(messages.installError(packages)) return reject(new Error(`${installCmd} installation failed`)) }) }) } function getInstallArgs(cmd, packages) { if (cmd === 'npm') { const args = ['install', '--save', '--save-exact'] return args.concat(packages, ['--verbose']) } }