documentation/lib/input/shallow.js
Tom MacWright 631c6925d4 feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 (#648)
* feat(core): Switch to Promises everywhere. Adopt Node v4 ES6

Big changes:

* Uses template strings where appropriate
* Config and argument parsing is unified and there is no such thing
  as formatterOptions anymore. All user-passed options go through
  mergeConfig.
* The node API surface changed (again): `buildSync` is removed,
  building operations return Promises.
* Now using Flow for internal type annotations.

More changes:

* Remove buildSync command
* feat(inference): Partially implement object shorthand support
* Refs #649
* Use Flow annotations to  enforce types
* Keep flow but switch to comment syntax
* Clarify types
* More flow improvements
* Turn server into class
* LinkerStack becomes class too
* Fix comment description type
* Run flow on lint
* Many more flow fixes
* More intense flow refactoring
* Simplify inference steps
* Update inference tests, flow errors down to 1
* Continue refining types
* Fix more flow issues
* Use 'use strict' everywhere
* Make 'ast' property configurable
* Fix many tests
* Fix more tests
* Fix more tests
* Fix augments
* Test Markdown meta support
* Improve test coverage
* Switch back from for of to for for speed
2017-01-27 16:14:19 -05:00

42 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
}))));
};