summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-28 20:16:30 +0200
committerSamy Pessé <samypesse@gmail.com>2014-04-28 20:16:30 +0200
commit5f1bfc02805e074ab47bc8966410cf8042363c48 (patch)
tree74072e8dbb2963e3697846dbc59efbb214f76d6b
parentb715901f9203daacf705ce4e9db47b3d75980996 (diff)
downloadgitbook-5f1bfc02805e074ab47bc8966410cf8042363c48.zip
gitbook-5f1bfc02805e074ab47bc8966410cf8042363c48.tar.gz
gitbook-5f1bfc02805e074ab47bc8966410cf8042363c48.tar.bz2
Fix #163: Move logic of git infos extraction to lib
-rw-r--r--bin/build.js36
-rw-r--r--lib/generate/index.js14
-rw-r--r--lib/parse/git.js (renamed from bin/utils.js)46
-rw-r--r--lib/parse/index.js3
4 files changed, 32 insertions, 67 deletions
diff --git a/bin/build.js b/bin/build.js
index 37415bd..597b0de 100644
--- a/bin/build.js
+++ b/bin/build.js
@@ -34,29 +34,19 @@ var makeBuildFunc = function(converter) {
console.log('Starting build ...');
- // Get repo's URL
- return utils.gitURL(dir)
- .then(function(url) {
- // Get ID of repo
- return utils.githubID(url);
- }, function(err) {
- return null;
- })
- .then(function(repoID) {
- return converter(
- _.extend({}, options || {}, {
- input: dir,
- output: outputDir,
- title: options.title,
- description: options.intro,
- github: options.github || repoID,
- githubHost: options.githubHost,
- generator: options.format,
- plugins: options.plugins,
- pluginsConfig: pluginsConfig
- })
- );
- })
+ return converter(
+ _.extend({}, options || {}, {
+ input: dir,
+ output: outputDir,
+ title: options.title,
+ description: options.intro,
+ github: options.github,
+ githubHost: options.githubHost,
+ generator: options.format,
+ plugins: options.plugins,
+ pluginsConfig: pluginsConfig
+ })
+ )
.then(function(output) {
console.log("Successfuly built !");
return output;
diff --git a/lib/generate/index.js b/lib/generate/index.js
index 0c3e693..0e7eb6c 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -63,6 +63,20 @@ var generate = function(options) {
// Clean output folder
return fs.remove(options.output)
+ // Get repo's URL
+ .then(function() {
+ return parse.git.url(options.input)
+ .then(function(_url) {
+ // Get ID of repo
+ return parse.git.githubID(_url);
+ }, function(err) {
+ return null;
+ })
+ .then(function(repoId) {
+ options.github = options.github || repoId;
+ });
+ })
+
.then(function() {
return fs.mkdirp(options.output);
})
diff --git a/bin/utils.js b/lib/parse/git.js
index 45bc7d5..4478f20 100644
--- a/bin/utils.js
+++ b/lib/parse/git.js
@@ -1,16 +1,8 @@
var Q = require('q');
var _ = require('lodash');
-
-var http = require('http');
-var send = require('send');
-
var cp = require('child_process');
-var path = require('path');
var url = require('url');
-var Gaze = require('gaze').Gaze;
-
-
// Get the remote of a given repo
function gitURL(path) {
var d = Q.defer();
@@ -53,44 +45,12 @@ function githubID(_url) {
return null;
}
-function titleCase(str)
-{
+function titleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
-function watch(dir) {
- var d = Q.defer();
- dir = path.resolve(dir);
-
- var gaze = new Gaze("**/*.md", {
- cwd: dir
- });
-
- gaze.once("all", function(e, filepath) {
- gaze.close();
-
- d.resolve(filepath);
- });
- gaze.once("error", function(err) {
- gaze.close();
-
- d.reject(err);
- });
-
- return d.promise;
-}
-
-function logError(err) {
- console.log(err.stack || err.message || err);
- return Q.reject(err);
-};
-
-
-// Exports
module.exports = {
- gitURL: gitURL,
+ url: gitURL,
githubID: githubID,
- titleCase: titleCase,
- watch: watch,
- logError: logError
+ titleCase: titleCase
};
diff --git a/lib/parse/index.js b/lib/parse/index.js
index 0ebb03a..bb7779f 100644
--- a/lib/parse/index.js
+++ b/lib/parse/index.js
@@ -5,5 +5,6 @@ module.exports = {
lex: require('./lex'),
progress: require('./progress'),
navigation: require('./navigation'),
- readme: require('./readme')
+ readme: require('./readme'),
+ git: require('./git')
};