Skip to content

Commit

Permalink
fix second run issues with --flag enabled. better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard committed Aug 9, 2015
1 parent a30db5f commit 1bf3343
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ src
nexe.exe
nexe
npm-debug.log
examples/**/src
examples/**/out.nex
5 changes: 4 additions & 1 deletion bin/nexe
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions examples/embedded-files/build.js
Original file line number Diff line number Diff line change
@@ -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"]
},
Expand Down
2 changes: 0 additions & 2 deletions examples/embedded-files/makefile

This file was deleted.

10 changes: 6 additions & 4 deletions examples/hello-world/build.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions examples/hello-world/makefile

This file was deleted.

4 changes: 4 additions & 0 deletions lib/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
79 changes: 46 additions & 33 deletions lib/exe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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');
Expand Down Expand Up @@ -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
**/
Expand Down
4 changes: 2 additions & 2 deletions lib/monkeypatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
**/

var async = require("async"),
fs = require("fs"),
_log = require("./log");
fs = require("fs"),
_log = require("./log");

/**
* Monkey patch a file.
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"author": "Craig Condon <craig.j.condon@gmail.com>",
"author": "Jared Allard <jaredallard@outlook.com>",
"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": {
Expand Down

0 comments on commit 1bf3343

Please sign in to comment.