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

/**
    Parse ignore files

    @param {Book}
    @return {Book}
*/
function parseIgnore(book) {
    var fs = book.getFS();
    var ignore = book.getIgnore();

    ignore.addPattern([
        // Skip Git stuff
        '.git/',

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

        // Skip stuff installed by plugins
        'node_modules',

        // Skip book outputs
        '_book',
        '*.pdf',
        '*.epub',
        '*.mobi'
    ]);

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

    .thenResolve(book);
}

module.exports = parseIgnore;