-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (37 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var Rx = require('rx');
var glob = require('./glob');
var readFile = Rx.Observable.fromNodeCallback(require('fs').readFile);
var resolvePath = require('path').resolve;
var asterParse = require('aster-parse');
module.exports = function (patterns, options) {
options = options || {};
var files = 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
};
});
});
var parse;
switch (typeof options.parse) {
case 'function':
parse = options.parse;
break;
case 'boolean':
case 'undefined':
if (options.parse !== false) {
parse = asterParse();
}
break;
case 'object':
parse = asterParse(options.parse);
break;
default:
throw new TypeError('Unknown options.parse format.');
}
return Rx.Observable.return(parse ? parse(files) : files);
};
module.exports.registerParser = asterParse.registerParser;