Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx committed Jun 7, 2016
0 parents commit 2e1d9b3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
26 changes: 26 additions & 0 deletions README.md
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
```
17 changes: 17 additions & 0 deletions cli.js
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')
}
73 changes: 73 additions & 0 deletions index.js
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)
}
27 changes: 27 additions & 0 deletions package.json
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"
}
}

0 comments on commit 2e1d9b3

Please sign in to comment.