1 | "use strict";
|
2 |
|
3 | const glob = require('./lib/globPromise');
|
4 |
|
5 | const func = require('./func');
|
6 |
|
7 | const filesToStream = require('./lib/filesToStream');
|
8 |
|
9 | const streamToString = require('./lib/streamToString');
|
10 |
|
11 | const _defaults = {
|
12 | glob: {},
|
13 | stream: false
|
14 | };
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | module.exports = function (patterns, options, callback) {
|
28 | if (func.typeOf(options) === 'function') {
|
29 | callback = options;
|
30 | options = {};
|
31 | }
|
32 |
|
33 | const settings = func.defaults(_defaults, options);
|
34 | const promise = glob(patterns, settings.glob).then(filesToStream).then(stream => {
|
35 | if (settings.stream) {
|
36 | return stream;
|
37 | }
|
38 |
|
39 | return streamToString(stream);
|
40 | }).then(result => {
|
41 | if (callback) {
|
42 | callback(null, result);
|
43 | } else {
|
44 | return result;
|
45 | }
|
46 | }).catch(err => {
|
47 | if (callback) {
|
48 | callback(err);
|
49 | } else {
|
50 | throw err;
|
51 | }
|
52 | });
|
53 |
|
54 | if (!callback) {
|
55 | return promise;
|
56 | }
|
57 | }; |
\ | No newline at end of file |