diff options
Diffstat (limited to 'lib/generate/config.js')
-rw-r--r-- | lib/generate/config.js | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/generate/config.js b/lib/generate/config.js index 7ec0741..fb232a6 100644 --- a/lib/generate/config.js +++ b/lib/generate/config.js @@ -1,3 +1,4 @@ +var Q = require('q'); var _ = require('lodash'); var path = require('path'); @@ -16,9 +17,10 @@ var CONFIG = { // Configuration file to use "configFile": "book", - // Book title and description (defaults are extracted from the README) + // Book metadats (somes are extracted from the README by default) "title": null, "description": null, + "isbn": null, // For ebook format, the extension to use for generation (default is detected from output extension) // "epub", "pdf", "mobi" @@ -96,10 +98,32 @@ var CONFIG = { } }; +// Return complete configuration +var defaultsConfig = function(options) { + return _.merge(options || {}, CONFIG, _.defaults); +}; + +// Read configuration from book.json +var readConfig = function(options) { + options = defaultsConfig(options); + + return Q() + .then(function() { + try { + var _config = require(path.resolve(options.input, options.configFile)); + options = _.merge(options, _.omit(_config, 'input', 'configFile', 'defaultsPlugins', 'generator')); + } + catch(err) { + // No config file: not a big deal + return Q(); + } + }) + .thenResolve(options); +}; + module.exports = { CONFIG: CONFIG, - defaults: function(options) { - return _.merge(options || {}, CONFIG, _.defaults); - } + defaults: defaultsConfig, + read: readConfig } |