Created
March 3, 2020 12:46
-
-
Save aofleejay/d79474d810a4395326ebf5310dcff31e to your computer and use it in GitHub Desktop.
Script to choose between yarn or npm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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