diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-17 13:30:45 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-17 13:30:45 +0100 |
commit | 853ba6079c37aa747721c8ee5d014479e69f3ad9 (patch) | |
tree | 60f655c942bafdc3e2caa6867b62a2173708a30f | |
parent | b6104c64fecb72c9f40554600d456c27dbd18be8 (diff) | |
download | gitbook-853ba6079c37aa747721c8ee5d014479e69f3ad9.zip gitbook-853ba6079c37aa747721c8ee5d014479e69f3ad9.tar.gz gitbook-853ba6079c37aa747721c8ee5d014479e69f3ad9.tar.bz2 |
Correctly clean and ignore output folder
-rw-r--r-- | lib/output/base.js | 23 | ||||
-rw-r--r-- | lib/output/folder.js | 27 | ||||
-rw-r--r-- | lib/utils/fs.js | 11 | ||||
-rw-r--r-- | package.json | 3 |
4 files changed, 49 insertions, 15 deletions
diff --git a/lib/output/base.js b/lib/output/base.js index 997b8da..6ac3d7e 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -27,18 +27,6 @@ function Output(book) { // Files to ignore in output this.ignore = Ignore(); - this.ignore.addPattern(_.compact([ - '.gitignore', - '.ignore', - '.bookignore', - - // The configuration file should not be copied in the output - this.book.config.path, - - // Structure file to ignore - this.book.summary.path, - this.book.langs.path - ])); } // Start the generation, for a parsed book @@ -105,7 +93,18 @@ Output.prototype.generate = function() { // Prepare the generation Output.prototype.prepare = function() { + this.ignore.addPattern(_.compact([ + '.gitignore', + '.ignore', + '.bookignore', + // The configuration file should not be copied in the output + this.book.config.path, + + // Structure file to ignore + this.book.summary.path, + this.book.langs.path + ])); }; // Write a page (parsable file), ex: markdown, etc diff --git a/lib/output/folder.js b/lib/output/folder.js index 9964ecd..05843cd 100644 --- a/lib/output/folder.js +++ b/lib/output/folder.js @@ -30,7 +30,32 @@ module.exports = function folderOutput(Base) { // Prepare the generation by creating the output folder FolderOutput.prototype.prepare = function() { - return fs.mkdirp(this.root()); + var that = this; + + return Promise() + .then(function() { + return Base.prototype.prepare.apply(that); + }) + + // Cleanup output folder + .then(function() { + return fs.rmDir(that.root()) + .fail(function() { + return Promise(); + }); + }) + + // Create output folder + .then(function() { + return fs.mkdirp(that.root()); + }) + + // Add output folder to ignored files + .then(function() { + that.ignore.addPattern([ + path.relative(that.book.root, that.root()) + ]); + }); }; diff --git a/lib/utils/fs.js b/lib/utils/fs.js index 840d1f9..c2f2bd3 100644 --- a/lib/utils/fs.js +++ b/lib/utils/fs.js @@ -1,6 +1,7 @@ var fs = require('graceful-fs'); var mkdirp = require('mkdirp'); var destroy = require('destroy'); +var rmdir = require('rmdir'); var tmp = require('tmp'); var request = require('request'); var path = require('path'); @@ -95,6 +96,13 @@ function ensureFile(filename) { return Promise.nfcall(mkdirp, base); } +// Remove a folder +function rmDir(base) { + return Promise.nfcall(rmdir, base, { + fs: fs + }); +} + module.exports = { exists: fileExists, existsSync: fs.existsSync, @@ -110,5 +118,6 @@ module.exports = { tmpDir: genTmpDir, download: download, uniqueFilename: uniqueFilename, - ensure: ensureFile + ensure: ensureFile, + rmDir: rmDir }; diff --git a/package.json b/package.json index 3eb6001..84da7c0 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "github-slugid": "1.0.0", "destroy": "1.0.4", "ignore": "2.2.19", - "deprecated": "0.0.1" + "deprecated": "0.0.1", + "rmdir": "1.2.0" }, "devDependencies": { "eslint": "1.5.0", |