summaryrefslogtreecommitdiffstats
path: root/lib/cli
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 13:12:34 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 13:12:34 +0100
commitb6104c64fecb72c9f40554600d456c27dbd18be8 (patch)
tree0c48caf160f8b8a2c54f4cfa76c0f586364dbc8b /lib/cli
parente95678cf3a3cfbcbfa8b64ca16c4030417187e88 (diff)
downloadgitbook-b6104c64fecb72c9f40554600d456c27dbd18be8.zip
gitbook-b6104c64fecb72c9f40554600d456c27dbd18be8.tar.gz
gitbook-b6104c64fecb72c9f40554600d456c27dbd18be8.tar.bz2
Use same json for page context and json builds
Diffstat (limited to 'lib/cli')
-rw-r--r--lib/cli/helper.js26
-rw-r--r--lib/cli/index.js23
2 files changed, 44 insertions, 5 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();
+ });
+ })
}