diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-06-03 17:20:26 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-06-03 17:20:26 +0200 |
commit | 77c6f0e967b46896d93cbec78353219937010994 (patch) | |
tree | 3b1fcd87631d7c935bb0748bf02440ce4d0857e5 | |
parent | c803270af8c2f7d19de83f2997dbd7fe7675bd54 (diff) | |
parent | f0e18afec18eb2d6155fa3e9dc3c0ed7e3a38a89 (diff) | |
download | gitbook-77c6f0e967b46896d93cbec78353219937010994.zip gitbook-77c6f0e967b46896d93cbec78353219937010994.tar.gz gitbook-77c6f0e967b46896d93cbec78353219937010994.tar.bz2 |
Merge pull request #291 from bebraw/book.js
Allow book.js to be used in addition to book.json
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | bin/build.js | 2 | ||||
-rw-r--r-- | lib/generate/index.js | 18 |
3 files changed, 10 insertions, 12 deletions
@@ -32,7 +32,7 @@ Options for commands `build` and `serve` are: ``` -o, --output <directory> Path to output directory, defaults to ./_book -f, --format <name> Change generation format, defaults to site, availables are: site, page, ebook, json ---config <config file> Configuration file to use, defaults to book.json +--config <config file> Configuration file to use, defaults to book.js or book.json ``` GitBook loads the default configuration from a `book.json` file in the repository if it exists. diff --git a/bin/build.js b/bin/build.js index 35018cb..4bb6bb4 100644 --- a/bin/build.js +++ b/bin/build.js @@ -12,7 +12,7 @@ var buildCommand = function(command) { return command .option('-o, --output <directory>', 'Path to output directory, defaults to ./_book') .option('-f, --format <name>', 'Change generation format, defaults to site, availables are: '+_.keys(generators).join(", ")) - .option('--config <config file>', 'Configuration file to use, defualt to book.json') + .option('--config <config file>', 'Configuration file to use, defaults to book.js or book.json') }; diff --git a/lib/generate/index.js b/lib/generate/index.js index 520981c..adbcf26 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -54,7 +54,7 @@ var generate = function(options) { "output": null, // Config file (relative to input) - "configFile": "book.json", + "configFile": "book", // Output generator "generator": "site", @@ -93,17 +93,15 @@ var generate = function(options) { // Read config file .then(function() { - return fs.readFile(path.resolve(options.input, options.configFile)) - .then(function(_config) { - // Extend current config - _config = JSON.parse(_config); - _config = _.omit(_config, 'input', 'configFile', 'defaultsPlugins'); - - _.extend(options, _config); - }, function() { + try { + var _config = require(path.resolve(options.input, options.configFile)); + + _.extend(options, _.omit(_config, 'input', 'configFile', 'defaultsPlugins')); + } + catch(err) { // No config file: not a big deal return Q(); - }); + } }) // Read readme |