electron/npm/install.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-10-20 04:17:38 +00:00
#!/usr/bin/env node
var os = require('os')
var path = require('path')
var nugget = require('nugget')
var extract = require('extract-zip')
2014-10-20 04:56:49 +00:00
var fs = require('fs')
2014-10-20 04:17:38 +00:00
2014-10-20 04:56:49 +00:00
var platform = os.platform()
var arch = os.arch()
2015-03-04 21:08:16 +00:00
if (platform === 'win32') {
// 64-bit is not available under windows.
2015-03-04 21:08:16 +00:00
arch = 'ia32'
}
2015-03-04 21:04:51 +00:00
var version = '0.21.3'
2015-03-04 21:08:16 +00:00
var filename = 'atom-shell-v' + version + '-' + platform + '-' + arch + '.zip'
var url = 'https://github.com/atom/atom-shell/releases/download/v' + version + '/atom-shell-v' + version + '-' + platform + '-' + arch + '.zip'
2014-10-20 04:17:38 +00:00
2015-03-04 21:08:16 +00:00
function onerror (err) {
2014-10-20 04:17:38 +00:00
throw err
}
2014-10-20 04:56:49 +00:00
var paths = {
darwin: path.join(__dirname, './dist/Atom.app/Contents/MacOS/Atom'),
linux: path.join(__dirname, './dist/atom'),
win32: path.join(__dirname, './dist/atom.exe')
}
2014-11-22 19:29:44 +00:00
var shebang = {
darwin: '#!/bin/bash\n',
linux: '#!/bin/bash\n',
win32: ''
}
2014-11-15 09:11:09 +00:00
var argv = {
darwin: '"$@"',
linux: '"$@"',
2014-11-15 09:13:23 +00:00
win32: '%*' // does this work with " " in the args?
2014-11-15 09:11:09 +00:00
}
2015-03-04 21:08:16 +00:00
if (!paths[platform]) throw new Error('Unknown platform: ' + platform)
2014-10-20 04:56:49 +00:00
2015-03-04 21:08:16 +00:00
nugget(url, {target: filename, dir: __dirname, resume: true, verbose: true}, function (err) {
2014-10-20 04:17:38 +00:00
if (err) return onerror(err)
2014-11-15 09:21:07 +00:00
fs.writeFileSync(path.join(__dirname, 'path.txt'), paths[platform])
2015-03-04 21:08:16 +00:00
fs.writeFileSync(path.join(__dirname, 'run.bat'), shebang[platform] + '"' + paths[platform] + '" ' + argv[platform])
2015-03-04 21:14:47 +00:00
extract(path.join(__dirname, filename), {dir: path.join(__dirname, 'dist')}, function (err) {
2014-10-20 04:17:38 +00:00
if (err) return onerror(err)
})
})