Fixes #107, implements --framework/-F. Fetchs iojs latest.

This commit is contained in:
RainbowDashDC
2015-03-19 23:50:48 -07:00
parent 4e402bf937
commit b0644f0d62
2 changed files with 83 additions and 22 deletions
+9 -4
View File
@@ -14,7 +14,7 @@ options('o', {
demand: true,
alias: 'output',
desc: 'The output binary',
default: process.cwd() + '/release/' + path.basename(process.cwd()) + '.nex'
default: "..."+(process.cwd() + '/release/' + path.basename(process.cwd()) + '.nex').substr(-47) // cleaner for long directories
}).
options('r', {
alias: 'runtime',
@@ -39,6 +39,11 @@ options('p', {
alias: 'python',
description: 'Set path of python to use.',
default: 'python'
}).
options('F', {
alias: 'framework',
description: 'Set the framework to use',
default: 'nodejs'
});
var argv = cli.argv;
@@ -64,7 +69,7 @@ require('../lib').compile({
flags : argv.f,
nodeVersion : argv.r,
python : argv.python,
nodeTempDir : toAbsolute(argv.t) }, function(error) {
if(error) console.log(error.message);
nodeTempDir : toAbsolute(argv.t),
framework : argv.F }, function(error) {
if(error) console.log(error.message);
});
+74 -18
View File
@@ -20,6 +20,8 @@ _monkeypatch = require("./monkeypatch");
var isWin = /^win/.test(process.platform);
var isPy;
var framework;
var version;
/**
* Compiliation process.
@@ -30,14 +32,15 @@ exports.compile = function (options, complete) {
var nodeCompiler, nexeEntryPath;
async.waterfall([
/** check relevant options
*
/**
*check relevant options
*/
function checkOpts (next) {
/*
/**
* Have we been given a custom flag for python executable?
*/
if(options.python!=='python' && options.python!=="" && options.python!==undefined) {
if(options.python!=='python' && options.python!==""
&& options.python!==undefined) {
if(isWin) {
isPy=options.python.replace(/\//gm, "\\"); // use windows file paths, batch is sensitive.
} else {
@@ -49,14 +52,49 @@ exports.compile = function (options, complete) {
isPy="python";
}
next();
// remove dots
options.framework = options.framework.replace(/\./g, "");
// set outter-scope framework variable.
framework = options.framework;
_log("framework => "+framework);
version = options.nodeVersion; // better framework vc
// check iojs version
if (framework === "iojs" && version === "latest" ) {
_log("fetching iojs versions");
mkdirp(options.nodeTempDir); // make temp dir, probably repetive.
// create write stream so we have control over events
var output = fs.createWriteStream(path.join(options.nodeTempDir,
"iojs-versions.json"));
request.get("https://iojs.org/dist/index.json")
.pipe(output);
output.on('close', function() {
_log("done");
var f = fs.readFileSync(path.join(options.nodeTempDir,
"iojs-versions.json"));
f = JSON.parse(f);
version = f[0].version.replace("v", "");
_log("iojs latest => "+version);
// continue down along the async road
next();
})
} else {
next();
}
},
/**
* first download node
*/
function downloadNode (next) {
_downloadNode(options.nodeVersion, options.nodeTempDir, next);
_downloadNode(version, options.nodeTempDir, next);
},
/**
@@ -166,14 +204,13 @@ exports.compile = function (options, complete) {
*
* @param {string} version, version of node to download
* @param {string} directory, where to store the downloaded src
* @param {string} runtime, iojs or node !NOTE! Not implemented.
* @param {function} complete, callback
*/
function _downloadNode (version, directory, complete) {
var nodeFileDir = path.resolve(path.join(process.cwd(), directory, version)),
nodeFilePath = path.resolve(path.join(nodeFileDir, "node-" + version + ".tar.gz"));
var nodeFileDir = path.resolve(path.join(directory, framework, version)), // fixes #107, was process.cwd(), + rest.
nodeFilePath = path.resolve(path.join(nodeFileDir, framework + "-" + version + ".tar.gz"));
// might already be downloaded, and unzipped
@@ -200,13 +237,16 @@ function _downloadNode (version, directory, complete) {
function downloadNode (next) {
if (fs.existsSync(nodeFilePath)) return next();
var url, prefix = "https://iojs.org/dist";
var type = global.type;
var url, prefix = "https://"+framework+".org/dist";
// pick which url depending on the version
if(framework==="nodejs") framework = "node"; // cmon node why can't you stay the same
if (version === "latest") {
url = prefix + "/iojs-" + version + ".tar.gz";
url = prefix + "/" + framework + "-" + version + ".tar.gz";
} else {
url = prefix + "/v" + version + "/iojs-v" + version + ".tar.gz";
url = prefix + "/v" + version + "/"+framework+"-v" + version + ".tar.gz";
}
_log("downloading %s", url);
@@ -250,8 +290,8 @@ function _downloadNode (version, directory, complete) {
* return the compiler object for the node version
*/
function (next) {
_getNodeCompiler(nodeFileDir, next)
function (next, type) {
_getNodeCompiler(nodeFileDir, next, type)
},
], complete);
@@ -262,15 +302,25 @@ function _downloadNode (version, directory, complete) {
* it.
*/
function _getNodeCompiler (nodeFileDir, complete) {
function _getNodeCompiler (nodeFileDir, complete, type) {
var dir = _getFirstDirectory(nodeFileDir);
// standard
var executable = "node.exe";
var binary = "node";
// iojs specifics.
if(framework === "iojs") {
executable = "iojs.exe";
binary = "iojs";
}
if (dir) {
if(isWin) {
complete(null, {
dir: dir,
version: path.basename(nodeFileDir),
releasePath: path.join(dir, "Release", "iojs.exe"),
releasePath: path.join(dir, "Release", executable),
make: function(next) {
// create a new env with minimal impact on old one
var newEnv = process.env
@@ -296,7 +346,7 @@ function _getNodeCompiler (nodeFileDir, complete) {
complete(null, {
dir: dir,
version: path.basename(nodeFileDir),
releasePath: path.join(dir, "out", "Release", "iojs"),
releasePath: path.join(dir, "out", "Release", binary),
make: function (next) {
var cfg = "./configure", configure;
if(isPy !== "python") {
@@ -343,6 +393,11 @@ function _getNodeCompiler (nodeFileDir, complete) {
configure.stderr.pipe(process.stderr);
configure.on("close", function () {
if(isPy !== "python") {
/**
* Originally I thought this only applied to io.js,
* however I soon found out this affects node.js,
* so it is now mainstream.
*/
_log("preparing python");
// loop over depends
@@ -394,6 +449,7 @@ function _monkeyPatchNodeConfig (compiler, complete) {
}
/**
* patch the gyp file to allow our custom includes
*/
function _monkeyPatchGyp (compiler, complete) {
@@ -501,7 +557,7 @@ function _logProgress (req) {
complete: "=",
incomplete: " ",
total: len,
width: ((isWin) ? 100 : process.stdout.columns - 2)
width: ((isWin) ? 100 : process.stdout.columns - 2) // windows doesn't output colums correctly
});
req.on("data", function (chunk) {