browserify: implement error checks, path checks, and support express

This commit is contained in:
Jared Allard
2016-01-22 12:26:26 -08:00
parent 2bc181f2ab
commit 6ce224d6e4
5 changed files with 70 additions and 40 deletions
+7 -7
View File
@@ -1,7 +1,7 @@
### Nexe
[![Join the chat at https://gitter.im/crcn/nexe](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/crcn/nexe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Dependency Status](https://david-dm.org/crcn/nexe.svg)](https://david-dm.org/crcn/nexe)
[![Stories in Ready](https://badge.waffle.io/crcn/nexe.svg?label=ready&title=Ready)](http://waffle.io/crcn/nexe)
[![Join the chat at https://gitter.im/crcn/nexe](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jaredallard/nexe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Dependency Status](https://david-dm.org/jaredallard/nexe.svg)](https://david-dm.org/crcn/nexe)
[![Stories in Ready](https://badge.waffle.io/jaredallard/nexe.svg?label=ready&title=Ready)](http://waffle.io/jaredallard/nexe)
Nexe is a command-line utility that compiles your Node.js application into a single executable file.
@@ -136,12 +136,12 @@ var nexe = require('nexe');
nexe.compile({
input: 'input.js',
output: 'path/to/bin',
nodeVersion: '0.12.5',
nodeVersion: '5.5.0',
nodeTempDir: 'src',
python: 'path/to/python',
resourceFiles: [ 'path/to/a/file' ],
flags: true,
framework: "nodejs"
framework: "node" // node, nodejs, or iojs
}, function(err) {
console.log(err);
});
@@ -159,8 +159,8 @@ is still in works, so it is likely to change.
"output": "nexe^$",
"temp": "src",
"runtime": {
"framework": "iojs",
"version": "2.3.1",
"framework": "node",
"version": "5.5.0",
"ignoreFlags": true
}
}
@@ -174,4 +174,4 @@ Notes:
* __Jared Allard__ ([@jaredallard](https://github.com/jaredallard)) <[jaredallard@outlook.com](mailto:jaredallard@outlook.com)> (Active)
* __Christopher Karper__ ([@ckarper](https://github.com/CKarper)) <[Christopher.Karper@gmail.com](mailto:Christopher.Karper@gmail.com)> (Active)
* __Craig Jefferds__ ([@crcn](https://github.com/crcn)) <[craig.j.condon@gmail.com](mailto:craig.j.condon@gmail.com)> (Not Active)
* __Craig Condon__ ([@crcn](https://github.com/crcn)) <[craig.j.condon@gmail.com](mailto:craig.j.condon@gmail.com)> (Old Project Owner)
+39 -16
View File
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2013 Craig Condon
* Copyright (c) 2015 Jared Allard
* Copyright (c) 2015-2016 Jared Allard
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -23,43 +23,66 @@
*
**/
var mdeps = require("module-deps"),
path = require("path"),
spawn = require('child_process').spawn,
fs = require("fs"),
through = require("through"),
async = require("async"),
browserify = require('browserify'),
builtins = require("builtins"),
_log = require("./log");
path = require("path"),
spawn = require('child_process').spawn,
fs = require("fs"),
through = require("through2"),
async = require("async"),
browserify = require('browserify'),
builtins = require("builtins"),
_log = require("./log");
/**
* User browserify to create a "packed" file.
*
* @param {string} input - input file
* @param {string} nc - node compiler dir
* @param {function} complete - next function to call (async)
* @param {String} input - input file
* @param {String} nc - node compiler dir
* @param {Function} complete - next function to call (async)
**/
function bundle (input, nc, complete) {
var bundlePath = path.join(nc, "lib", "nexe.js");
var ws = fs.createWriteStream(bundlePath);
var proc = spawn('node', ['node_modules/browserify/bin/cmd.js', '--node', input ]);
var proc = spawn('node', [path.join(__dirname, '../', 'node_modules/browserify/bin/cmd.js'), '--node', input ]);
// TODO: Get path of nexe directory, and refer to it.
proc.stdout.pipe(ws);
proc.on('error', function(err) {
console.error(err.toString('ascii'));
_log('error', 'Failed to invoke browserify');
process.exit(1);
})
proc.stderr.on('data', function(data) {
console.error(data.toString('ascii'));
_log('error', 'Browserify failed to launch');
process.exit(1);
});
proc.on('close', function(code) {
console.log("browserify finished")
_log("Browserify finished");
})
ws.on('error', function(err) {
console.log(err);
_log('error', 'Failed to save stdout to disk');
process.exit(1);
})
ws.on('close', function() {
var source = fs.readFileSync(bundlePath, 'utf8');
source = source.replace(/[^\x00-\x7F]/g, "");
fs.writeFileSync(bundlePath, source, 'utf8');
complete();
// write the source modified to nexe.js
fs.writeFile(bundlePath, source, 'utf8', function(err) {
if(err) {
_log('error', 'failed to save source');
process.exit(1);
}
complete();
});
});
}
+2 -1
View File
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2013 Craig Condon
* Copyright (c) 2015-2016 Jared Allard
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -21,7 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**/
var path = require("path"),
fs = require("fs");
+10 -4
View File
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2013 Craig Condon
* Copyright (c) 2015-2016 Jared Allard
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -305,11 +306,16 @@ function _downloadNode (version, directory, complete) {
function downloadNode (next) {
if (fs.existsSync(nodeFilePath)) return next();
var type = global.type;
var url, prefix = "https://"+framework+".org/dist";
var uri = framework;
// pick which url depending on the version
if(framework==="nodejs") framework = "node"; // cmon node why can't you stay the same
if(framework==="node") {
uri = 'nodejs'; // if node, use nodejs uri
} else if(framework === 'nodejs') {
framework = 'node'; // support nodejs, and node, as framework.
}
var type = global.type;
var url, prefix = "https://"+uri+".org/dist";
if (version === "latest") {
url = prefix + "/" + framework + "-" + version + ".tar.gz";
+12 -12
View File
@@ -3,7 +3,7 @@
"name": "nexe",
"description": "create single executables out of your [node/io].js applications",
"license": "MIT",
"version": "0.4.2",
"version": "1.0.0",
"contributors": [
{
"name": "Criag Condon",
@@ -17,31 +17,31 @@
},
"main": "./lib/index.js",
"dependencies": {
"async": "1.4.2",
"browserify": "^11.0.1",
"builtins": "1.0.2",
"async": "1.5.2",
"browserify": "^13.0.0",
"builtins": "1.0.3",
"colors": "^1.1.2",
"glob": "^5.0.14",
"insert-module-globals": "^6.5.2",
"glob": "^6.0.4",
"insert-module-globals": "^7.0.1",
"mkdirp": "^0.5.1",
"module-deps": "^3.9.0",
"module-deps": "^4.0.5",
"ncp": "^2.0.0",
"outcome": "0.0.18",
"progress": "^1.1.8",
"request": "^2.61.0",
"request": "^2.67.0",
"sprintf": "~0.1.5",
"step": "0.0.x",
"tar.gz": "1.0.0",
"tar.gz": "1.0.2",
"through": "^2.3.8",
"yargs": "^3.19.0"
"yargs": "^3.32.0"
},
"nexe": {
"input": "./bin/nexe",
"output": "nexe^$",
"temp": "src",
"runtime": {
"framework": "iojs",
"version": "3.0.0",
"framework": "nodejs",
"version": "5.5.0",
"ignoreFlags": true
}
},