From fb57b09e6692f2dc77c0ec4caa36b866284792b8 Mon Sep 17 00:00:00 2001 From: Adam Snodgrass Date: Fri, 28 Feb 2014 18:54:38 -0600 Subject: [PATCH 1/6] Added progress to package.json dependencies; Defined _log in monkeypatch.js --- lib/monkeypatch.js | 2 ++ package.json | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/monkeypatch.js b/lib/monkeypatch.js index 0e78562..da31add 100644 --- a/lib/monkeypatch.js +++ b/lib/monkeypatch.js @@ -1,6 +1,8 @@ var async = require("async"), fs = require("fs"); +var _log = require('./log'); + module.exports = _monkeypatch; diff --git a/package.json b/package.json index 8a03ba9..159d8b8 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "sardines": "~0.4.5", "async": "~0.2.10", "colors": "~0.6.2", - "glob": "~3.2.9" + "glob": "~3.2.9", + "progress": "~1.1.3" }, "preferGlobal": "true", "bin": { From a0202559bcaf847bbc2a614e7713724f5e0ab009 Mon Sep 17 00:00:00 2001 From: Adam Snodgrass Date: Fri, 28 Feb 2014 21:16:38 -0600 Subject: [PATCH 2/6] Add option to disable node and v8 flags and pass through app flags --- bin/nexe | 6 ++++++ lib/exe.js | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bin/nexe b/bin/nexe index 8f9f7ac..960e5c7 100755 --- a/bin/nexe +++ b/bin/nexe @@ -26,6 +26,11 @@ options('t', { default: '/tmp/nexe', description: 'The path to store node.js sources' }). +options('f', { + alias: 'flags', + description: 'Don\'t parse node and v8 flags, pass through app flags', + default: false +}). options('v', { alias: 'version', description: 'Display version number' @@ -54,6 +59,7 @@ function toRelative(pt) { require('../lib').compile({ input : toRelative(argv.i), output : toRelative(argv.o), + flags : argv.f, nodeVersion : argv.r, nodeTempDir : toRelative(argv.t) }, function(error) { diff --git a/lib/exe.js b/lib/exe.js index 133604b..78c583a 100644 --- a/lib/exe.js +++ b/lib/exe.js @@ -9,7 +9,7 @@ ProgressBar = require("progress"), child_process = require("child_process"), glob = require("glob"), sardines = require("sardines"), -os = require("os"), +os = require("os"), spawn = child_process.spawn; @@ -61,6 +61,17 @@ exports.compile = function (options, complete) { _monkeyPatchNodeConfig(nodeCompiler, next); }, + /** + * monkeypatch node.cc to prevent v8 and node from processing CLI flags + */ + function monkeyPatchNodeCc (next) { + if (options.flags) { + _monkeyPatchMainCc(nodeCompiler, next); + } else { + next(); + } + }, + /** * compile the node application */ @@ -221,6 +232,7 @@ function _monkeyPatchNodeConfig (compiler, complete) { function (next) { _monkeyPatchMainJs(compiler, next) } + ], complete); } @@ -261,6 +273,34 @@ function _monkeyPatchMainJs (compiler, complete) { ); } +/** + */ + +function _monkeyPatchMainCc(compiler, complete) { + var mainPath = path.join(compiler.dir, "src", "node.cc"); + _monkeypatch( + mainPath, + function (content) { + return ~content.indexOf('// // TODO use parse opts'); + }, + function (content, next) { + var lines = content.split('\n'); + /* These lines exist until v0.11.6 */ + var startLine = lines.indexOf(' // TODO use parse opts'); + var endLine = lines.indexOf(' option_end_index = i;'); + + for (var i = startLine; i < endLine; i++) { + lines[i] = '//' + lines[i]; + } + + lines[endLine] = ' option_end_index = 1;'; + lines = lines.join('\n'); + next(null, lines); + }, + complete + ); +} + /** */ From 1e982d0e82e8275a4a5c2f309809d6592b45d5cb Mon Sep 17 00:00:00 2001 From: Adam Snodgrass Date: Fri, 28 Feb 2014 21:35:56 -0600 Subject: [PATCH 3/6] Remove duplicate _log definition --- lib/monkeypatch.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/monkeypatch.js b/lib/monkeypatch.js index 7140b17..be57993 100644 --- a/lib/monkeypatch.js +++ b/lib/monkeypatch.js @@ -2,8 +2,6 @@ var async = require("async"), fs = require("fs"), _log = require("./log"); -var _log = require('./log'); - module.exports = _monkeypatch; From a20406b42761e6c14ad2c1d0c4b0a47b98fe7933 Mon Sep 17 00:00:00 2001 From: Adam Snodgrass Date: Fri, 28 Feb 2014 21:40:59 -0600 Subject: [PATCH 4/6] Updated README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 12cf2e5..76f7ecb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Nexe is a command-line utility that compiles your Node.js application into a sin ## Requirements -- Linux / Mac +- Linux / Mac / BSD ## Caveats @@ -47,7 +47,7 @@ Options: -o, --output The output binary [default: cwd/release/app.nex] -r, --runtime The node.js runtime to use [default: "0.8.15"] -t, --temp The path to store node.js sources [default: /tmp/nexe] - + -f, --flags Don't parse node and v8 flags, pass through app flags [default: false] ```` @@ -58,7 +58,7 @@ Options: var nexe = require('nexe'); -nexe.compile({ input: 'input.js', output: 'path/to/bin', runtime: '0.8.15' } function() { +nexe.compile({ input: 'input.js', output: 'path/to/bin', runtime: '0.8.15', flags: true } function() { }); From fd01aac2e7f7a422724b04e7b6783484b78a22ee Mon Sep 17 00:00:00 2001 From: Jan-Henrik Date: Mon, 12 May 2014 20:29:02 +0200 Subject: [PATCH 5/6] Added Windows Support using vcbuild.bat --- lib/exe.js | 85 +++++++++++++++++++++++++++++++++------------------- package.json | 3 +- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/lib/exe.js b/lib/exe.js index 3271bfe..31158ea 100644 --- a/lib/exe.js +++ b/lib/exe.js @@ -10,12 +10,15 @@ child_process = require("child_process"), glob = require("glob"), sardines = require("sardines"), os = require("os"), +targz = require('tar.gz'), spawn = child_process.spawn; var _log = require("./log"), _monkeypatch = require("./monkeypatch"); +var isWin = /^win/.test(process.platform); + /** */ @@ -105,8 +108,8 @@ exports.compile = function (options, complete) { function _downloadNode (version, directory, complete) { - var nodeFileDir = path.join(directory, version), - nodeFilePath = path.join(nodeFileDir, "node-" + version + ".tar.gz"); + var nodeFileDir = path.resolve(path.join(process.cwd(), directory, version)), + nodeFilePath = path.resolve(path.join(nodeFileDir, "node-" + version + ".tar.gz")); // might already be downloaded, and unzipped @@ -122,7 +125,8 @@ function _downloadNode (version, directory, complete) { */ function makeDirectory (next) { - mkdirp(path.dirname(nodeFilePath), function () { next(); }) + mkdirp.sync(path.dirname(nodeFilePath)); + next(); }, /** @@ -130,7 +134,6 @@ function _downloadNode (version, directory, complete) { */ function downloadNode (next) { - if (fs.existsSync(nodeFilePath)) return next(); var url, prefix = "http://nodejs.org/dist"; @@ -156,15 +159,19 @@ function _downloadNode (version, directory, complete) { */ function unzipNodeTarball (next) { + if(isWin) { + _log("Extracting the .tar.gz."); + new targz().extract(nodeFilePath, nodeFileDir, next); + } else { + var cmd = ["tar", "-xf", nodeFilePath, "-C", nodeFileDir]; + _log(cmd.join(" ")); - var cmd = ["tar", "-xf", nodeFilePath, "-C", nodeFileDir]; - _log(cmd.join(" ")); + var tar = spawn(cmd.shift(), cmd); + tar.stdout.pipe(process.stdout); + tar.stderr.pipe(process.stderr); - var tar = spawn(cmd.shift(), cmd); - tar.stdout.pipe(process.stdout); - tar.stderr.pipe(process.stderr); - - tar.on("close", function () { next(); }) + tar.on("close", function () { next(); }) + } }, /** @@ -185,28 +192,44 @@ function _getNodeCompiler (nodeFileDir, complete) { var dir = _getFirstDirectory(nodeFileDir); if (dir) { - complete(null, { - dir: dir, - version: path.basename(nodeFileDir), - releasePath: path.join(dir, "out", "Release", "node"), - make: function (next) { - var configure = spawn("./configure", [], { cwd: dir }); - configure.stdout.pipe(process.stdout); - configure.stderr.pipe(process.stderr); - configure.on("close", function () { - var platformMake = "make"; - if (os.platform().match(/bsd$/) != null) { - platformMake = "gmake"; - } - var make = spawn(platformMake, [], { cwd: dir }); - make.stdout.pipe(process.stdout); - make.stderr.pipe(process.stderr); - make.on("close", function () { + if(isWin) { + complete(null, { + dir: dir, + version: path.basename(nodeFileDir), + releasePath: path.join(dir, "Release", "node.exe"), + make: function(next) { + var vcbuild = spawn("vcbuild.bat", ["nosign", "release"], { cwd: dir }); + vcbuild.stdout.pipe(process.stdout); + vcbuild.stderr.pipe(process.stderr); + vcbuild.on("close", function() { next(); }); - }) - } - }); + } + }); + } else { + complete(null, { + dir: dir, + version: path.basename(nodeFileDir), + releasePath: path.join(dir, "out", "Release", "node"), + make: function (next) { + var configure = spawn("./configure", [], { cwd: dir }); + configure.stdout.pipe(process.stdout); + configure.stderr.pipe(process.stderr); + configure.on("close", function () { + var platformMake = "make"; + if (os.platform().match(/bsd$/) != null) { + platformMake = "gmake"; + } + var make = spawn(platformMake, [], { cwd: dir }); + make.stdout.pipe(process.stdout); + make.stderr.pipe(process.stderr); + make.on("close", function () { + next(); + }); + }) + } + }); + } return true; } diff --git a/package.json b/package.json index ad62889..22a9e61 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "async": "~0.2.10", "colors": "~0.6.2", "glob": "~3.2.9", - "progress": "~1.1.3" + "progress": "~1.1.3", + "tar.gz": "^0.1.1" }, "preferGlobal": "true", "bin": { From 9f86d88ec52ef5975394dd547098ac3ec5ab0602 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Date: Mon, 12 May 2014 20:33:04 +0200 Subject: [PATCH 6/6] Added Windows support to Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76f7ecb..8ec17f3 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,12 @@ Nexe is a command-line utility that compiles your Node.js application into a sin ## Requirements -- Linux / Mac / BSD +- Linux / Mac / BSD / Windows +- Windows: Python 2.6 or 2.7 (in PATH), Visual Studio 2010 or 2012 ## Caveats - Doesn't support native modules (yet). -- Doesn't support windows (yet). ## Installation