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
+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";