diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-24 18:07:17 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-24 18:07:17 +0100 |
commit | 0b4a6b5362795f25594aabb458378df1599e4dbd (patch) | |
tree | f5511e33d640cd9493363414907f4e524b1e6029 /lib/cli | |
parent | 3a0636046ea0b9bc898438d502e3bf80f6c4d312 (diff) | |
download | gitbook-0b4a6b5362795f25594aabb458378df1599e4dbd.zip gitbook-0b4a6b5362795f25594aabb458378df1599e4dbd.tar.gz gitbook-0b4a6b5362795f25594aabb458378df1599e4dbd.tar.bz2 |
Output folder is an option for FolderOutput
Diffstat (limited to 'lib/cli')
-rw-r--r-- | lib/cli/helper.js | 49 | ||||
-rw-r--r-- | lib/cli/index.js | 5 |
2 files changed, 40 insertions, 14 deletions
diff --git a/lib/cli/helper.js b/lib/cli/helper.js index e62c8d9..4cd7f21 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 Promise = require('../utils/promise'); var fs = require('../utils/fs'); var JSONOutput = require('../output/json'); var WebsiteOutput = require('../output/website'); @@ -54,7 +55,16 @@ function bookCmd(fn) { function outputCmd(fn) { return bookCmd(function(book, args, kwargs) { var Out = FORMATS[kwargs.format]; - return fn(new Out(book), args); + var outputFolder = undefined; + + // Set output folder + if (args[0]) { + outputFolder = path.resolve(process.cwd(), args[0]); + } + + return fn(new Out(book, { + root: outputFolder + }), args); }); } @@ -69,24 +79,45 @@ function ebookCmd(format) { exec: bookCmd(function(book, args, kwargs) { return fs.tmpDir() .then(function(dir) { - var outputFile = path.resolve(process.cwd(), args[1] || 'book.' + format); + var ext = '.'+format; + var outputFile = path.resolve(process.cwd(), args[1] || ('book' + ext)); var output = new EBookOutput(book, { + root: dir, format: format }); return output.book.parse() .then(function() { - // Set output folder - output.book.config.set('output', dir); return output.generate(); }) - // Copy the ebook file + // Copy the ebook files .then(function() { - return fs.copy( - path.resolve(dir, 'index.' + format), - outputFile - ); + if (output.book.isMultilingual()) { + return Promise.serie(output.book.langs.list(), function(lang) { + var _outputFile = path.join( + path.dirname(outputFile), + path.basename(outputFile, ext) + '_' + lang.id + ext + ); + + return fs.copy( + path.resolve(dir, lang.id, 'index' + ext), + _outputFile + ); + }) + .thenResolve(output.book.langs.count()); + } else { + return fs.copy( + path.resolve(dir, 'index' + ext), + outputFile + ).thenResolve(1); + } + }) + .then(function(n) { + output.book.log.info.ok(n+' file(s) generated'); + + output.book.log.info.ln('cleaning up... '); + return output.book.log.info.promise(fs.rmDir(dir)); }); }); }) diff --git a/lib/cli/index.js b/lib/cli/index.js index 05f97b0..33df69f 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -64,11 +64,6 @@ module.exports = { exec: helper.outputCmd(function(output, args, kwargs) { return output.book.parse() .then(function() { - // Set output folder - if (args[0]) { - output.book.config.set('output', path.resolve(process.cwd(), args[0])); - } - return output.generate(); }); }) |