Skip to content

allows options.source also to be an array of strings #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ A programmatic interface for [jsdoc3](https://github.com/jsdoc3/jsdoc) with a fe
* _inner_
* [~JsdocOptions](#module_jsdoc-api..JsdocOptions)
* [.files](#module_jsdoc-api..JsdocOptions.JsdocOptions+files) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
* [.source](#module_jsdoc-api..JsdocOptions.JsdocOptions+source) : <code>string</code>
* [.source](#module_jsdoc-api..JsdocOptions.JsdocOptions+source) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
* [.cache](#module_jsdoc-api..JsdocOptions.JsdocOptions+cache) : <code>boolean</code>
* [.access](#module_jsdoc-api..JsdocOptions.JsdocOptions+access) : <code>string</code>
* [.configure](#module_jsdoc-api..JsdocOptions.JsdocOptions+configure) : <code>string</code>
Expand Down Expand Up @@ -123,7 +123,7 @@ The jsdoc options, common for all operations.

* [~JsdocOptions](#module_jsdoc-api..JsdocOptions)
* [.files](#module_jsdoc-api..JsdocOptions.JsdocOptions+files) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
* [.source](#module_jsdoc-api..JsdocOptions.JsdocOptions+source) : <code>string</code>
* [.source](#module_jsdoc-api..JsdocOptions.JsdocOptions+source) : <code>string</code> \| <code>Array.&lt;string&gt;</code>
* [.cache](#module_jsdoc-api..JsdocOptions.JsdocOptions+cache) : <code>boolean</code>
* [.access](#module_jsdoc-api..JsdocOptions.JsdocOptions+access) : <code>string</code>
* [.configure](#module_jsdoc-api..JsdocOptions.JsdocOptions+configure) : <code>string</code>
Expand All @@ -146,8 +146,8 @@ One or more filenames to process. Either this or `source` must be supplied.
**Kind**: instance property of [<code>JsdocOptions</code>](#module_jsdoc-api..JsdocOptions)
<a name="module_jsdoc-api..JsdocOptions.JsdocOptions+source"></a>

#### options.source : <code>string</code>
A string containing source code to process. Either this or `source` must be supplied.
#### options.source : <code>string</code> \| <code>Array.&lt;string&gt;</code>
A string or array of strings containing source code to process. Either this or `files` must be supplied.

**Kind**: instance property of [<code>JsdocOptions</code>](#module_jsdoc-api..JsdocOptions)
<a name="module_jsdoc-api..JsdocOptions.JsdocOptions+cache"></a>
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class JsdocOptions {
this.files = arrayify(options.files)

/**
* A string containing source code to process. Either this or `source` must be supplied.
* @type {string}
* A string or array of strings containing source code to process. Either this or `files` must be supplied.
* @type {string|string[]}
*/
this.source = options.source

Expand Down
3 changes: 2 additions & 1 deletion lib/explain-sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
const JsdocCommand = require('./jsdoc-command')
const FileSet = require('file-set')

/**
* @static
Expand All @@ -23,7 +24,7 @@ class ExplainSync extends JsdocCommand {
const toSpawnArgs = require('object-to-spawn-args')
const jsdocArgs = toSpawnArgs(this.jsdocOptions)
.concat([ '-X' ])
.concat(this.options.source ? this.tempFile.path : this.inputFileSet.files)
.concat(this.options.source ? new FileSet(this.tempFiles.map(tempFile => tempFile.path)).files : this.inputFileSet.files)

jsdocArgs.unshift(this.jsdocPath)

Expand Down
3 changes: 2 additions & 1 deletion lib/explain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
const JsdocCommand = require('./jsdoc-command')
const FileSet = require('file-set')

/**
* @module explain
Expand Down Expand Up @@ -34,7 +35,7 @@ class Explain extends JsdocCommand {
const toSpawnArgs = require('object-to-spawn-args')
const jsdocArgs = toSpawnArgs(this.jsdocOptions)
.concat([ '-X' ])
.concat(this.options.source ? this.tempFile.path : this.inputFileSet.files)
.concat(this.options.source ? new FileSet(this.tempFiles.map(tempFile => tempFile.path)).files : this.inputFileSet.files)
jsdocArgs.unshift(this.jsdocPath)

const spawn = require('child_process').spawn
Expand Down
13 changes: 9 additions & 4 deletions lib/jsdoc-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ class JsdocCommand {
options.files = arrayify(options.files)

this.cache = cache
this.tempFile = null
this.tempFiles = null
const TempFile = require('./temp-file')
if (options.source) this.tempFile = new TempFile(options.source)
if (options.source) {
// make sure `options.source` is an array
if (!Array.isArray(options.source)) options.source = [options.source]

this.tempFiles = options.source.map(source => new TempFile(source))
}

const jsdocOptions = Object.assign({}, options)
delete jsdocOptions.files
Expand Down Expand Up @@ -94,8 +99,8 @@ class JsdocCommand {
* perform post-execution cleanup
*/
postExecute () {
if (this.tempFile) {
this.tempFile.delete()
if (this.tempFiles) {
this.tempFiles.forEach(tempFile => tempFile.delete())
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/render-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RenderSync extends JsdocCommand {
if (err) throw err
const toSpawnArgs = require('object-to-spawn-args')
const jsdocArgs = toSpawnArgs(this.jsdocOptions)
.concat(this.options.source ? this.tempFile.path : this.options.files)
.concat(this.options.source ? this.tempFiles.map(tempFile => tempFile.path) : this.options.files)

jsdocArgs.unshift(this.jsdocPath)

Expand Down
30 changes: 30 additions & 0 deletions test/render-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,33 @@ runner.test('.renderSync({ source, destination })', function () {
fs.statSync('./tmp/renderSync/out/index.html')
})
})

runner.test('.renderSync({ source[], destination })', function () {
Fixture.createTmpFolder('tmp/renderSync')
const sources = [
`import Foo from "foo"
/**
* FooPrime is some child class
* @class
* @param {Object} - an input
* @extends Foo
*/
function FooPrime() {}
export default FooPrime
`,
`import Foo from "foo"
/**
* FooSecond is some other child class
* @class
* @param {Object} - an input
* @extends Foo
*/
function FooSecond() {}
export default FooSecond
`]
jsdoc.renderSync({ source: sources, destination: 'tmp/renderSync/out' })
a.doesNotThrow(function () {
fs.statSync('./tmp/renderSync/out/FooPrime.html')
fs.statSync('./tmp/renderSync/out/FooSecond.html')
})
})