From 1a6b113d6e0e670a1e698ff26120ed64ab03aca2 Mon Sep 17 00:00:00 2001 From: calebboyd Date: Thu, 3 Aug 2017 22:59:15 -0500 Subject: [PATCH] chore: wip bundling --- README.md | 12 ++++++------ package.json | 2 +- src/bundling/fuse.ts | 4 ++++ src/bundling/nexe-fuse.ts | 31 ++++++++++++++++++++++++++++++ src/cli.ts | 40 +++++++++++++++------------------------ src/options.ts | 11 +++++++++-- 6 files changed, 66 insertions(+), 34 deletions(-) create mode 100644 src/bundling/nexe-fuse.ts diff --git a/README.md b/README.md index f451b9e..84453d5 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ `nexe -i ./my-app-bundle.js -o ./my-app.exe` -- stdin & stdout interfaces +- stdin interface - `rollup -c | nexe --resource ./public/**/* > my-app.exe` + `rollup -c | nexe --resource ./public/**/* -o my-app.exe` For more CLI options see: `nexe --help` @@ -89,6 +89,10 @@ nexe.compile({ - #### `target: string` - Dash seperated platform-architecture-version. e.g. `'win32-ia32-6.10.3'` - default: `[process.platform, process.arch, process.version.slice(1)].join('-')` +- #### `bundle: string` + - Path to a custom bundling function. When executed it should either return a fusebox producer, or a string. + - If it is a string it will be required and the export `nexeBundle` will be used + - Defaults to the internal fuse-box configuration - #### `name: string` - Module friendly name of the application - default: basename of the input file, or `nexe_${Date.now()}` @@ -171,10 +175,6 @@ For examples, see the built in patches: [src/patches](src/patches) Any modifications made to `SourceFile#contents` will be maintained in the cache _without_ the need to explicitly write them back out, e.g. using `NexeCompiler#setFileContentsAsync`. -## Bundling - -Bundling in nexe has been decoupled from the compiler pipeline. While in beta it is completely seperate. Any bundle will always work with nexe as it is node compatible. - ### Native Modules Nexe has a plugin built for use with [fuse-box](http://fuse-box.org) > 2.2.1. This plugin currently supports modules that require `.node` files and those that use the `bindings` module. diff --git a/package.json b/package.json index 1ea528f..0854b58 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "bluebird": "^3.5.0", "chalk": "^1.1.3", "download": "^6.2.0", + "fuse-box": "^2.2.1", "globby": "^6.1.0", "memory-fs": "^0.4.1", "minimist": "^1.2.0", @@ -52,7 +53,6 @@ "@types/rimraf": "0.0.28", "mocha": "^3.2.0", "prettier": "^1.4.4", - "standard": "^10.0.1", "typescript": "^2.4.1" } } diff --git a/src/bundling/fuse.ts b/src/bundling/fuse.ts index c305d30..0eb921c 100644 --- a/src/bundling/fuse.ts +++ b/src/bundling/fuse.ts @@ -34,6 +34,10 @@ export interface NativeModulePluginOptions { | true } +export default function(options: NativeModulePluginOptions) { + return new NativeModulePlugin(options) +} + export class NativeModulePlugin { public test: RegExp public limit2Project = false diff --git a/src/bundling/nexe-fuse.ts b/src/bundling/nexe-fuse.ts new file mode 100644 index 0000000..6025f2b --- /dev/null +++ b/src/bundling/nexe-fuse.ts @@ -0,0 +1,31 @@ +import { NexeCompiler } from '../compiler' +import { FuseBox, JSONPlugin, CSSPlugin, HTMLPlugin } from 'fuse-box' +import NativeModulePlugin from './fuse' + +function bundleProducer(filename: string) { + const fuse = FuseBox.init({ + cache: false, + log: Boolean(process.env.NEXE_BUNDLE_DEBUG) || false, + homeDir: './', + writeBundles: false, + target: 'server', + plugins: [JSONPlugin(), CSSPlugin(), HTMLPlugin()] + }) + fuse.bundle('nexe').instructions(`> ${filename}`) + return fuse.run().then(x => { + if (x.bundles.size > 1) { + console.log('THROW', x.bundles) + } + let output = '' + x.bundles.forEach(y => (output = y.context.output.lastPrimaryOutput.content!.toString())) + }) +} + +export default function bundle(compiler: NexeCompiler, next: any) { + if (!compiler.options.bundle) { + return next() + } + + if (typeof compiler.options.bundle === 'string') { + } +} diff --git a/src/cli.ts b/src/cli.ts index fc866f9..9b397c0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -49,35 +49,25 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise { - deliverable.once('error', reject) - - if (shouldPipeOutput) { - log.step('Writing binary to stdout') - deliverable.pipe(process.stdout).once('error', reject) - resolve() - } else if (compiler.output) { - const step = log.step('Writing result to file') - deliverable - .pipe(createWriteStream(normalize(compiler.output))) - .on('error', reject) - .once('close', (e: Error) => { - if (e) { - reject(e) - } else if (compiler.output) { - chmodSync(compiler.output, '755') - step.log(`Executable written to: ${compiler.output}`) - resolve(compiler.quit()) - } - }) - } + const step = log.step('Writing result to file') + deliverable + .pipe(createWriteStream(normalize(compiler.output!))) + .on('error', reject) + .once('close', (e: Error) => { + if (e) { + reject(e) + } else if (compiler.output) { + chmodSync(compiler.output, '755') + step.log(`Executable written to: ${compiler.output}`) + resolve(compiler.quit()) + } + }) }) } diff --git a/src/options.ts b/src/options.ts index e5106c3..9aa3211 100644 --- a/src/options.ts +++ b/src/options.ts @@ -56,6 +56,7 @@ export interface NexeOptions { clean: boolean enableNodeCli: boolean sourceUrl?: string + bundle: boolean | string loglevel: 'info' | 'silent' | 'verbose' silent?: boolean verbose?: boolean @@ -80,6 +81,8 @@ const defaults = { targets: [], vcBuild: ['nosign', 'release'], enableNodeCli: false, + bundle: true, + build: true, patches: [] } const alias = { @@ -104,6 +107,7 @@ const argv = parseArgv(process.argv, { alias, default: defaults }) const help = ` nexe --help CLI OPTIONS + -b --build -- build from source -i --input =index.js -- application entry point -o --output =my-app.exe -- path to output file -t --target =win32-x64-6.10.3 -- *target a prebuilt binary @@ -116,7 +120,9 @@ nexe --help CLI OPTIONS -vc --vcBuild =x64 -- *pass arguments to vcbuild.bat -s --snapshot =/path/to/snapshot -- build with warmup snapshot -r --resource =./paths/**/* -- *embed file bytes within the binary + --bundle =./path/to/config -- pass a module path that exports nexeBundle --temp =./path/to/temp -- nexe temp files (for downloads and source builds) + --no-bundle -- set when input is already bundled --ico -- file name for alternate icon file (windows) --rc-* -- populate rc file options (windows) --clean -- force download of sources @@ -176,7 +182,7 @@ function extractName(options: NexeOptions) { function normalizeOptionsAsync(input: Partial) { if (argv.help || argv._.some((x: string) => x === 'version')) { - process.stderr.write(argv.help ? help : '2.0.0-beta.1' + EOL, () => process.exit(0)) + process.stderr.write(argv.help ? help : '2.0.0-beta.3' + EOL, () => process.exit(0)) } const options = Object.assign({}, defaults, input) as NexeOptions @@ -188,9 +194,10 @@ function normalizeOptionsAsync(input: Partial) { options.targets = flattenFilter(opts.target, options.targets) options.make = flattenFilter(options.make) options.vcBuild = flattenFilter(options.vcBuild) + options.configure = flattenFilter(options.configure) options.resources = flattenFilter(opts.resource, options.resources) options.rc = options.rc || extractCliMap(/^rc-.*/, options) - options.build = true // FIXME + if (options.build || options.padding === 0) { options.targets = [] options.build = true