summaryrefslogtreecommitdiffstats
path: root/lib/parse/parseIgnore.js
blob: d13663dc8f0d592143ef222b2f619c4f5cba9e7e (plain)
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
49
var Promise = require('../utils/promise');
var IGNORE_FILES = require('../constants/ignoreFiles');

/**
    Parse ignore files

    @param {Book}
    @return {Book}
*/
function parseIgnore(book) {
    if (book.isLanguageBook()) {
        return Promise.reject(new Error('Ignore files could be parsed for language books'));
    }

    var fs = book.getFS();
    var ignore = book.getIgnore();

    ignore = ignore.add([
        // Skip Git stuff
        '.git/',

        // Skip OS X meta data
        '.DS_Store',

        // Skip stuff installed by plugins
        'node_modules',

        // Skip book outputs
        '_book',

        // Ignore files in the templates folder
        '_layouts'
    ]);

    return Promise.serie(IGNORE_FILES, function(filename) {
        return fs.readAsString(filename)
        .then(function(content) {
            ignore = ignore.add(content.toString().split(/\r?\n/));
        }, function(err) {
            return Promise();
        });
    })

    .then(function() {
        return book.setIgnore(ignore);
    });
}

module.exports = parseIgnore;