summaryrefslogtreecommitdiffstats
path: root/lib/parse/parseIgnore.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-04-30 20:15:08 +0200
committerSamy Pesse <samypesse@gmail.com>2016-04-30 20:15:08 +0200
commit36b49c66c6b75515bc84dd678fd52121a313e8d2 (patch)
treebc7e0f703d4557869943ec7f9495cac7a5027d4f /lib/parse/parseIgnore.js
parent87db7cf1d412fa6fbd18e9a7e4f4755f2c0c5547 (diff)
parent80b8e340dadc54377ff40500f86b1de631395806 (diff)
downloadgitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.zip
gitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.tar.gz
gitbook-36b49c66c6b75515bc84dd678fd52121a313e8d2.tar.bz2
Merge branch 'fixes'
Diffstat (limited to 'lib/parse/parseIgnore.js')
-rw-r--r--lib/parse/parseIgnore.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/parse/parseIgnore.js b/lib/parse/parseIgnore.js
new file mode 100644
index 0000000..b23bfd8
--- /dev/null
+++ b/lib/parse/parseIgnore.js
@@ -0,0 +1,50 @@
+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.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',
+
+ // Ignore files in the templates folder
+ '_layouts'
+ ]);
+
+ return Promise.serie(IGNORE_FILES, function(filename) {
+ return fs.readAsString(filename)
+ .then(function(content) {
+ ignore.addPattern(content.toString().split(/\r?\n/));
+ }, function(err) {
+ return Promise();
+ });
+ })
+
+ .thenResolve(book);
+}
+
+module.exports = parseIgnore;