remove examples, base of browserify

This commit is contained in:
Jared Allard
2015-08-19 14:59:12 -07:00
parent a0a82e9547
commit 292063c482
14 changed files with 50 additions and 278 deletions
-1
View File
@@ -1 +0,0 @@
console.log("hello browser!");
-19
View File
@@ -1,19 +0,0 @@
var nexe = require('../..');
nexe.compile(
{
input: "./index.js",
output: "./out.nex",
nodeVersion: "3.0.0",
framework: "iojs",
nodeTempDir: "src",
python: "python",
flags: true,
resourceFiles: ["./message.txt"]
},
function (err) {
if (err) {
console.log(err);
}
}
);
-1
View File
@@ -1 +0,0 @@
Hello World!!!
-23
View File
@@ -1,23 +0,0 @@
var http = require("http"),
fs = require("fs"),
path = require("path"),
nexeres = require("nexeres"),
childProc = require("child_process"),
port = 1337;
//Fork a new process to execute the broser.js
childProc.fork(path.join(__dirname, "browser.js"));
if (false) {
require("./browser.js"); //force the bundler to include the .js file
}
//start a web server on specified port (or default if not given)
console.log("started HTTP server on port %d", port = Number(process.argv.concat().pop()) || port);
http.createServer(function(req, res) {
//return the embeded file in response to any request
res.write(nexeres.get("message.txt"));
res.end();
}).listen(port);
-1
View File
@@ -1 +0,0 @@
hello world!
-4
View File
@@ -1,4 +0,0 @@
{
"main": "./index.js",
"browser": "./index.js"
}
-1
View File
@@ -1 +0,0 @@
console.log("hello browser!");
-18
View File
@@ -1,18 +0,0 @@
var nexe = require('../..');
nexe.compile(
{
input: "./index.js",
output: "./out.nex",
nodeVersion: "3.0.0",
nodeTempDir: "./src",
framework: "iojs",
python: 'python',
flags: true
},
function (err) {
if (err) {
console.log(err);
}
}
);
-23
View File
@@ -1,23 +0,0 @@
var http = require("http"),
fs = require("fs"),
path = require("path"),
nexeres = require("nexeres"),
childProc = require("child_process"),
port = 1337;
//Fork a new process to execute the broser.js
childProc.fork(path.join(__dirname, "browser.js"));
if (false) {
require("./browser.js"); //force the bundler to include the .js file
}
//start a web server on specified port (or default if not given)
console.log("started HTTP server on port %d", port = Number(process.argv.concat().pop()) || port);
http.createServer(function(req, res) {
//return the embeded file in response to any request
res.write("Hello, world!");
res.end();
}).listen(port);
-1
View File
@@ -1 +0,0 @@
hello world!
-4
View File
@@ -1,4 +0,0 @@
{
"main": "./index.js",
"browser": "./index.js"
}
+32 -154
View File
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2013 Craig Condon
* Copyright (c) 2015 Jared Allard
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -21,165 +22,42 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**/
var mdeps = require("module-deps"),
through = require("through"),
async = require("async"),
builtins = require("builtins");
var mdeps = require("module-deps"),
path = require("path"),
fs = require("fs"),
through = require("through"),
async = require("async"),
browserify = require('browserify'),
builtins = require("builtins"),
_log = require("./log");
var _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)
**/
function bundle (input, nc, complete) {
var b = browserify();
var bundlePath = path.join(nc, "lib", "nexe.js");
var ws = fs.createWriteStream(bundlePath);
function bundle (input, complete) {
if(fs.existsSync(bundlePath)) {
fs.unlinkSync(bundlePath);
}
async.waterfall([
b.add(input); // add the file.
var bfs = b.bundle(); // open the bundle stream.
/**
* first we resolve all of the deps
*/
function resolveDeps (next) {
var deps = [];
var md = mdeps({
xtransform: function (tr, file) {
var buffer = [];
console.log(tr);
return through(write, end);
var self = this;
function write (chunk) {
buffer.push(chunk.toString());
// console.log(chunk.toString(""))
console.log(tr);
}
function end() {
var content = buffer.join("");
// console.log(content);
/*
// TODO add uglify flag
var source = uglify.parse(content, {
strict: false
});
source.figure_out_scope();
source.compute_char_frequency();
source.mangle_names();
// TODO - production
content = source.print_to_string({
ascii_only: true,
quote_keys: true
});*/
this.queue(content);
this.queue(null);
}
},
filter: function (id) {
if ([ 'nexeres', 'sys', 'readline' ].indexOf(id) > -1) { return false; }
return !~builtins.indexOf(id);
},
extensions: [ '.js', '.json' ],
ignoreMissing: true
});
/** event for missing packages, fixes conditional requires **/
md.on('missing', function(id, parent) {
_log("warn", "couldn't find require '" + id + "', errors may occur.");
});
md.pipe(through(function (chunk) {
deps.push(chunk);
}, function () {
next(null, deps);
}));
md.end({ file: input })
},
function bundleScript (deps, next) {
var buffer = [loader.toString()];
var dbuffer = [];
for (var i = deps.length; i--;) {
var dep = deps[i];
var req = "function (require, module, exports, __dirname) { \n"
if (dep.id.toLowerCase().indexOf(".json", dep.id.length - 5) !== -1) {
//this is the result of require("someFile.json"), so we need to export it from the function
req += "module.exports = "
}
if ((/^\#\!/).test(dep.source)) {
dep.source = '//' + dep.source;
}
req += dep.source + "}";
dbuffer.push(JSON.stringify(dep.id) + ": ["+req+", "+!!dep.entry+", "+JSON.stringify(dep.deps)+"]")
}
buffer = ["(" + loader.toString() + ").call(null, {"+dbuffer.join(",")+"}," + JSON.stringify(deps[deps.length-1].id) + ")"].toString();
next(null, buffer);
}
], complete)
bfs.pipe(ws); // pipe it to the write stream we created earlier
ws.on('close', function() {
// may need to be added later
// source = source.replace(/[^\x00-\x7F]/g, "");
complete();
})
}
var loader = function (deps, key) {
var pathModule = global.require("path");
var darr = [];
var dir = global.require("path").dirname(process.execPath);
var argv3 = process.argv[3];
if (argv3) {
argv3 = pathModule.relative(pathModule.dirname(process.execPath), argv3);
argv3 = pathModule.resolve(pathModule.dirname(key), argv3);
}
if (process.argv[2] == "--child_process" && deps[argv3]) {
//we've been forked and should run the module specified by argv3[3] instead of the start up module
key = argv3;
process.argv.splice(2, 2); //restore the argv to [0] = executable, [1] = nexejs
}
else if (process.argv[2] == "--child_process") {
//fork called, but for a module not bundled.
argv3 = process.argv[3];
process.argv.splice(1, 2); //restore the argv to [0] = executable, [1] = script
global.require(argv3);
return;
}
darr.push(deps[key]); //start up module.
function initModule (dep) {
if (dep.module) return dep.module.exports;
dep.module = { exports: {} };
dep[0](function (path) {
var rdep = deps[dep[2][path]];
var exports = rdep ? rdep.module ? rdep.module.exports : initModule(rdep) : global.require(path);
return exports;
}, dep.module, dep.module.exports, dir);
return dep.module.exports;
}
//run the startup module
darr.forEach(initModule);
return darr.filter(function (dep) {
return dep[1];
}).map(function (dep) {
return dep.module || {};
}).pop();
}
module.exports = bundle;
+3 -17
View File
@@ -148,21 +148,7 @@ exports.compile = function (options, complete) {
function combineProject (nc, next) {
nodeCompiler = nc;
_log("bundle %s", options.input);
bundle(options.input, next);
},
/**
* write the bundle to the lib directory of the target node version
*/
function writeBundle (source, next) {
bundlePath = path.join(nodeCompiler.dir, "lib", "nexe.js");
_log("bundle -> %s", bundlePath);
//Remove all non-ascii code from sources
source = source.replace(/[^\x00-\x7F]/g, "");
// same path as all the other JS files
fs.writeFile(bundlePath, source, next);
bundle(options.input, nodeCompiler.dir, next);
},
function embedResources(next) {
@@ -554,7 +540,7 @@ function _monkeyPatchMainCc(compiler, complete) {
function (content, next) {
var lines = content.split('\n');
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;';
_log("patched node.cc")
@@ -627,7 +613,7 @@ 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
+15 -11
View File
@@ -17,21 +17,22 @@
},
"main": "./lib/index.js",
"dependencies": {
"async": "1.2.1",
"builtins": "1.0.1",
"colors": "^1.0.3",
"glob": "^5.0.5",
"mkdirp": "^0.5.0",
"module-deps": "^3.6.4",
"async": "1.4.2",
"browserify": "^11.0.1",
"builtins": "1.0.2",
"colors": "^1.1.2",
"glob": "^5.0.14",
"mkdirp": "^0.5.1",
"module-deps": "^3.9.0",
"ncp": "^2.0.0",
"outcome": "0.0.18",
"progress": "^1.1.8",
"request": "^2.53.0",
"request": "^2.61.0",
"sprintf": "~0.1.5",
"step": "0.0.x",
"tar.gz": "0.1.1",
"through": "^2.3.6",
"yargs": "^3.2.1"
"tar.gz": "1.0.0",
"through": "^2.3.8",
"yargs": "^3.19.0"
},
"nexe": {
"input": "./bin/nexe",
@@ -39,12 +40,15 @@
"temp": "src",
"runtime": {
"framework": "iojs",
"version": "2.3.1",
"version": "3.0.0",
"ignoreFlags": true
}
},
"preferGlobal": "true",
"bin": {
"nexe": "./bin/nexe"
},
"devDependencies": {
"nodeunit": "^0.9.1"
}
}