summaryrefslogtreecommitdiffstats
path: root/lib/init.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-01-22 21:04:36 +0100
committerSamy Pessé <samypesse@gmail.com>2016-01-22 21:04:36 +0100
commit877f2e477b010f9f37a9044606f110a90f077680 (patch)
tree5cd61cf3b00ba10dc6110535ed9fdf67d8baba72 /lib/init.js
parentc8e2fc0e57d223c01a51d6ee186fc1662cd74d13 (diff)
downloadgitbook-877f2e477b010f9f37a9044606f110a90f077680.zip
gitbook-877f2e477b010f9f37a9044606f110a90f077680.tar.gz
gitbook-877f2e477b010f9f37a9044606f110a90f077680.tar.bz2
Start rewrite
Diffstat (limited to 'lib/init.js')
-rw-r--r--lib/init.js83
1 files changed, 0 insertions, 83 deletions
diff --git a/lib/init.js b/lib/init.js
deleted file mode 100644
index 2fc8016..0000000
--- a/lib/init.js
+++ /dev/null
@@ -1,83 +0,0 @@
-var _ = require('lodash');
-var Q = require('q');
-var path = require('path');
-
-var Book = require('./book');
-var fs = require('./utils/fs');
-
-// Initialize folder structure for a book
-// Read SUMMARY to created the right chapter
-function initBook(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 = initBook;