Merge pull request #28 from alexwhitman/fixup
Linting, spawning and temp directory
This commit is contained in:
@@ -38,9 +38,10 @@ Or git:
|
||||
Usage: nexe -i [sources] -o [binary]
|
||||
|
||||
Options:
|
||||
-i, --input The entry javascript files [default: cwd]
|
||||
-o, --output The output binary [default: cwd/release/app.nex]
|
||||
-r, --runtime The node.js runtime to use [default: "0.8.15"]
|
||||
-i, --input The entry javascript files [default: cwd]
|
||||
-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]
|
||||
|
||||
|
||||
````
|
||||
|
||||
@@ -20,6 +20,11 @@ options('r', {
|
||||
alias: 'runtime',
|
||||
default: '0.8.21',
|
||||
description: 'The node.js runtime to use'
|
||||
}).
|
||||
options('t', {
|
||||
alias: 'temp',
|
||||
default: '/tmp/nexe',
|
||||
description: 'The path to store node.js sources'
|
||||
});
|
||||
|
||||
var argv = cli.argv;
|
||||
@@ -38,7 +43,7 @@ function toRelative(pt) {
|
||||
|
||||
|
||||
|
||||
require('../lib').compile({ input: toRelative(argv.i), output: toRelative(argv.o), runtime: argv.r }, function(error) {
|
||||
|
||||
require('../lib').compile({ input: toRelative(argv.i), output: toRelative(argv.o), runtime: argv.r, temp: toRelative(argv.t) }, function(error) {
|
||||
|
||||
if(error) console.log(error.message);
|
||||
});
|
||||
});
|
||||
|
||||
+34
-28
@@ -27,7 +27,7 @@ exports.compile = function(args, next) {
|
||||
*/
|
||||
|
||||
function() {
|
||||
downloadNode(args.runtime, this);
|
||||
downloadNode(args.runtime, args.temp, this);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -60,20 +60,20 @@ exports.compile = function(args, next) {
|
||||
* 5. bundle it all together
|
||||
*/
|
||||
|
||||
on.success(function() {
|
||||
console.log("building node.js");
|
||||
this.node.make(this);
|
||||
}),
|
||||
on.success(function() {
|
||||
console.log("building node.js");
|
||||
this.node.make(this);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 6. copy the executable
|
||||
*/
|
||||
/**
|
||||
* 6. copy the executable
|
||||
*/
|
||||
|
||||
on.success(function() {
|
||||
console.log("copying binary to output directory to %s", args.output);
|
||||
on.success(function() {
|
||||
console.log("copying binary to output directory to %s", args.output);
|
||||
|
||||
mkdirp(path.dirname(args.output), this);
|
||||
}),
|
||||
mkdirp(path.dirname(args.output), this);
|
||||
}),
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -87,20 +87,20 @@ exports.compile = function(args, next) {
|
||||
|
||||
next
|
||||
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
function downloadNode(version, next) {
|
||||
function downloadNode(version, temp, next) {
|
||||
|
||||
var tmpPath = path.join("/tmp/nexe", "node-v" + version + ".tar.gz"),
|
||||
var tmpPath = path.join(temp, "node-v" + version + ".tar.gz"),
|
||||
srcDr = tmpPath.replace(/\.tar.gz$/, "");
|
||||
|
||||
try {
|
||||
|
||||
mkdirp.sync(path.dirname(tmpPath))
|
||||
mkdirp.sync(path.dirname(tmpPath));
|
||||
|
||||
//an error will usually occur when the dir already exists.
|
||||
} catch(e) { }
|
||||
@@ -162,17 +162,23 @@ function downloadNode(version, next) {
|
||||
|
||||
//makes node.js
|
||||
make: function(next) {
|
||||
var proc = exec(sprintf("cd %s; ./configure; make; ", srcDr));
|
||||
proc.stdout._events = {}; //remove stdout & stdin capture
|
||||
proc.stdin._events = {};
|
||||
proc.stdout.on("data", function(chunk) {
|
||||
process.stdout.write(chunk);
|
||||
var configure = spawn('./configure', [], { cwd: srcDr });
|
||||
configure.stdout.on('data', function(data) {
|
||||
process.stdout.write(data.toString());
|
||||
});
|
||||
proc.stderr.on("data", function(chunk) {
|
||||
process.stdout.write(chunk);
|
||||
configure.stderr.on('data', function(data) {
|
||||
process.stderr.write(data.toString());
|
||||
});
|
||||
configure.on('close', function() {
|
||||
var make = spawn('make', [], { cwd: srcDr });
|
||||
make.stdout.on('data', function(data) {
|
||||
process.stdout.write(data.toString());
|
||||
});
|
||||
make.stderr.on('data', function(data) {
|
||||
process.stderr.write(data.toString());
|
||||
});
|
||||
make.on('close', next);
|
||||
});
|
||||
|
||||
proc.on("exit", next);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -207,7 +213,7 @@ function monkeyPatchNodejs(node, next) {
|
||||
//nexe already injected?
|
||||
if(~content.indexOf('nexe')) return this();
|
||||
|
||||
fs.writeFile(nodejsPath,
|
||||
fs.writeFile(nodejsPath,
|
||||
content.replace(/\(function\(process\) \{/,'(function(process){ \n process._eval = \'require("nexe");\'; '),
|
||||
"utf8",
|
||||
this);
|
||||
@@ -241,4 +247,4 @@ function monkeyPatchNodejs(node, next) {
|
||||
|
||||
next
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user