started adding copay shell to copay

This commit is contained in:
Gordon Hall 2014-06-06 14:23:40 -04:00
commit e7c5addfab
19 changed files with 781 additions and 3 deletions

View file

@ -0,0 +1,70 @@
/*
** copay-shell - linux builder
*/
var os = require('os');
var downloadAtom = require('./download-atom-shell');
var async = require('async');
var fs = require('fs');
var path = require('path');
var color = require('cli-color');
var exec = require('child_process').exec;
var shell_target = path.normalize(__dirname + '/../build/linux/Copay')
var app_target = path.normalize(__dirname + '/../build/linux/Copay/resources/app')
async.series(
[
function getBinary(done) {
downloadAtom(done);
},
function copyBuildFiles(done) {
console.log(color.blue('{copay}'), 'copying app files');
var ignore = ['.git','assets','build','scripts'].map(function(dir) {
return '--exclude ' + dir
}).join(' ');
var appDir = path.normalize(__dirname + '/../');
exec('rsync -av --progress ' + appDir + ' ' + app_target + ' ' + ignore, {
maxBuffer: Infinity // LOL
}, function(err, stdout, stderr) {
done(err || stderr);
});
},
function removeDefaultApp(done) {
console.log(color.blue('{copay}'), 'removing default application');
rmdir(path.normalize(__dirname + '/../build/linux/Copay/resources/default_app'));
done();
},
function renameExecutable(done) {
console.log(color.blue('{copay}'), 'renaming executable');
fs.rename(shell_target + '/atom', shell_target + '/Copay', done);
},
function zipBuild(done) {
console.log(color.blue('{copay}'), 'zipping distributable package');
exec('zip -r ' + path.normalize(shell_target, '/../Copay-' + process.platform) + ' ' + shell_target, {
maxBuffer: Infinity // LOL x 2
},function(err, stdout, stderr) {
done(err || stderr);
});
}
],
function(err, results) {
if (err) return console.log(color.blue('{copay}'), color.red(err));
console.log(color.blue('{copay}'), color.green('success!'));
}
);
function rmdir(dir) {
if (fs.existsSync(dir)) {
var list = fs.readdirSync(dir);
for(var i = 0; i < list.length; i++) {
var filename = path.join(dir, list[i]);
var stat = fs.statSync(filename);
if (filename == '.' || filename == '..') null;
else if (stat.isDirectory()) rmdir(filename);
else fs.unlinkSync(filename);
}
fs.rmdirSync(dir);
}
};

View file

@ -0,0 +1,106 @@
/*
** copay-shell - atom shell downloader
*/
var path = require('path');
var fs = require('fs');
var GitHub = require('github-releases');
var async = require('async');
var readl = require('readline');
var color = require('cli-color');
var github = new GitHub({ repo: 'atom/atom-shell' });
var exec = require('child_process').exec;
var os = require('os');
var version = 'v0.13.0';
var target = path.normalize(__dirname + '/../bin/' + process.platform);
console.log(color.blue('{copay}'), 'ensuring existence of output directory');
ensureOutputTargets();
console.log(color.blue('{copay}'), 'getting atom-shell release ' + version);
github.getReleases({ tag_name: version }, function(err, releases) {
if (err || !releases.length) {
return console.log('Release not found');
}
switch (process.platform) {
case 'linux':
var filename = 'atom-shell-' + version + '-' + process.platform + '-x64.zip';
break;
case 'darwin':
var filename = 'atom-shell-' + version + '-' + process.platform + '-x64.zip';
break;
case 'win32':
var filename = 'atom-shell-' + version + '-' + process.platform + '-ia32.zip';
break;
default:
console.log('platform ' + process.platform + ' not supported');
process.exit();
}
console.log(color.blue('{copay}'), 'looking for prebuilt binary ' + filename);
for (var a = 0; a < releases[0].assets.length; a++) {
var asset = releases[0].assets[a];
if (asset.name === filename) {
console.log(color.blue('{copay}'), 'downloading ' + asset.name);
var rl = readl.createInterface({
input: process.stdin,
output: process.stdout
});
rl.write(' bytes received: 0');
return github.downloadAsset(asset, function(err, inStream) {
if (err) {
console.log(err);
process.exit();
}
var bytes = 0;
inStream.on('data', function(chunk) {
rl.write(null, { ctrl: true, name: 'u' });
rl.write(' bytes received: ' + (bytes + chunk.length));
bytes += chunk.length;
});
inStream.on('end', function() {
rl.close();
console.log('');
console.log(color.blue('{copay}'), 'downloaded!');
});
var out = target;
var tmp = os.tmpDir() + '/atom-shell.zip';
var outStream = fs.createWriteStream(tmp);
outStream.on('finish', function() {
console.log(color.blue('{copay}'), 'unzipping archive');
exec('unzip -o ' + tmp + ' -d ' + out, function(err, stdout, stderr) {
console.log(err || stderr || (color.blue('{copay}') + ' done!'))
});
});
inStream.pipe(outStream);
});
}
}
});
function ensureOutputTargets() {
if (!fs.existsSync(target)) fs.mkdirSync(target);
// if (!fs.existsSync(target + process.platform)) {
// fs.mkdirSync(target + process.platform);
// }
};

39
shell/scripts/launch.js Normal file
View file

@ -0,0 +1,39 @@
/*
** copay-shell - launch
*/
var color = require('cli-color');
var path = require('path');
var appPath = path.normalize(__dirname + '/../../');
var execPath = path.normalize(__dirname + '/../bin/' + process.platform);
var spawn = require('child_process').spawn;
// update execPath with platform specific binary locations
switch (process.platform) {
case 'linux':
execPath += '/atom-shell/atom';
break;
case 'darwin':
execPath += '/Atom.app/Contents/MacOS/Atom';
break;
case 'win32':
execPath += '\\atom-shell\\atom.exe'
break;
default:
console.log('Platform not supported.');
process.exit();
}
var copay = spawn(execPath, [appPath]);
copay.stdout.on('data', function (data) {
console.log(data);
});
copay.stderr.on('data', function (data) {
console.log(color.red(data));
});
copay.on('close', function (code) {
console.log('child process exited with code ' + code);
});