bundle/exe: more ES6, browserify.excludes, browserify.requires in package.json.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
### Nexe
|
||||
|
||||
[](https://gitter.im/jaredallard/nexe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://david-dm.org/crcn/nexe)
|
||||
[](https://gitter.im/jaredallard/nexe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://david-dm.org/jaredallard/nexe)
|
||||
[](http://waffle.io/jaredallard/nexe)
|
||||
|
||||
Nexe is a command-line utility that compiles your Node.js application into a single executable file.
|
||||
|
||||
+20
-3
@@ -62,23 +62,35 @@ function bundle(input, nc, options, complete) {
|
||||
|
||||
|
||||
_log('executing browserify via API');
|
||||
let bproc = browserify([], {
|
||||
let bproc = browserify([input], {
|
||||
debug: options.debug,
|
||||
commondir: false,
|
||||
paths: [path.join(nc, 'lib')],
|
||||
builtins: false,
|
||||
insertGlobalVars: insertGlobalVars,
|
||||
detectGlobals: true,
|
||||
browserField: false
|
||||
}).add(input);
|
||||
});
|
||||
|
||||
if (options.browserifyExcludes && Array.isArray(options.browserifyExcludes)) {
|
||||
for (let i = 0; i < options.browserifyExcludes.length; i++) {
|
||||
let lib = options.browserifyExcludes[i];
|
||||
_log('Excluding lib from browserify bundle', lib);
|
||||
_log('Excluding \'%s\' from browserify bundle', lib);
|
||||
bproc.exclude(lib);
|
||||
}
|
||||
}
|
||||
|
||||
// copy the excludes code for requires for now.
|
||||
if (options.browserifyRequires && Array.isArray(options.browserifyRequires)) {
|
||||
for (let i = 0; i < options.browserifyRequires.length; i++) {
|
||||
let lib = options.browserifyRequires[i];
|
||||
let name = lib.file || lib; // for object format.
|
||||
|
||||
_log('Force including \'%s\' in browserify bundle', name);
|
||||
bproc.require(lib);
|
||||
}
|
||||
}
|
||||
|
||||
if(options.debug) {
|
||||
bproc.require(require.resolve('source-map-support'))
|
||||
}
|
||||
@@ -87,6 +99,11 @@ function bundle(input, nc, options, complete) {
|
||||
.pipe(exorcist(mapfile, mapfile, './')) // generate source maps.
|
||||
.pipe(ws) // pipe to file
|
||||
|
||||
// error on require errors, still can't contionue. ffs browserify
|
||||
bprocbun.on('error', function(err) {
|
||||
_log('error', '[browserify] '+err);
|
||||
});
|
||||
|
||||
ws.on('error', function(err) {
|
||||
console.log(err);
|
||||
_log('error', 'Failed to save stdout to disk');
|
||||
|
||||
+17
-14
@@ -25,9 +25,21 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var path = require("path"),
|
||||
let path = require("path"),
|
||||
fs = require("fs");
|
||||
|
||||
/**
|
||||
* Accessort for embed
|
||||
**/
|
||||
const accessor = function(key) {
|
||||
if (embeddedFiles.hasOwnProperty(key)) {
|
||||
return new Buffer(embeddedFiles[key], 'base64');
|
||||
} else {
|
||||
//file was not embedded, throw err.
|
||||
throw new Error('Embedded file not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed files.
|
||||
*
|
||||
@@ -35,8 +47,8 @@ var path = require("path"),
|
||||
* @param {string} resourceRoot - root of resources.
|
||||
* @param {function} compelte - callback
|
||||
**/
|
||||
function embed(resourceFiles, resourceRoot, complete) {
|
||||
function encode(filePath) {
|
||||
function embed(resourceFiles, resourceRoot, options, complete) {
|
||||
const encode = function(filePath) {
|
||||
return fs.readFileSync(filePath).toString('base64');
|
||||
}
|
||||
|
||||
@@ -47,8 +59,8 @@ function embed(resourceFiles, resourceRoot, complete) {
|
||||
throw new Error("Bad Argument: resourceFiles is not an array");
|
||||
}
|
||||
|
||||
var buffer = "var embeddedFiles = {\n";
|
||||
for (var i = 0; i < resourceFiles.length; ++i) {
|
||||
let buffer = "var embeddedFiles = {\n";
|
||||
for (let i = 0; i < resourceFiles.length; ++i) {
|
||||
buffer += JSON.stringify(path.relative(resourceRoot, resourceFiles[i])) + ': "';
|
||||
buffer += encode(resourceFiles[i]) + '",\n';
|
||||
}
|
||||
@@ -58,13 +70,4 @@ function embed(resourceFiles, resourceRoot, complete) {
|
||||
complete(null, buffer);
|
||||
}
|
||||
|
||||
var accessor = function(key) {
|
||||
if (embeddedFiles.hasOwnProperty(key)) {
|
||||
return new Buffer(embeddedFiles[key], 'base64');
|
||||
} else {
|
||||
//file was not embedded, throw err.
|
||||
throw new Error('Embedded file not found');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = embed;
|
||||
|
||||
+23
-25
@@ -50,20 +50,6 @@ var isPy;
|
||||
var framework;
|
||||
var version;
|
||||
|
||||
var option_list = [
|
||||
"python",
|
||||
"debug",
|
||||
"input",
|
||||
"output",
|
||||
"nodeTempDir",
|
||||
"flags",
|
||||
"framework",
|
||||
"nodeConfigureArgs",
|
||||
"nodeMakeArgs",
|
||||
"nodeVersion",
|
||||
"browserifyExcludes"
|
||||
]
|
||||
|
||||
/**
|
||||
* Compiliation process.
|
||||
*/
|
||||
@@ -144,20 +130,18 @@ exports.compile = function(options, complete) {
|
||||
},
|
||||
|
||||
/**
|
||||
* bundle the application into one script
|
||||
*/
|
||||
|
||||
function combineProject(nc, next) {
|
||||
* Embed Resources into a base64 encoded array.
|
||||
**/
|
||||
function embedResources(nc, next) {
|
||||
nodeCompiler = nc;
|
||||
_log("bundle %s", options.input);
|
||||
bundle(options.input, nodeCompiler.dir, options, next);
|
||||
},
|
||||
|
||||
function embedResources(next) {
|
||||
_log("embedResources %s", options.resourceFiles);
|
||||
embed(options.resourceFiles, options.resourceRoot, next);
|
||||
embed(options.resourceFiles, options.resourceRoot, nc, next);
|
||||
},
|
||||
|
||||
/**
|
||||
* Write nexeres.js
|
||||
**/
|
||||
function writeResources(resources, next) {
|
||||
let resourcePath = path.join(nodeCompiler.dir, "lib", "nexeres.js");
|
||||
_log("resource -> %s", resourcePath);
|
||||
@@ -165,6 +149,14 @@ exports.compile = function(options, complete) {
|
||||
fs.writeFile(resourcePath, resources, next);
|
||||
},
|
||||
|
||||
/**
|
||||
* Bundle the application into one script
|
||||
**/
|
||||
function combineProject(next) {
|
||||
_log("bundle %s", options.input);
|
||||
bundle(options.input, nodeCompiler.dir, options, next);
|
||||
},
|
||||
|
||||
/**
|
||||
* monkeypatch some files so that the nexe.js file is loaded when the app runs
|
||||
*/
|
||||
@@ -686,6 +678,7 @@ function _monkeyPatchMainJs(compiler, complete) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make child_process work.
|
||||
*/
|
||||
function _monkeyPatchChildProcess(compiler, complete) {
|
||||
var childProcPath = path.join(compiler.dir, "lib", "child_process.js");
|
||||
@@ -953,7 +946,7 @@ function _logProgress(req) {
|
||||
* @return {object} nexe.compile - options object
|
||||
**/
|
||||
exports.package = function(path, options) {
|
||||
var _package; // scope
|
||||
let _package; // scope
|
||||
|
||||
// check if the file exists
|
||||
if (fs.existsSync(path) === false) {
|
||||
@@ -970,7 +963,7 @@ exports.package = function(path, options) {
|
||||
}
|
||||
|
||||
// construct the object
|
||||
var obj = {
|
||||
let obj = {
|
||||
input: (_package.nexe.input || options.i),
|
||||
output: (_package.nexe.output || options.o),
|
||||
flags: (_package.nexe.runtime.ignoreFlags || (options.f || false)),
|
||||
@@ -986,6 +979,11 @@ exports.package = function(path, options) {
|
||||
framework: (_package.nexe.runtime.framework || options.f)
|
||||
}
|
||||
|
||||
if(_package.nexe.browserify !== undefined) {
|
||||
obj.browserifyRequires = (_package.nexe.browserify.requires || []);
|
||||
obj.browserifyExcludes = (_package.nexe.browserify.excludes || []);
|
||||
}
|
||||
|
||||
Object.keys(_package.nexe).forEach(function(v, i) {
|
||||
if (v !== "runtime") {
|
||||
_log("log", v + " => '" + _package.nexe[v] + "'");
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
"input": "./bin/nexe",
|
||||
"output": "nexe^$",
|
||||
"temp": "src",
|
||||
"browserifyRequires": [
|
||||
"lib/nexeres.js"
|
||||
],
|
||||
"runtime": {
|
||||
"framework": "nodejs",
|
||||
"version": "5.5.0",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Hello, world! I'm in a file :)
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Embedded Files Test
|
||||
*
|
||||
* @author Jared Allard <jaredallard@outlook.com>
|
||||
* @version 0.0.1
|
||||
* @license MIT
|
||||
**/
|
||||
|
||||
const nexeres = require('nexeres');
|
||||
|
||||
console.log(nexeres.get('hw.txt').toString('ascii'))
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "embededfiles-test",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
},
|
||||
"nexe": {
|
||||
"input": "index.js",
|
||||
"output": "test.nex",
|
||||
"resourceFiles": [
|
||||
"hw.txt"
|
||||
],
|
||||
"browserify": {
|
||||
"excludes": [
|
||||
"./process"
|
||||
],
|
||||
"requires": [
|
||||
{
|
||||
"file": "nexeres",
|
||||
"expose": "nexeres"
|
||||
}
|
||||
]
|
||||
},
|
||||
"temp": "src",
|
||||
"debug": false,
|
||||
"runtime": {
|
||||
"framework": "node",
|
||||
"version": "5.5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user