From 1bf334399b4d9bbaf4bd09051cabb6a27fb539ac Mon Sep 17 00:00:00 2001 From: Jared Allard Date: Sun, 9 Aug 2015 08:32:18 -0700 Subject: [PATCH] fix second run issues with --flag enabled. better error handling --- .gitignore | 2 + bin/nexe | 5 +- examples/embedded-files/build.js | 10 ++-- examples/embedded-files/makefile | 2 - examples/hello-world/build.js | 10 ++-- examples/hello-world/makefile | 2 - lib/embed.js | 4 ++ lib/exe.js | 79 +++++++++++++++++++------------- lib/monkeypatch.js | 4 +- package.json | 12 ++--- 10 files changed, 76 insertions(+), 54 deletions(-) delete mode 100644 examples/embedded-files/makefile delete mode 100755 examples/hello-world/makefile diff --git a/.gitignore b/.gitignore index 1aa9837b..cf81e2b1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ src nexe.exe nexe npm-debug.log +examples/**/src +examples/**/out.nex diff --git a/bin/nexe b/bin/nexe index c05c5315..234e66ea 100755 --- a/bin/nexe +++ b/bin/nexe @@ -58,13 +58,16 @@ if(argv.h || argv.help) { process.exit(); } +/** + * TODO: Support network shares? + **/ function toAbsolute(pt) { if(pt.substr(0, 1) == "/") return pt; + if(pt.substr(1, 3) == ":/") return pt; // for windows "c:/" return path.join(process.cwd(), pt); } if(fs.lstatSync(argv.i).isDirectory()) { - _log("log", "checking package.json"); opts = nexe.package(path.join(argv.i, "package.json"), argv); nexe.compile(opts, function(error) { if(error) { diff --git a/examples/embedded-files/build.js b/examples/embedded-files/build.js index 43c279fb..740b46ce 100644 --- a/examples/embedded-files/build.js +++ b/examples/embedded-files/build.js @@ -1,11 +1,13 @@ -var nexe = require('nexe'); +var nexe = require('../..'); nexe.compile( { input: "./index.js", - output: "./hellowWorld.exe", - nodeVersion: "0.10.33", - nodeTempDir: "", + output: "./out.nex", + nodeVersion: "3.0.0", + framework: "iojs", + nodeTempDir: "src", + python: "python", flags: true, resourceFiles: ["./message.txt"] }, diff --git a/examples/embedded-files/makefile b/examples/embedded-files/makefile deleted file mode 100644 index fe19143a..00000000 --- a/examples/embedded-files/makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - nexe -i ./ -o ./hello-world.nex -r 0.8.18 \ No newline at end of file diff --git a/examples/hello-world/build.js b/examples/hello-world/build.js index 858a6b6a..b2aac569 100644 --- a/examples/hello-world/build.js +++ b/examples/hello-world/build.js @@ -1,11 +1,13 @@ -var nexe = require('nexe'); +var nexe = require('../..'); nexe.compile( { input: "./index.js", - output: "", - nodeVersion: "0.10.33", - nodeTempDir: "", + output: "./out.nex", + nodeVersion: "3.0.0", + nodeTempDir: "./src", + framework: "iojs", + python: 'python', flags: true }, function (err) { diff --git a/examples/hello-world/makefile b/examples/hello-world/makefile deleted file mode 100755 index fe19143a..00000000 --- a/examples/hello-world/makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - nexe -i ./ -o ./hello-world.nex -r 0.8.18 \ No newline at end of file diff --git a/lib/embed.js b/lib/embed.js index c7c5a2f0..42296c2b 100644 --- a/lib/embed.js +++ b/lib/embed.js @@ -21,9 +21,13 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * **/ + var path = require("path"), fs = require("fs"); +/** + * TODO: Optimize this code. (more like document it so I understand it better.) + **/ function embed(resourceFiles, resourceRoot, complete) { function encode(filePath) { return fs.readFileSync(filePath).toString('base64'); diff --git a/lib/exe.js b/lib/exe.js index b36064a8..3920c66f 100644 --- a/lib/exe.js +++ b/lib/exe.js @@ -21,30 +21,30 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * **/ -var async = require("async"), -outcome = require("outcome"), -mkdirp = require("mkdirp"), -request = require("request"), -path = require("path"), -fs = require("fs"), -ncp = require("ncp").ncp, -ProgressBar = require("progress"), -child_process = require("child_process"), -glob = require("glob"), -bundle = require("./bundle"), -embed = require("./embed"), -os = require("os"), -targz = require('tar.gz'), -_log = require("./log"), -_monkeypatch = require("./monkeypatch"), -spawn = child_process.spawn; +var async = require("async"), + outcome = require("outcome"), + mkdirp = require("mkdirp"), + request = require("request"), + path = require("path"), + fs = require("fs"), + ncp = require("ncp").ncp, + ProgressBar = require("progress"), + child_process = require("child_process"), + glob = require("glob"), + bundle = require("./bundle"), + embed = require("./embed"), + os = require("os"), + targz = require('tar.gz'), + _log = require("./log"), + _monkeypatch = require("./monkeypatch"), + spawn = child_process.spawn; var isWin = /^win/.test(process.platform); var isPy; var framework; var version; -option_list = [ +var option_list = [ "python", "input", "output", @@ -80,11 +80,11 @@ exports.compile = function (options, complete) { } }); - /** - * Have we been given a custom flag for python executable? - */ + /** + * Have we been given a custom flag for python executable? + **/ if(options.python!=='python' && options.python!=="" - && options.python!==undefined) { + && options.python!==undefined) { if(isWin) { isPy=options.python.replace(/\//gm, "\\"); // use windows file paths, batch is sensitive. } else { @@ -541,7 +541,7 @@ function _monkeyPatchChildProcess(compiler, complete) { } /** - * Patch node.cc to not check the internal arguments. + * Patch node.cc to not check the internal arguments. */ function _monkeyPatchMainCc(compiler, complete) { @@ -553,21 +553,32 @@ function _monkeyPatchMainCc(compiler, complete) { }, function (content, next) { var lines = content.split('\n'); - - /* pre 0.11.6 compat? */ - var endLine = lines.indexOf(' option_end_index = i;'); - lines[endLine] = ' option_end_index = 1;'; + var endLine = lines.indexOf(' option_end_index = i;'); // pre node 0.11.6 compat + + if(endLine !== -1) { // check if it succedded or not. + lines[endLine] = ' option_end_index = 1;'; + } else { + _log("not a version of node before 0.11.6"); + } /** * This is the new method of passing the args. Tested on node.js 0.12.5 * and iojs 2.3.1 **/ - var startLine = lines.indexOf(' while (index < nargs && argv[index][0] == \'-\') {'); - var endLine = lines.indexOf(' // Copy remaining arguments.'); - endLine = endLine-1; // space, then it's at the } - - for (var i = startLine; i < endLine; i++) { - lines[i] = '//' + lines[i]; + if(endLine === -1) { // only if the pre-0.12.5 failed. + var startLine = lines.indexOf(' while (index < nargs && argv[index][0] == \'-\') {'); // beginning of the function + endLine = lines.indexOf(' // Copy remaining arguments.'); + endLine = endLine-1; // space, then it's at the } + + // remove the offending lines + if(startLine !== -1) { + for (var i = startLine; i < endLine; i++) { + lines[i] = undefined; // set the value to undefined so it's skipped by the join + } + _log('patched node.cc'); + } else { + _log("skipping node.cc override -- already been done."); + } } lines = lines.join('\n'); @@ -619,6 +630,8 @@ function _logProgress (req) { * * @param {string} path - path to package.json * @param {object} options - fallback options + * + * @todo implement options overriding package defaults. * * @return {object} nexe.compile options object **/ diff --git a/lib/monkeypatch.js b/lib/monkeypatch.js index 1ba98722..dd269497 100644 --- a/lib/monkeypatch.js +++ b/lib/monkeypatch.js @@ -23,8 +23,8 @@ **/ var async = require("async"), -fs = require("fs"), -_log = require("./log"); + fs = require("fs"), + _log = require("./log"); /** * Monkey patch a file. diff --git a/package.json b/package.json index c044d009..2ab2e5ac 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,19 @@ { - "author": "Craig Condon ", + "author": "Jared Allard ", "name": "nexe", - "description": "Roll node.js applications into a single executable", + "description": "create single executables out of your [node/io].js applications", "license": "MIT", "version": "0.4.0", "contributors": [ { - "name": "Jared Allard", - "email": "jaredallard@outlook.com", - "url": "jaredallard.com" + "name": "Criag Condon", + "email": "craig.j.condon@gmail.com", + "url": "http://crcn.io/" } ], "repository": { "type": "git", - "url": "git://github.com/crcn/nexe.git" + "url": "git://github.com/jaredallard/nexe.git" }, "main": "./lib/index.js", "dependencies": {