diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-21 18:33:07 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-21 18:33:07 +0100 |
commit | 7b2e332f6c0f3b3fa3e278bb82585bdd4e2deb0b (patch) | |
tree | fc8e301fdeb18d96a95bc26e0c833316f90edec8 /lib/cli/helper.js | |
parent | ab541c165366feeebda10e1b5dfce42ba1b5db3f (diff) | |
download | gitbook-7b2e332f6c0f3b3fa3e278bb82585bdd4e2deb0b.zip gitbook-7b2e332f6c0f3b3fa3e278bb82585bdd4e2deb0b.tar.gz gitbook-7b2e332f6c0f3b3fa3e278bb82585bdd4e2deb0b.tar.bz2 |
Complete ebook command to output one file
Diffstat (limited to 'lib/cli/helper.js')
-rw-r--r-- | lib/cli/helper.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/cli/helper.js b/lib/cli/helper.js index 6dae58c..9510b49 100644 --- a/lib/cli/helper.js +++ b/lib/cli/helper.js @@ -4,6 +4,7 @@ var path = require('path'); var Book = require('../book'); var NodeFS = require('../fs/node'); var Logger = require('../utils/logger'); +var fs = require('../utils/fs'); var JSONOutput = require('../output/json'); var WebsiteOutput = require('../output/website'); var EBookOutput = require('../output/ebook'); @@ -57,9 +58,45 @@ function outputCmd(fn) { }); } +// Command to generate an ebook +function ebookCmd(format) { + return { + name: format + ' [book] [output] [file]', + description: 'generates ebook '+format, + options: [ + LOG_OPTION + ], + exec: bookCmd(function(book, args, kwargs) { + return fs.tmpDir() + .then(function(dir) { + var outputFile = path.resolve(process.cwd(), args[1] || 'book.' + format); + var output = new EBookOutput(book, { + format: format + }); + + return output.book.parse() + .then(function() { + // Set output folder + output.book.config.set('output', dir); + return output.generate(); + }) + + // Copy the ebook file + .then(function() { + return fs.copy( + path.resolve(dir, 'index.' + format), + outputFile + ); + }); + }); + }) + }; +} + module.exports = { bookCmd: bookCmd, outputCmd: outputCmd, + ebookCmd: ebookCmd, options: { log: LOG_OPTION, |