Last active
April 28, 2019 10:50
-
-
Save jsynowiec/b67221be8f34ac531f17c69fdaf1efbe to your computer and use it in GitHub Desktop.
[yarn with npm fallback] Try to install dependencies using yarn or fall back to npm if yarn is not available #nodejs #yarn #npm
This file contains 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 os = require('os'); | |
const exec = require('child_process').exec; | |
switch (os.platform()) { | |
case 'win32': | |
exec('yarn --version', (err, stdout, stderr) => { | |
if (err) { | |
exec('npm install'); | |
return; | |
} else { | |
exec('yarn'); | |
} | |
}); | |
break; | |
case 'darwin': | |
case 'linux': | |
exec('if [ -z `which yarn`]; then npm install; else yarn; fi;'); | |
break; | |
default: | |
throw new Error('Unsupported platform.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or use
yarn || npm install
. Should work on both, Windows and macOS