diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-21 22:58:51 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-21 22:58:51 +0200 |
commit | f86c27b090ab88598679b7e69b87c3286bdc7a17 (patch) | |
tree | 1b8680536cb7f7f88639eaf8e6a7a5805ff09b7c /bin | |
parent | b5b8ed72a55e0a6a23aa7695ab223a0e7c8c7cc6 (diff) | |
download | gitbook-f86c27b090ab88598679b7e69b87c3286bdc7a17.zip gitbook-f86c27b090ab88598679b7e69b87c3286bdc7a17.tar.gz gitbook-f86c27b090ab88598679b7e69b87c3286bdc7a17.tar.bz2 |
Add option --pluginsConfig
Diffstat (limited to 'bin')
-rw-r--r-- | bin/build.js | 33 | ||||
-rwxr-xr-x | bin/gitbook.js | 19 |
2 files changed, 31 insertions, 21 deletions
diff --git a/bin/build.js b/bin/build.js index 53593cb..5948fe3 100644 --- a/bin/build.js +++ b/bin/build.js @@ -1,18 +1,37 @@ var path = require('path'); var Q = require('q'); var _ = require('lodash'); +var fs = require('fs'); var utils = require('./utils'); - var generate = require("../lib/generate"); var parse = require("../lib/parse"); -var fs = require('../lib/generate/fs'); var generators = require("../lib/generate").generators; +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('-t, --title <name>', 'Name of the book to generate, default is extracted from readme') + .option('-i, --intro <intro>', 'Description of the book to generate, default is extracted from readme') + .option('--plugins <plugins>', 'List of plugins to use separated by ":"') + .option('--pluginsConfig <json file>', 'JSON File containing plugins configuration') + .option('-g, --github <repo_path>', 'ID of github repo like : username/repo') + .option('--githubHost <url>', 'The url of the github host (defaults to https://github.com/'); +}; + + var makeBuildFunc = function(converter) { return function(dir, options) { dir = dir || process.cwd(); - outputDir = options.output + outputDir = options.output; + + // Read plugins config + var pluginsConfig = {}; + if (options.pluginsConfig) { + pluginsConfig = JSON.parse(fs.readFileSync(options.pluginsConfig)) + } + console.log('Starting build ...'); // Get repo's URL @@ -33,7 +52,8 @@ var makeBuildFunc = function(converter) { github: options.github || repoID, githubHost: options.githubHost, generator: options.format, - plugins: options.plugins + plugins: options.plugins, + pluginsConfig: pluginsConfig }) ); }) @@ -42,9 +62,10 @@ var makeBuildFunc = function(converter) { return output; }, utils.logError); }; -} +}; module.exports = { folder: makeBuildFunc(generate.folder), - file: makeBuildFunc(generate.file) + file: makeBuildFunc(generate.file), + command: buildCommand }; diff --git a/bin/gitbook.js b/bin/gitbook.js index d254c10..88ba5e2 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -17,22 +17,11 @@ var build = require('./build'); prog .version(pkg.version); -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('-t, --title <name>', 'Name of the book to generate, default is extracted from readme') - .option('-i, --intro <intro>', 'Description of the book to generate, default is extracted from readme') - .option('-g, --github <repo_path>', 'ID of github repo like : username/repo') - .option('--githubHost <url>', 'The url of the github host (defaults to https://github.com/') - .option('--plugins <plugins>', 'List of plugins to use separated by ":"'); -}; - -buildCommand(prog.command('build [source_dir]')) +build.command(prog.command('build [source_dir]')) .description('Build a gitbook from a directory') .action(build.folder); -buildCommand(prog.command('serve [source_dir]')) +build.command(prog.command('serve [source_dir]')) .description('Build then serve a gitbook from a directory') .option('-p, --port <port>', 'Port for server to listen on', 4000) .action(function(dir, options) { @@ -50,7 +39,7 @@ buildCommand(prog.command('serve [source_dir]')) }); }); -buildCommand(prog.command('pdf [source_dir]')) +build.command(prog.command('pdf [source_dir]')) .description('Build a gitbook as a PDF') .option('-pf, --paperformat <format>', 'PDF paper format (default is A4): "5in*7.5in", "10cm*20cm", "A4", "Letter"') .action(function(dir, options) { @@ -60,7 +49,7 @@ buildCommand(prog.command('pdf [source_dir]')) })); }); -buildCommand(prog.command('ebook [source_dir]')) +build.command(prog.command('ebook [source_dir]')) .description('Build a gitbook as a eBook') .option('-c, --cover <path>', 'Cover image, default is cover.png if exists') .action(function(dir, options) { |