diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-21 14:26:09 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-04-21 14:26:09 -0700 |
commit | 4c90fdb7b27fdf6527b59097d489a9df0a929264 (patch) | |
tree | b00f3196f58ed712dea40dd69a261fc43129a651 /bin | |
parent | d1c1d7b75b6e4a304d031c4313cf54ae8aa3a11d (diff) | |
parent | 98c133df3c9077c1b06748c3206bea3ff011ed3a (diff) | |
download | gitbook-4c90fdb7b27fdf6527b59097d489a9df0a929264.zip gitbook-4c90fdb7b27fdf6527b59097d489a9df0a929264.tar.gz gitbook-4c90fdb7b27fdf6527b59097d489a9df0a929264.tar.bz2 |
Merge pull request #123 from GitbookIO/feature/plugins
Fix #65: Plugins Architecture
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 3059dde..6f90e1d 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, - theme: options.theme + 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 f46d4d1..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('--theme <path>', 'Path to theme directory'); -}; - -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) { |