documentation/lib/input/shallow.js
Tom MacWright 25152edeb9 style(prettier): Use prettier for code formatting (#710)
* style(prettier): Use prettier for code formatting

This saves us style issues. Also adds husky and lint-staged for pre-commit testing

Refs https://github.com/documentationjs/documentation/issues/709
2017-04-10 14:25:45 -04:00

47 lines
1.3 KiB
JavaScript

'use strict';
/* @flow */
var smartGlob = require('../smart_glob.js');
/**
* A readable source for content that doesn't do dependency resolution, but
* simply reads files and pushes them onto a stream.
*
* If an array of strings is provided as input to this method, then
* they will be treated as filenames and read into the stream.
*
* If an array of objects is provided, then we assume that they are valid
* objects with `source` and `file` properties, and don't use the filesystem
* at all. This is one way of getting documentation.js to run in a browser
* or without fs access.
*
* @param indexes entry points
* @param options parsing options
* @return promise with parsed files
*/
module.exports = function(
indexes /*: Array<string|Object>*/,
config /*: DocumentationConfig */
) /*: Promise<Array<SourceFile>>*/ {
var objects = [];
var strings = [];
for (var index of indexes) {
if (typeof index === 'string') {
strings.push(index);
} else if (typeof index === 'object') {
objects.push(index);
} else {
return Promise.reject(
new Error('Indexes should be either strings or objects')
);
}
}
return Promise.resolve(
objects.concat(
smartGlob(strings, config.parseExtension).map(file => ({
file
}))
)
);
};