Skip to content

Instantly share code, notes, and snippets.

@jsynowiec
Last active April 28, 2019 10:50
Show Gist options
  • Select an option

  • Save jsynowiec/b67221be8f34ac531f17c69fdaf1efbe to your computer and use it in GitHub Desktop.

Select an option

Save jsynowiec/b67221be8f34ac531f17c69fdaf1efbe to your computer and use it in GitHub Desktop.

Revisions

  1. jsynowiec revised this gist Apr 28, 2019. No changes.
  2. Jakub Synowiec created this gist Oct 20, 2016.
    22 changes: 22 additions & 0 deletions yarn-or-npmi.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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.');
    }