Skip to content

Instantly share code, notes, and snippets.

@aofleejay
Created March 3, 2020 12:46
Show Gist options
  • Save aofleejay/d79474d810a4395326ebf5310dcff31e to your computer and use it in GitHub Desktop.
Save aofleejay/d79474d810a4395326ebf5310dcff31e to your computer and use it in GitHub Desktop.
Script to choose between yarn or npm.
const path = require('path')
const spawn = require('cross-spawn')
const execSync = require('child_process').execSync
const root = path.resolve('project')
let command
let args = []
try {
execSync('yarn -v', { stdio: 'ignore' })
command = 'yarn'
args = args.concat(['--cwd', root, 'add'])
} catch {
command = 'npm'
args = args.concat(['--prefix', root, 'install'])
}
const devDependencies = ['chalk']
const commandOptions = ['-D', '-E']
args = args.concat(commandOptions, devDependencies)
spawn.sync(command, args, { stdio: "inherit" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment