+37
-3
@@ -1,20 +1,54 @@
|
||||
import { NexeCompiler } from '../compiler'
|
||||
import { resolve } from 'path'
|
||||
import { resolve, relative } from 'path'
|
||||
import { each } from '@calebboyd/semaphore'
|
||||
import resolveFiles from 'resolve-dependencies'
|
||||
import { dequote, STDIN_FLAG } from '../util'
|
||||
import { Readable } from 'stream'
|
||||
|
||||
function getStdIn(stdin: Readable): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
let out = ''
|
||||
stdin
|
||||
.setEncoding('utf8')
|
||||
.on('readable', () => {
|
||||
let current
|
||||
while ((current = stdin.read())) {
|
||||
out += current
|
||||
}
|
||||
})
|
||||
.on('end', () => resolve(out))
|
||||
})
|
||||
}
|
||||
|
||||
export default async function bundle(compiler: NexeCompiler, next: any) {
|
||||
const { bundle, cwd, input } = compiler.options
|
||||
compiler.entrypoint = './' + relative(cwd, input)
|
||||
compiler.startup = ';require("module").runMain();'
|
||||
|
||||
if (!bundle) {
|
||||
await compiler.addResource(resolve(cwd, input))
|
||||
return next()
|
||||
}
|
||||
|
||||
if (!input) {
|
||||
let code = ''
|
||||
if (typeof bundle === 'string') {
|
||||
code = await require(bundle).createBundle(compiler.options)
|
||||
}
|
||||
|
||||
if (input === STDIN_FLAG) {
|
||||
compiler.stdinUsed = true
|
||||
compiler.entrypoint = './__nexe_stdin.js'
|
||||
code = code || dequote(await getStdIn(process.stdin))
|
||||
await compiler.addResource(resolve(cwd, compiler.entrypoint), code)
|
||||
return next()
|
||||
}
|
||||
|
||||
const { files } = await resolveFiles(input, { cwd, expand: true, loadContent: false })
|
||||
const { files, warnings } = await resolveFiles(input, { cwd, expand: true, loadContent: false })
|
||||
|
||||
if (warnings.length) {
|
||||
throw new Error('Parsing Error:\n' + warnings.join('\n'))
|
||||
}
|
||||
|
||||
await each(Object.keys(files), (filename: string) => compiler.addResource(filename), {
|
||||
concurrency: 10
|
||||
})
|
||||
|
||||
+4
-35
@@ -1,24 +1,8 @@
|
||||
import { normalize, relative, resolve } from 'path'
|
||||
import { normalize, relative } from 'path'
|
||||
import { createWriteStream, chmodSync, statSync } from 'fs'
|
||||
import { dequote } from '../util'
|
||||
import { Readable } from 'stream'
|
||||
import { NexeCompiler } from '../compiler'
|
||||
import { NexeTarget } from '../target'
|
||||
|
||||
function getStdIn(stdin: Readable): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
let out = ''
|
||||
stdin
|
||||
.setEncoding('utf8')
|
||||
.on('readable', () => {
|
||||
let current
|
||||
while ((current = stdin.read())) {
|
||||
out += current
|
||||
}
|
||||
})
|
||||
.on('end', () => resolve(out))
|
||||
})
|
||||
}
|
||||
import { STDIN_FLAG } from '../util'
|
||||
|
||||
/**
|
||||
* The "cli" step detects the appropriate input. If no input options are passed,
|
||||
@@ -26,28 +10,13 @@ function getStdIn(stdin: Readable): Promise<string> {
|
||||
* After all the build steps have run, the output (the executable) is written to a file or piped to stdout.
|
||||
*
|
||||
* Configuration:
|
||||
* - compiler.options.input - file path to the input bundle.
|
||||
* - fallbacks: stdin, package.json#main
|
||||
* - compiler.options.output - file path to the output executable.
|
||||
* - fallbacks: stdout, nexe_ + epoch + ext
|
||||
*
|
||||
* @param {*} compiler
|
||||
* @param {*} next
|
||||
*/
|
||||
export default async function cli(compiler: NexeCompiler, next: () => Promise<void>) {
|
||||
const { log } = compiler
|
||||
let stdInUsed = false
|
||||
if (!process.stdin.isTTY && compiler.options.enableStdIn) {
|
||||
stdInUsed = true
|
||||
compiler.entrypoint = './__nexe_stdin.js'
|
||||
const code = dequote(await getStdIn(process.stdin))
|
||||
await compiler.addResource(resolve(compiler.options.cwd, compiler.entrypoint), code)
|
||||
} else {
|
||||
compiler.entrypoint = './' + relative(compiler.options.cwd, compiler.options.input)
|
||||
}
|
||||
compiler.startup = ';require("module").runMain();'
|
||||
await next()
|
||||
|
||||
const { log } = compiler
|
||||
const target = compiler.options.targets.shift() as NexeTarget
|
||||
const deliverable = await compiler.compileAsync(target)
|
||||
|
||||
@@ -67,7 +36,7 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
|
||||
const outputFile = relative(process.cwd(), output)
|
||||
step.log(
|
||||
`Entry: '${
|
||||
stdInUsed ? (compiler.options.mangle ? '[stdin]' : '[none]') : inputFile
|
||||
compiler.stdinUsed ? (compiler.options.mangle ? STDIN_FLAG : '[none]') : inputFile
|
||||
}' written to: ${outputFile}`
|
||||
)
|
||||
resolve(compiler.quit())
|
||||
|
||||
Reference in New Issue
Block a user