diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-31 13:51:31 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-31 13:51:31 -0700 |
commit | a88ea48206e157821075064097952335cec063ed (patch) | |
tree | f28077aa8b5049dd6818f3fd1fec5cad834b603b /bin/gitbook.js | |
parent | 264a506e8b3039b89fe0aa1d8e8f3f33cc360cff (diff) | |
download | gitbook-a88ea48206e157821075064097952335cec063ed.zip gitbook-a88ea48206e157821075064097952335cec063ed.tar.gz gitbook-a88ea48206e157821075064097952335cec063ed.tar.bz2 |
Initial gitbook binary
Diffstat (limited to 'bin/gitbook.js')
-rwxr-xr-x | bin/gitbook.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/gitbook.js b/bin/gitbook.js new file mode 100755 index 0000000..6ec3e79 --- /dev/null +++ b/bin/gitbook.js @@ -0,0 +1,60 @@ +#! /usr/bin/env node + +// Requires +var _ = require('lodash'); +var path = require('path'); +var prog = require('commander'); + +var pkg = require('../package.json'); +var generate = require("../lib/generate"); + +var utils = require('./utils'); + + +// General options +prog +.version(pkg.version) +.option('-d, --dir <source_directory>', 'Source directory of book, containing Markdown files'); + + +prog +.command('build [source_dir]') +.description('Build a gitbook from a directory') +.option('-o, --output <directory>', 'Path to output directory, defaults to ./_book') +.option('-t, --title <name>', 'Name of the book to generate, defaults to repo name') +.option('-g, --github <repo_path>', 'ID of github repo like : username/repo') +.action(function(dir, options) { + dir = dir || process.cwd(); + outputDir = options.output || path.join(dir, '_book'); + + // Get repo's URL + utils.gitURL(dir) + .then(function(url) { + // Get ID of repo + return utils.githubID(url); + }) + .then(function(repoID) { + var parts = repoID.split('/', 2); + var user = parts[0], repo = parts[1]; + + return generate.folder( + dir, + outputDir, + { + title: options.title || utils.titleCase(repo), + github: options.github || repoID + } + ); + }) + .then(function(output) { + console.log(output); + }, function(err) { + console.log(err.stack, err); + }); +}); + + +// Parse and fallback to help if no args +if(_.isEmpty(prog.parse(process.argv).args) && process.argv.length === 2) { + prog.help(); +} |