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

var DEFAULT_IGNORES = [
    // 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'
];

/**
    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(DEFAULT_IGNORES);

    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;