Skip to content

Commit 00bfbeb

Browse files
committed
Merge branch 'mbehzad-allow-options.source-to-be-an-string-array-as-well'
2 parents 00bbf84 + 2ab5adf commit 00bfbeb

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

lib/explain.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class Explain extends JsdocCommand {
1515
}
1616

1717
async _runJsdoc () {
18-
const cmd = `node ${this.jsdocPath} ${toSpawnArgs(this.jsdocOptions).join(' ')} -X ${arrayify(this.options.source ? this.tempFile.path : this.inputFileSet.files).join(' ')}`
18+
// console.log('SKDJKLAHS', this.options, this.tempFileSet?.files, this.inputFileSet.files)
19+
const cmd = this.options.source.length
20+
? `node ${this.jsdocPath} ${toSpawnArgs(this.jsdocOptions).join(' ')} -X ${this.tempFileSet.files.join(' ')}`
21+
: `node ${this.jsdocPath} ${toSpawnArgs(this.jsdocOptions).join(' ')} -X ${this.inputFileSet.files.join(' ')}`
1922

2023
let jsdocOutput = { stdout: '', stderr: '' }
2124
try {

lib/jsdoc-command.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class JsdocCommand {
1616
'Must set at least one of .files, .source or .configure'
1717
)
1818
options.files = arrayify(options.files)
19+
options.source = arrayify(options.source)
1920

2021
this.cache = cache
21-
this.tempFile = null
22-
if (options.source) this.tempFile = new TempFile(options.source)
22+
this.tempFiles = []
2323

2424
const jsdocOptions = Object.assign({}, options)
2525
delete jsdocOptions.files
@@ -43,12 +43,21 @@ class JsdocCommand {
4343
async execute () {
4444
this.inputFileSet = new FileSet()
4545
await this.inputFileSet.add(this.options.files)
46+
47+
if (this.options.source.length) {
48+
this.tempFiles = this.options.source.map(source => new TempFile(source))
49+
this.tempFileSet = new FileSet()
50+
await this.tempFileSet.add(this.tempFiles.map(t => t.path))
51+
}
52+
4653
let result
4754
try {
4855
result = await this.getOutput()
4956
} finally {
50-
if (this.tempFile) {
51-
this.tempFile.delete()
57+
if (this.tempFiles) {
58+
for (const tempFile of this.tempFiles) {
59+
tempFile.delete()
60+
}
5261
}
5362
}
5463
return result

lib/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Render extends JsdocCommand {
66
async getOutput () {
77
return new Promise((resolve, reject) => {
88
const jsdocArgs = toSpawnArgs(this.jsdocOptions)
9-
.concat(this.options.source ? this.tempFile.path : this.options.files)
9+
.concat(this.options.source.length ? this.tempFiles.map(t => t.path) : this.options.files)
1010

1111
jsdocArgs.unshift(this.jsdocPath)
1212
const handle = spawn('node', jsdocArgs, { stdio: 'inherit' })

test/render.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,34 @@ test.set('.render({ source, destination })', async function () {
2525
})
2626
})
2727

28+
test.set('.render({ source[], destination })', async function () {
29+
Fixture.createTmpFolder('tmp/renderSource')
30+
const sources = [
31+
`import Foo from "foo"
32+
/**
33+
* FooPrime is some child class
34+
* @class
35+
* @param {Object} - an input
36+
* @extends Foo
37+
*/
38+
function FooPrime() {}
39+
export default FooPrime
40+
`,
41+
`import Foo from "foo"
42+
/**
43+
* FooSecond is some other child class
44+
* @class
45+
* @param {Object} - an input
46+
* @extends Foo
47+
*/
48+
function FooSecond() {}
49+
export default FooSecond
50+
`]
51+
await jsdoc.render({ source: sources, destination: 'tmp/renderSource/out' })
52+
a.doesNotThrow(function () {
53+
statSync('./tmp/renderSource/out/FooPrime.html')
54+
statSync('./tmp/renderSource/out/FooSecond.html')
55+
})
56+
})
57+
2858
export { test, only, skip }

0 commit comments

Comments
 (0)