Skip to content

Commit

Permalink
simplified code, updated dependencies now has code embed
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 8, 2018
1 parent d483088 commit c7585fd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 77 deletions.
24 changes: 4 additions & 20 deletions binarybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs-extra');
const path = require('path');
const decompress = require('inly');
const spawn = require('cross-spawn');
const uncompress = require('unpack-all');
const uncompress = require('all-unpacker');
const node_wget = require('node-wget');
const retryPromise = require('retrying-promise');

Expand All @@ -16,10 +16,6 @@ const _7zAppfile = '7z1604-extra.7z';
const _7zApptocopy = [ '7za.dll','7za.exe','7zxa.dll' ];
const _7zAppurl = 'http://7-zip.org/a/';

const unarAppfile = 'unar1.8.1_win.zip';
const unarApptocopy = [ 'lsar.exe','unar.exe','Foundation.1.0.dll' ];
const unarAppurl = 'https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/theunarchiver/';

const platform = 'darwin';
const cwd = process.cwd();
const destination = path.join(cwd, platform);
Expand All @@ -33,7 +29,7 @@ if (_7zipData.url != null) {
platformUnpacker(source, destination)
.then(function (mode) {
if (mode='done') {
var whattodelete = unarApptocopy.concat(_7zApptocopy).concat( [unarAppfile, _7zAppfile] );
var whattodelete = _7zApptocopy.concat([ _7zAppfile]);
whattodelete.forEach(function (s) { fs.unlink(path.join(cwd, s), (err) => { if (err) console.error(err); }); });
fs.remove(destination, (err) => { if (err) console.error(err); });
console.log('Binaries copied successfully!');
Expand Down Expand Up @@ -72,17 +68,10 @@ function wget(path) {

function platformUnpacker(source, destination){
return new retryPromise(function (resolve, retry, reject) {
wget({ url: unarAppurl + unarAppfile, dest: path.join(cwd,unarAppfile) })
.then(function () {
wget({ url: _7zAppurl + _7zAppfile, dest: path.join(cwd,_7zAppfile) })
.then(function () {
console.log('Extracting: ' + unarAppfile + ', to decompress: ' + _7zAppfile );
const extract = decompress(path.join(cwd,unarAppfile), cwd);
extract.on('file', (name) => { console.log(name); });
extract.on('error', (error) => { return reject(error); });
extract.on('end', () => {
console.log('Extracting: ' + _7zAppfile + ', to decompress: ' + _7zipData.filename );
unpack(path.join(cwd, _7zAppfile), '.', _7zApptocopy)
unpack(path.join(cwd, _7zAppfile), cwd, _7zApptocopy)
.then(function() {
var response = [];
downloadandcopy.forEach(function(macos, index) {
Expand Down Expand Up @@ -110,17 +99,12 @@ function platformUnpacker(source, destination){
if ( retrytime.length === downloadandcopy.length ) reject(err);
else retry();
});
});

}).catch(function (err) {
retrytime.push(err);
if ( retrytime.length === downloadandcopy.length ) reject(err);
else retry();
});
}).catch(function (err) {
retrytime.push(err);
if ( retrytime.length === downloadandcopy.length ) reject(err);
else retry();
});
});
}

Expand Down
84 changes: 34 additions & 50 deletions installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs-extra');
var path = require('path');
var decompress = require('inly');
var spawn = require('cross-spawn');
var uncompress = require('unpack-all');
var uncompress = require('all-unpacker');
var macuncompress = require('xar');
var node_wget = require('node-wget');

Expand All @@ -17,10 +17,6 @@ const _7zAppfile = '7z1604-extra.7z';
const _7zApptocopy = [ '7za.dll','7za.exe','7zxa.dll' ];
const _7zAppurl = 'http://7-zip.org/a/';

const unarAppfile = (process.platform == "darwin") ? 'unar1.8.1.zip' : 'unar1.8.1_win.zip' ;
const unarApptocopy = [ 'lsar.exe','unar.exe','Foundation.1.0.dll' ];
const unarAppurl = 'https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/theunarchiver/';

const cwd = process.cwd();
const destination = path.join(cwd, process.platform);
const source = path.join(cwd, _7zipData.filename);
Expand Down Expand Up @@ -49,10 +45,7 @@ if ((_7zipData.url != null) && (process.platform != "darwin")) {
}
console.log('Binaries copied successfully!');
if (mode=='darwin') {
var whattodelete = unarApptocopy.concat(_7zApptocopy).concat( [unarAppfile, _7zAppfile] );
whattodelete.forEach(function (s) { fs.unlink(path.join(cwd, s), (err) => { if (err) console.error(err); }); });
} else if (mode=='win32') {
var whattodelete = unarApptocopy.concat( unarAppfile );
var whattodelete = _7zApptocopy.concat([ _7zAppfile]);
whattodelete.forEach(function (s) { fs.unlink(path.join(cwd, s), (err) => { if (err) console.error(err); }); });
}
fs.unlink(source, (err) => { if (err) console.error(err); });
Expand Down Expand Up @@ -116,48 +109,38 @@ function wget(path) {

function platformUnpacker(source, destination){
return new Promise(function (resolve, reject) {
if ((process.platform == "win32") || (process.platform == "darwin_not_ready")) {
wget({ url: unarAppurl + unarAppfile, dest: path.join(cwd,unarAppfile) })
.then(function () {
console.log('Extracting: ' + unarAppfile + ', to decompress: ' + ((process.platform == "win32") ? _7zipData.filename : _7zAppfile ));
const extract = decompress(path.join(cwd,unarAppfile), cwd);
extract.on('file', (name) => { console.log(name); });
extract.on('error', (error) => { return reject(error); });
extract.on('end', () => {
if (process.platform == "darwin") {
wget({ url: _7zAppurl + _7zAppfile, dest: path.join(cwd,_7zAppfile) })
.then(function () {
console.log('Extracting: ' + _7zAppfile + ', to decompress: ' + _7zipData.filename );
unpack(path.join(cwd, _7zAppfile), '.', _7zApptocopy)
.then(function() {
console.log('Decompressing ' + _7zipData.filename);
macunpack(source, destination)
//winunpack(source, destination)
.then(function(data) {
//console.log('Decompressing: p7zip-9.20.1-1');
//unpack(path.join(destination,'p7zip-9.20.1-1'), process.platform, _7zipData.applocation + path.sep +'*')
console.log('Decompressing: p7zipinstall.pkg/Payload');
unpack(path.join(destination,'p7zipinstall.pkg','Payload'), process.platform, _7zipData.applocation + path.sep + '*')
.then( function(result) {
console.log(result);
resolve('darwin'); })
.catch(function (err) { return reject(err); });
})
.catch(function (err) { return reject(err); });
})
.catch(function (err) { return reject(err); });
})
.catch(function (err) { return reject(err); });
} else {
unpack(source, process.platform)
.then(function (result) {
if (process.platform == "darwin") {
wget({ url: _7zAppurl + _7zAppfile, dest: path.join(cwd,_7zAppfile) })
.then(function () {
console.log('Extracting: ' + _7zAppfile + ', to decompress: ' + _7zipData.filename );
unpack(path.join(cwd, _7zAppfile), cwd, _7zApptocopy)
.then(function() {
console.log('Decompressing ' + _7zipData.filename);
macunpack(source, destination)
//winunpack(source, destination)
.then(function(data) {
//console.log('Decompressing: p7zip-9.20.1-1');
//unpack(path.join(destination,'p7zip-9.20.1-1'), process.platform, _7zipData.applocation + path.sep +'*')
console.log('Decompressing: p7zipinstall.pkg/Payload');
unpack(path.join(destination,'p7zipinstall.pkg','Payload'), process.platform, _7zipData.applocation + path.sep + '*')
.then( function(result) {
console.log(result);
resolve('win32'); })
.catch(function (err) { return reject(err); });
}
});
resolve('darwin');
})
.catch(function (err) { return reject(err); });
})
.catch(function (err) { return reject(err); });
})
.catch(function (err) { return reject(err); });
})
.catch(function (err) { return reject(err); });
} else if (process.platform == "win32") {
unpack(source, process.platform)
.then(function (result) {
console.log(result);
resolve('win32');
})
.catch(function (err) { return reject(err); });
.catch(function (err) { return reject(err); });
} else if (process.platform == "linux") {
console.log('Decompressing ' + _7zipData.filename);
const extract = decompress(source, destination);
Expand All @@ -167,7 +150,8 @@ function platformUnpacker(source, destination){
const system_installer = require('system-install');
const cmd = system_installer().split(" ")[0];
const args = [ system_installer().split(" ")[1] ];
const distro = args.concat(['install','-y']).concat(((system_installer().split(" ")[1] == 'yum') || (system_installer().split(" ")[1] == 'dnf')) ? ['glibc.i686'] : ['libc6-i386']);
const install = [ system_installer().split(" ")[2] ];
const distro = args.concat(install).concat(((system_installer().split(" ")[1] == 'yum') || (system_installer().split(" ")[1] == 'dnf')) ? ['-y','glibc.i686'] : ['-y','libc6-i386']);
console.log(cmd + ' ' + distro);
spawn.sync(cmd, distro, { stdio: 'pipe' });
resolve('linux');
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,23 @@
"util"
],
"dependencies": {
"when": "^3.7.7",
"cross-spawn": "^4.0.0"
"when": "^3.7.8",
"cross-spawn": "^6.0.4"
},
"optionalDependencies": {
"fs-extra": "^2.0.0",
"fs-extra": "^5.0.0",
"node-wget": "^0.4.2",
"inly": "^1.2.3",
"xar": "^1.1.1",
"all-unpacker": "^0.0.5",
"macos-release": "^1.1.0",
"retrying-promise": "^0.0.4",
"system-install": "^1.0.4",
"when": "^3.7.8",
"system-install": "^1.0.4"
"xar": "^1.1.1"
},
"devDependencies": {
"chai": "^3.5.0",
"chai": "^4.1.2",
"istanbul": "^0.4.5",
"mocha": "^3.2.0"
"mocha": "^5.0.0"
}
}

0 comments on commit c7585fd

Please sign in to comment.