Skip to content

Commit 0365a96

Browse files
committed
fix stdin interface
1 parent 43244d6 commit 0365a96

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

bin/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ if (options.src && options.src.length) {
2525
var parseStream = parse(options)
2626
parseStream
2727
.on('error', function (err) {
28-
stop(err.message, 1)
28+
stop(err.stack, 1)
2929
})
3030
.pipe(process.stdout)
3131
} else {
3232
var parseStream = parse(options)
3333
parseStream.on('error', function (err) {
34-
stop(err.message, 1)
34+
stop(err.stack, 1)
3535
})
3636
process.stdin.pipe(parseStream).pipe(process.stdout)
3737
}

es5/jsdoc-parse.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ var fileSet = require('file-set');
1212
var Transform = require('stream').Transform;
1313
var cliOptions = require('./cli-options');
1414
var os = require('os');
15-
var tempPath = require('temp-path');
15+
var getTempPath = require('temp-path');
16+
17+
function tempPath() {
18+
return getTempPath() + 'jsdoc-parse.js';
19+
}
1620

1721
module.exports = jsdocParse;
1822
jsdocParse.cliOptions = cliOptions.definitions;
@@ -134,16 +138,18 @@ function getJsdocOutput(src, options, done) {
134138
var handle = cp.spawn('node', args, { stdio: [process.stdin, outputFile, outputStderr] });
135139
handle.on('error', done);
136140
handle.on('close', function (code) {
141+
var stderr = fs.readFileSync(outputStderrPath, 'utf8');
142+
var stdout = fs.readFileSync(outputFilePath, 'utf8');
143+
if (/no input files/.test(stdout)) code = 1;
144+
137145
if (code) {
138-
var output = fs.readFileSync(outputStderrPath, 'utf8');
139146
fs.unlinkSync(outputFilePath);
140147
fs.unlinkSync(outputStderrPath);
141-
done(new Error(output));
148+
done(new Error(stderr || stdout));
142149
} else {
143-
var output = fs.readFileSync(outputFilePath, 'utf8');
144150
fs.unlinkSync(outputFilePath);
145151
fs.unlinkSync(outputStderrPath);
146-
done(null, output);
152+
done(null, stdout);
147153
}
148154
});
149155
}

lib/jsdoc-parse.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const fileSet = require('file-set')
99
const Transform = require('stream').Transform
1010
const cliOptions = require('./cli-options')
1111
const os = require('os')
12-
const tempPath = require('temp-path')
12+
const getTempPath = require('temp-path')
13+
14+
function tempPath () {
15+
return getTempPath() + 'jsdoc-parse.js'
16+
}
1317

1418
/**
1519
* Exports a single function to parse jsdoc data.
@@ -196,16 +200,18 @@ function getJsdocOutput (src, options, done) {
196200
var handle = cp.spawn('node', args, { stdio: [ process.stdin, outputFile, outputStderr ]})
197201
handle.on('error', done)
198202
handle.on('close', function (code) {
203+
const stderr = fs.readFileSync(outputStderrPath, 'utf8')
204+
const stdout = fs.readFileSync(outputFilePath, 'utf8')
205+
if (/no input files/.test(stdout)) code = 1
206+
199207
if (code) {
200-
const output = fs.readFileSync(outputStderrPath, 'utf8')
201208
fs.unlinkSync(outputFilePath)
202209
fs.unlinkSync(outputStderrPath)
203-
done(new Error(output))
210+
done(new Error(stderr || stdout))
204211
} else {
205-
const output = fs.readFileSync(outputFilePath, 'utf8')
206212
fs.unlinkSync(outputFilePath)
207213
fs.unlinkSync(outputStderrPath)
208-
done(null, output)
214+
done(null, stdout)
209215
}
210216
})
211217
}

0 commit comments

Comments
 (0)