This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
28 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
var spawn = require('child_process').spawn | ||
|
||
function Switcher (version) { | ||
var binArgs = { | ||
n: ['n', version], | ||
nvm: [process.env.SHELL, '-c', 'source $NVM_DIR/nvm.sh; nvm use ' + version] | ||
} | ||
|
||
function switcher (bin) { | ||
var args = binArgs[bin] | ||
bin = args.shift() | ||
return spawn(bin, args, { stdio: 'inherit' }) | ||
} | ||
|
||
switcher.binaries = Object.keys(binArgs) | ||
return switcher | ||
} | ||
|
||
module.exports = Switcher |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
var _which = require('which') | ||
var NVM_DIR = process.env.NVM_DIR | ||
|
||
function which (bin, cb) { | ||
var binaries = { | ||
n: function () { return _which(bin, cb) }, | ||
nvm: function () { | ||
if (NVM_DIR) return process.nextTick(cb) | ||
process.nextTick(function () { return cb('nope') }) | ||
} | ||
} | ||
|
||
return binaries[bin]() | ||
} | ||
|
||
module.exports = which |