Source files reader for aster.
This module is part of aster and is available via aster.src.
You use it in build scripts whenever you want to get list of files for executing build pipeline:
var aster = require('aster');
aster.src([
'**/*.js',
'!node_modules/**'
])
.map(plugin1(optionsForPlugin1))
.map(plugin2(optionsForPlugin2))
// ...
.subscribe(aster.runner);aster.src returns Rx.Observable which, in order, emits single inner observable collection of file ASTs wrapped with custom {type: 'File', program: ..., loc: {source: 'fileName.js'}} node.
Type: String|String[]
List of patterns as array of strings or one comma-separated string.
Type: Object
glob module options (see https://github.com/isaacs/node-glob#options for details).
Can be used to customize how to created an Observable for javascript sources to be parsed. By default patterns is used by glob to pattern match files and then read each file as an observable stream.
function (patterns, options) {
// return Observable
}If you are observing source code that does not reside in files that can be filtered via the patterns, simply ignore and leave out this argument:
function (options) { ... }
The default Observable factory function used:
var readFile = Rx.Observable.fromNodeCallback(require('fs').readFile);
function filesSrc(patterns, options) {
return glob(patterns, options).flatMap(function (path) {
var fullPath = resolvePath(options.cwd || '', path);
return readFile(fullPath, 'utf-8').map(function (contents) {
return {
path: path,
contents: contents
};
});
});
}You can pass either a factory function or an Observable directly
function srcObserver(options) {
return Rx.Observable.of(options.sources);
}
const sources = ['var a = 1', 'var b = a + 2']
// alternatively:
// const srcObserver = Rx.Observable.of(options.sources);
aster.src({
srcObserver,
sources,
})Type: Boolean
Default: false
Set to true if you want patterns to be used as explicit list of files instead of globbing patterns (used by aster-watch).
Type: Function|Boolean|Object
Default: true
- If preconfigured parser (i.e.,
require('aster-parse-js')({loc: false})) or customfunction (files) { ... }is passed, it will be used as is. - If boolean is passed:
truemeans files should be parsed with parser associated with file extension (see aster-parse).falsemeans files should not be parsed and so they are pushed as{path: string, contents: string}object.
- If object is passed, it will be used as parsing options.
Method for registering custom parsers associated with extension, see asterParse.registerParser for details.

