1 | var Promise = require('bluebird');
|
2 | var streamRead = require('./stream');
|
3 |
|
4 | function bundleFiles(list, allfiles, route, concatChar, removeComments) {
|
5 | var p = Promise.resolve('');
|
6 |
|
7 | list.filter(function (b) {
|
8 | var file = allfiles.filter(function (path) {
|
9 | return b.indexOf(path) >= 0;
|
10 | });
|
11 | if (file.length > 0) {
|
12 | p = p.then(function (content) {
|
13 | return streamRead(route.get(file[0])).then(function (str) {
|
14 | return combine(content, str, concatChar, removeComments);
|
15 | });
|
16 | });
|
17 | }
|
18 | });
|
19 |
|
20 | return p;
|
21 | }
|
22 |
|
23 | function combine(content, target, concatChar, removeComments) {
|
24 | if (content.length > 0) {
|
25 | content += concatChar;
|
26 | if (!removeComments) {
|
27 |
|
28 |
|
29 | content += '\n';
|
30 | }
|
31 | }
|
32 | if (removeComments) {
|
33 | target = target
|
34 |
|
35 | .replace(/\/\*(.|\n)*?\*\//mg, '')
|
36 |
|
37 | .replace(/(^\s*|\s*$)/g, '');
|
38 | }
|
39 | return content + target;
|
40 | }
|
41 |
|
42 | module.exports = {
|
43 | bundleFiles: bundleFiles,
|
44 | combine: combine,
|
45 | };
|