diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-10-05 09:54:40 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-10-05 09:54:40 +0200 |
commit | 6c2539e886a2893aa7d9bd4c4f84260145de6bd1 (patch) | |
tree | c90dce4bb73fd29f4c75cfffd6e65c508b21084d /lib/book.js | |
parent | aba25d8521a8f7129721c7b52621da7abc6222c5 (diff) | |
download | gitbook-6c2539e886a2893aa7d9bd4c4f84260145de6bd1.zip gitbook-6c2539e886a2893aa7d9bd4c4f84260145de6bd1.tar.gz gitbook-6c2539e886a2893aa7d9bd4c4f84260145de6bd1.tar.bz2 |
Move Book.init in another file
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/lib/book.js b/lib/book.js index 514a719..fa72618 100644 --- a/lib/book.js +++ b/lib/book.js @@ -812,78 +812,4 @@ Book.prototype.normError = function(err, opts, defs) { return err; }; -// Init and return a book -Book.init = function(root, opts) { - var book = new Book(root, opts); - var extensionToUse = ".md"; - - var chaptersPaths = function(chapters) { - return _.reduce(chapters || [], function(accu, chapter) { - var o = { - title: chapter.title - }; - if (chapter.path) o.path = chapter.path; - - return accu.concat( - [o].concat(chaptersPaths(chapter.articles)) - ); - }, []); - }; - - book.log.info.ln("init book at", root); - return fs.mkdirp(root) - .then(function() { - book.log.info.ln("detect structure from SUMMARY (if it exists)"); - return book.parseSummary(); - }) - .fail(function() { - return Q(); - }) - .then(function() { - var summary = book.summaryFile || "SUMMARY.md"; - var chapters = book.summary.chapters || []; - extensionToUse = path.extname(summary); - - if (chapters.length === 0) { - chapters = [ - { - title: "Summary", - path: "SUMMARY"+extensionToUse - }, - { - title: "Introduction", - path: "README"+extensionToUse - } - ]; - } - - return Q(chaptersPaths(chapters)); - }) - .then(function(chapters) { - // Create files that don"t exist - return Q.all(_.map(chapters, function(chapter) { - if (!chapter.path) return Q(); - var absolutePath = path.resolve(book.root, chapter.path); - - return fs.exists(absolutePath) - .then(function(exists) { - if(exists) { - book.log.info.ln("found", chapter.path); - return; - } else { - book.log.info.ln("create", chapter.path); - } - - return fs.mkdirp(path.dirname(absolutePath)) - .then(function() { - return fs.writeFile(absolutePath, "# "+chapter.title+"\n"); - }); - }); - })); - }) - .then(function() { - book.log.info.ln("initialization is finished"); - }); -}; - module.exports= Book; |