summaryrefslogtreecommitdiffstats
path: root/bin/build.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-06 22:03:44 -0700
committerSamy Pessé <samypesse@gmail.com>2014-04-06 22:03:44 -0700
commit742229a98948f50fb75c978141626b1c9cfa9583 (patch)
tree619eac2faa52dc12d60d34da6a1ff69fabc54757 /bin/build.js
parent9fe80b878e94cef08d89b3af3aa60907bae45f56 (diff)
downloadgitbook-742229a98948f50fb75c978141626b1c9cfa9583.zip
gitbook-742229a98948f50fb75c978141626b1c9cfa9583.tar.gz
gitbook-742229a98948f50fb75c978141626b1c9cfa9583.tar.bz2
Add command "ebook" to generate an ebook
Diffstat (limited to 'bin/build.js')
-rw-r--r--bin/build.js65
1 files changed, 62 insertions, 3 deletions
diff --git a/bin/build.js b/bin/build.js
index bea8ff9..6050b88 100644
--- a/bin/build.js
+++ b/bin/build.js
@@ -1,11 +1,13 @@
var path = require('path');
var Q = require('q');
var _ = require('lodash');
+var tmp = require('tmp');
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 buildFunc = function(dir, options) {
@@ -34,7 +36,7 @@ var buildFunc = function(dir, options) {
var title = options.title || utils.titleCase(repo);
return generate.folder(
- {
+ _.extend(options.options || {}, {
input: dir,
output: outputDir,
title: title,
@@ -42,7 +44,7 @@ var buildFunc = function(dir, options) {
github: githubID,
generator: options.format,
theme: options.theme
- }
+ })
);
})
.then(function(output) {
@@ -51,4 +53,61 @@ var buildFunc = function(dir, options) {
}, utils.logError);
};
-module.exports = buildFunc; \ No newline at end of file
+var buildFiles = function(dir, outputFile, options, masterOptions) {
+ var ext = masterOptions.extension;
+
+ outputFile = outputFile || path.resolve(dir, "book."+ext);
+
+ Q.nfcall(tmp.dir)
+ .then(function(tmpDir) {
+ return buildFunc(
+ dir,
+ _.extend(options, {
+ output: tmpDir,
+ format: masterOptions.format,
+ options: masterOptions.options
+ })
+ )
+ .then(function(_options) {
+ var copyPDF = function(lang) {
+ var _outputFile = outputFile;
+ var _tmpDir = tmpDir;
+
+ if (lang) {
+ _outputFile = _outputFile.slice(0, -path.extname(_outputFile).length)+"_"+lang+path.extname(_outputFile);
+ _tmpDir = path.join(_tmpDir, lang);
+ }
+
+ console.log("Generating in", _outputFile);
+ return fs.copy(
+ path.join(_tmpDir, "index."+ext),
+ _outputFile
+ );
+ };
+
+ // Multi-langs book
+ return Q()
+ .then(function() {
+ if (_options.langsSummary) {
+ console.log("Generating for all the languages");
+ return Q.all(
+ _.map(_options.langsSummary.list, function(lang) {
+ return copyPDF(lang.lang);
+ })
+ );
+ } else {
+ return copyPDF();
+ }
+ })
+ .then(function() {
+ return fs.remove(tmpDir);
+ })
+ .fail(utils.logError);
+ });
+ })
+};
+
+module.exports = {
+ folder: buildFunc,
+ files: buildFiles
+}; \ No newline at end of file