-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 2e1d9b3
Showing
5 changed files
with
144 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,26 @@ | ||
# evm | ||
|
||
> Electron Version Manager | ||
- [x] unix support | ||
- [ ] windows support (experimental) | ||
- [x] evm install | ||
- [x] evm use | ||
- [ ] evm ls | ||
|
||
```plain | ||
npm install -g evm | ||
``` | ||
|
||
```plain | ||
evm install 0.33.6 | ||
evm install 1.2.1 | ||
evm use 1.2.1 | ||
evm use 0.33.6 | ||
``` | ||
|
||
``` | ||
// inspired by electron-download, electron-prebuilt | ||
// inspired by nvm, nrm, nwjs | ||
// inspired by prt | ||
``` |
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,17 @@ | ||
#!/usr/bin/env node | ||
var args = process.argv.slice(2) | ||
var evm = require('./') | ||
|
||
switch (args[0]) { | ||
case 'install': | ||
case 'use': | ||
evm[args[0]]({ version: args[1] }, function (err) { | ||
// if (err) throw err | ||
if (err) console.error(err) | ||
}) | ||
break; | ||
default: | ||
console.info('repo: https://github.com/fritx/evm') | ||
console.info('eg. evm install 1.2.1') | ||
console.info('eg. evm use 0.33.5') | ||
} |
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,73 @@ | ||
// inspired by electron-download, electron-prebuilt | ||
// inspired by nvm, nrm, nwjs | ||
// inspired by prt | ||
|
||
// todo: use promise | ||
// todo: evm ls | ||
var download = require('electron-download') | ||
var extract = require('extract-zip') | ||
var basename = require('path').basename | ||
var extname = require('path').extname | ||
var dirname = require('path').dirname | ||
var join = require('path').join | ||
var fs = require('fs') | ||
|
||
exports.install = install | ||
exports.use = use | ||
|
||
function install (opts, cb) { | ||
opts.platform = opts.platform || process.platform | ||
opts.arch = opts.arch || process.arch | ||
|
||
download(opts, function (err, zip) { | ||
if (err) return cb(err) | ||
var dir = join(dirname(zip), basename(zip, '.zip')) | ||
extract(zip, { dir: dir }, function (err) { | ||
// if (err && err.code !== 'EEXIST') return cb(err) | ||
if (err) return cb(err) | ||
cb() | ||
}) | ||
}) | ||
} | ||
|
||
function use (opts, cb) { | ||
opts.platform = opts.platform || process.platform | ||
opts.arch = opts.arch || process.arch | ||
|
||
var bin = { | ||
darwin: 'Electron.app/Contents/MacOS/Electron', | ||
freebsd: 'electron', | ||
linux: 'electron', | ||
win32: 'electron.exe' | ||
}[opts.platform] | ||
var dir = ['electron', 'v' + opts.version, opts.platform, opts.arch].join('-') | ||
var dist = join(process.env.HOME, '.electron', dir, bin) | ||
|
||
fs.exists(dist, function (exists) { | ||
if (!exists) { | ||
console.warn('v' + opts.version + ' is not installed') | ||
return cb() | ||
} | ||
crosslink(dist, cb) | ||
}) | ||
} | ||
|
||
function crosslink (file, cb) { | ||
if (process.platform === 'win32') { | ||
winlink(file, cb) | ||
} else { | ||
var target = '/usr/local/bin/electron' | ||
fs.unlink(target, function () { | ||
fs.symlink(file, target, cb) | ||
}) | ||
} | ||
} | ||
|
||
// experimental: windows support | ||
function winlink (file, cb) { | ||
var ext = extname(file) | ||
var base = basename(file, ext) | ||
var cmdfile = join(process.env.windir, base + '.cmd') | ||
var cmd = '"' + file + '" %*' | ||
fs.writeFile(cmdfile, cmd, cb) | ||
} |
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,27 @@ | ||
{ | ||
"name": "evm", | ||
"description": "Electron Version Manager", | ||
"version": "0.0.1", | ||
"homepage": "https://github.com/fritx/evm", | ||
"repository": "fritx/evm", | ||
"license": "MIT", | ||
"keywords": [ | ||
"evm", | ||
"electron", | ||
"atom-shell", | ||
"atom", | ||
"version", | ||
"manager", | ||
"switcher", | ||
"binary", | ||
"env" | ||
], | ||
"bin": { | ||
"evm": "cli.js" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"electron-download": "^2.1.2", | ||
"extract-zip": "^1.5.0" | ||
} | ||
} |