chore: wip bundling

This commit is contained in:
calebboyd
2017-08-03 22:59:15 -05:00
parent 15d919c302
commit 1a6b113d6e
6 changed files with 66 additions and 34 deletions
+6 -6
View File
@@ -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.
+1 -1
View File
@@ -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"
}
}
+4
View File
@@ -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
+31
View File
@@ -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') {
}
}
+15 -25
View File
@@ -49,35 +49,25 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
compiler.input = ''
}
compiler.input = compiler.input.trim()
await next()
const shouldPipeOutput = Boolean(!output && !process.stdout.isTTY)
const outputName = output || `${compiler.options.name}${isWindows ? '.exe' : ''}`
compiler.output = shouldPipeOutput ? null : outputName
compiler.output = output || `${compiler.options.name}${isWindows ? '.exe' : ''}`
const deliverable = await compiler.compileAsync()
return new Bluebird((resolve, reject) => {
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())
}
})
})
}
+9 -2
View File
@@ -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<NexeOptions>) {
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<NexeOptions>) {
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