fix: disable stdin for programatic usage

This commit is contained in:
calebboyd
2017-09-29 17:49:17 -05:00
parent c8310ce3bc
commit 2a2526d3bc
3 changed files with 18 additions and 14 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "nexe",
"description": "Create a single executable out of your Node.js application",
"license": "MIT",
"version": "2.0.0-rc.9",
"version": "2.0.0-rc.10",
"contributors": [
"Craig Condon <craig.j.condon@gmail.com> (http://crcn.io)",
"Jared Allard <jaredallard@outlook.com>",
+2 -1
View File
@@ -34,6 +34,7 @@ export interface NexeOptions {
native: any
empty: boolean
sourceUrl?: string
enableStdIn?: boolean
python?: string
loglevel: 'info' | 'silent' | 'verbose'
silent?: boolean
@@ -82,7 +83,7 @@ const alias = {
l: 'loglevel',
'fake-argv': 'fakeArgv'
}
const argv = parseArgv(process.argv, { alias, default: defaults })
const argv = parseArgv(process.argv, { alias, default: { ...defaults, enableStdIn: true } })
const g = c.gray
let help = `
${c.bold('nexe <entry-file> [options]')}
+15 -12
View File
@@ -5,15 +5,18 @@ import { readFileAsync, dequote, isWindows } from '../util'
import { NexeCompiler } from '../compiler'
import { NexeTarget } from '../target'
function readStreamAsync(stream: NodeJS.ReadableStream): PromiseLike<string> {
function getStdIn(stdin: NodeJS.ReadStream): Promise<string> {
return new Promise(resolve => {
let input = ''
stream.setEncoding('utf-8')
stream.on('data', (x: string) => {
input += x
})
stream.once('end', () => resolve(dequote(input)))
stream.resume && stream.resume()
let out = ''
stdin
.setEncoding('utf8')
.on('readable', () => {
let current
while ((current = stdin.read())) {
out += current
}
})
.on('end', () => resolve(out))
})
}
@@ -34,9 +37,9 @@ function readStreamAsync(stream: NodeJS.ReadableStream): PromiseLike<string> {
export default async function cli(compiler: NexeCompiler, next: () => Promise<void>) {
const { log } = compiler
let stdInUsed = false
if (!process.stdin.isTTY) {
if (!process.stdin.isTTY && compiler.options.enableStdIn) {
stdInUsed = true
compiler.input = await readStreamAsync(process.stdin)
compiler.input = await getStdIn(process.stdin)
}
await next()
@@ -53,10 +56,10 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
if (e) {
reject(e)
} else if (compiler.output) {
chmodSync(compiler.output, '755')
chmodSync(compiler.output, '755') //todo fix erroneous rw mode change
step.log(
`Entry: '${stdInUsed
? '[stdin]'
? compiler.options.empty ? '[empty]' : '[stdin]'
: compiler.options.input}' written to: ${compiler.output}`
)
resolve(compiler.quit())