diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-11-30 13:04:38 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-11-30 13:04:38 +0100 |
commit | ed48f5f3eede0f55ddc5fc4a65b319ce4e3875d5 (patch) | |
tree | 0a52f9e0727b1a0798996ae97d711b9780f7d289 /lib/generate/config.js | |
parent | 7b4accb117d1e3dbd7b6853a7455d96b6fd0f352 (diff) | |
download | gitbook-ed48f5f3eede0f55ddc5fc4a65b319ce4e3875d5.zip gitbook-ed48f5f3eede0f55ddc5fc4a65b319ce4e3875d5.tar.gz gitbook-ed48f5f3eede0f55ddc5fc4a65b319ce4e3875d5.tar.bz2 |
Add command "install" to install plugins from book.json
Diffstat (limited to 'lib/generate/config.js')
-rw-r--r-- | lib/generate/config.js | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/generate/config.js b/lib/generate/config.js index 7ec0741..d2054df 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'); @@ -96,10 +97,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 } |