summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cli/helper.js26
-rw-r--r--lib/cli/index.js23
-rw-r--r--lib/config/default.js5
-rw-r--r--lib/output/base.js6
-rw-r--r--lib/output/json.js10
-rw-r--r--lib/page/index.js3
6 files changed, 56 insertions, 17 deletions
diff --git a/lib/cli/helper.js b/lib/cli/helper.js
index 67bc502..61b9957 100644
--- a/lib/cli/helper.js
+++ b/lib/cli/helper.js
@@ -3,6 +3,9 @@ var _ = require('lodash');
var Book = require('../book');
var NodeFS = require('../fs/node');
var Logger = require('../utils/logger');
+var JSONOutput = require('../output/json');
+var WebsiteOutput = require('../output/website');
+var EBookOutput = require('../output/ebook');
var LOG_OPTION = {
name: 'log',
@@ -16,6 +19,19 @@ var LOG_OPTION = {
defaults: 'info'
};
+var FORMAT_OPTION = {
+ name: 'format',
+ description: 'Format to build to',
+ values: ['website', 'json', 'ebook'],
+ defaults: 'website'
+};
+
+var FORMATS = {
+ json: JSONOutput,
+ website: WebsiteOutput,
+ ebook: EBookOutput
+};
+
// Commands which is processing a book
// the root of the book is the first argument (or current directory)
function bookCmd(fn) {
@@ -29,13 +45,14 @@ function bookCmd(fn) {
logLevel: kwargs.log
});
- return fn(book, args.slice(1));
+ return fn(book, args.slice(1), kwargs);
};
}
// Commands which is working on a Output instance
-function outputCmd(Out, fn) {
- return bookCmd(function(book, args) {
+function outputCmd(fn) {
+ return bookCmd(function(book, args, kwargs) {
+ var Out = FORMATS[kwargs.format];
return fn(new Out(book), args);
});
}
@@ -45,6 +62,7 @@ module.exports = {
outputCmd: outputCmd,
options: {
- log: LOG_OPTION
+ log: LOG_OPTION,
+ format: FORMAT_OPTION
}
};
diff --git a/lib/cli/index.js b/lib/cli/index.js
index 4bb926b..c9a2e8f 100644
--- a/lib/cli/index.js
+++ b/lib/cli/index.js
@@ -1,4 +1,5 @@
-var Output = require('../output/base');
+var path = require('path');
+
var PluginsManager = require('../plugins');
var helper = require('./helper');
@@ -39,6 +40,26 @@ module.exports = {
var plugins = new PluginsManager(book);
return plugins.install();
})
+ },
+
+ {
+ name: 'build [book] [output]',
+ description: 'build a book',
+ options: [
+ helper.options.log,
+ helper.options.format
+ ],
+ exec: helper.outputCmd(function(output, args, kwargs) {
+ return output.book.parse()
+ .then(function() {
+ // Set output folder
+ if (args[0]) {
+ output.book.config.set('output', path.resolve(process.cwd(), args[0]));
+ }
+
+ return output.generate();
+ });
+ })
}
diff --git a/lib/config/default.js b/lib/config/default.js
index 92defaa..a35f1a5 100644
--- a/lib/config/default.js
+++ b/lib/config/default.js
@@ -1,11 +1,6 @@
var path = require('path');
module.exports = {
- // Options that can't be extend
- 'configFile': 'book',
- 'generator': 'website',
- 'extension': null,
-
// Book metadatas (somes are extracted from the README by default)
'title': null,
'description': null,
diff --git a/lib/output/base.js b/lib/output/base.js
index 02a69b1..997b8da 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -82,10 +82,12 @@ Output.prototype.generate = function() {
.value();
return Promise.serie(byTypes.asset, function(filename) {
+ that.log.info.ln('copy asset', filename);
return that.onAsset(filename);
})
.then(function() {
return Promise.serie(byTypes.page, function(filename) {
+ that.log.info.ln('process page', filename);
return that.onPage(that.book.getPage(filename));
});
});
@@ -94,6 +96,10 @@ Output.prototype.generate = function() {
// Finish the generation
.then(function() {
return that.finish();
+ })
+
+ .then(function() {
+ that.log.info.ln('generation finished with success!');
});
};
diff --git a/lib/output/json.js b/lib/output/json.js
index 913bc2b..9e6cb3c 100644
--- a/lib/output/json.js
+++ b/lib/output/json.js
@@ -1,7 +1,7 @@
+var _ = require('lodash');
var gitbook = require('../gitbook');
var conrefsLoader = require('./conrefs');
-
var JSONOutput = conrefsLoader();
JSONOutput.prototype.name = 'json';
@@ -18,13 +18,11 @@ JSONOutput.prototype.onPage = function(page) {
// Write as json
.then(function() {
- var json = {
+ var json = _.extend(page.getContext(), {
gitbook: {
version: gitbook.version
- },
- path: page.path,
- sections: page.content
- };
+ }
+ });
return that.writeFile(
page.withExtension('.json'),
diff --git a/lib/page/index.js b/lib/page/index.js
index 342830a..06b210e 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -118,7 +118,8 @@ Page.prototype.getContext = function() {
page: {
title: article? article.title : null,
next: next? next.getContext() : null,
- previous: prev? prev.getContext() : null
+ previous: prev? prev.getContext() : null,
+ content: this.content
}
};
};