Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
#1357: Add small node module to handle JX build dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jun 15, 2016
1 parent 04cd1f7 commit c09e1b0
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -98,7 +98,7 @@ module.exports = function(grunt) {
]);

// Pkg the CLI binary
grunt.registerTask('pkgcli', [
grunt.registerTask('pkg:cli', [
'clean:cliBuild',
'clean:cliDist',
'copy:cliBuild',
Expand Down
4 changes: 4 additions & 0 deletions modules/jxcore/index.js
@@ -0,0 +1,4 @@
/**
* Export `findpath` function to get the platform dependant path of the `nodewebkit` binary
*/
module.exports.findpath = require('./lib/findpath.js');
13 changes: 13 additions & 0 deletions modules/jxcore/lib/findpath.js
@@ -0,0 +1,13 @@
var fs = require('fs');
var path = require('path');
var bindir = path.resolve(__dirname, '..', 'bin');

module.exports = function() {
var bin = bindir;
if (process.platform === 'win32') {
bin = path.join(bin, 'jx.exe');
} else {
bin = path.join(bin, 'jx');
}
return bin;
}
20 changes: 20 additions & 0 deletions modules/jxcore/package.json
@@ -0,0 +1,20 @@
{
"name": "jxcore",
"version": "0.3.1",
"subpatch": "1",
"description": "NPM based dependency downloader",
"scripts": {
"postinstall": "node scripts/install.js"
},
"license": "MIT",
"dependencies": {
"decompress": "^2.2.1",
"download": "^3.3.0",
"file-exists": "^0.1.1",
"merge": "^1.2.0",
"multimeter": "^0.1.1",
"rimraf": "^2.2.8",
"semver": "^4.3.0",
"chalk": "~1.0.0"
}
}
86 changes: 86 additions & 0 deletions modules/jxcore/scripts/install.js
@@ -0,0 +1,86 @@
#!/usr/bin/env node

var Download = require('download');
var rimraf = require('rimraf');
var semver = require('semver');
var createBar = require('multimeter')(process);
var path = require('path');
var fs = require('fs');
var merge = require('merge');
var urlModule = require('url');
var Decompress = require('decompress');
var fileExists = require('file-exists');
var chalk = require('chalk');

var v = semver.parse(require('../package.json').version);
var subpatch = require('../package.json').subpatch;
var version = [v.major, v.minor, v.patch, subpatch].join('');

/*
* Determine package type
*/
var getPkgType = function() {
switch (process.platform) {
case 'win32': return 'win64';
case 'darwin': return 'osx64';
case 'linux': return 'deb64';
}
};

function logError(e) {
console.error(chalk.bold.red((typeof e === 'string') ? e : e.message));
process.exit(1);
}

function cb(error) {
if( error != null ) {
return logError( error )
}

process.nextTick(function() {
process.exit();
});
}

if (v.prerelease && typeof v.prerelease[0] === 'string') {
var prerelease = v.prerelease[0].split('-');
if (prerelease.length > 1) {
prerelease = prerelease.slice(0, -1);
}
version += '-' + prerelease.join('-');
}

if (!getPkgType()) logError('Could not find a compatible version of nw.js to download for your platform.');

var url = [
'https://raw.githubusercontent.com/jxcore/jxcore-release/master/',
version,
'jx_' + getPkgType() + 'v8.zip'
].join('/');

var dest = path.resolve(__dirname, '..', 'bin');
rimraf.sync(dest);

var bar = createBar({ before: url + ' [' });

var total = 0;
var progress = 0;

var parsedUrl = urlModule.parse(url);
var decompressOptions = { strip: 1, mode: '755' };
if( parsedUrl.protocol == 'file:' ) {
if ( !fileExists(parsedUrl.path) ) {
logError('Could not find ' + parsedUrl.path);
}
new Decompress()
.src( parsedUrl.path )
.dest( dest )
.use( Decompress.zip(decompressOptions) )
.use( Decompress.targz(decompressOptions) )
.run( cb );
} else {
new Download(merge({ extract: true }, decompressOptions))
.get( url )
.dest( dest )
.run( cb );
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -67,6 +67,7 @@
"grunt-mocha-cli": "^2.0.0",
"grunt-shell": "^1.1.1",
"jshint-stylish": "~1.0.0",
"jxcore": "file:./modules/jxcore",
"matchdep": "^0.3.0",
"mock-fs": "^3.5.0",
"randomstring": "^1.0.5",
Expand Down
6 changes: 5 additions & 1 deletion tasks/shell.js
Expand Up @@ -32,6 +32,9 @@ module.exports = function(common) {
*/
var cliPkgTask = function(dev) {

// Grab JXCore bin
var jxBin = require('jxcore').findpath();

// "Constants"
var platform = common.system.platform;
var cpCmd = (platform === 'win32') ? 'copy' : 'cp';
Expand All @@ -51,7 +54,8 @@ module.exports = function(common) {

// JX package command
var jxCmd = [
'jx package',
jxBin,
'package',
'bin/kbox.js',
pkgName,
'--add "' + jxAddPatterns.join(',') + '"',
Expand Down

0 comments on commit c09e1b0

Please sign in to comment.