Fix #163: Move logic of git infos extraction to lib

This commit is contained in:
Samy Pessé
2014-04-28 20:16:30 +02:00
parent b715901f92
commit 5f1bfc0280
4 changed files with 32 additions and 67 deletions
+13 -23
View File
@@ -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;
+14
View File
@@ -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);
})
+3 -43
View File
@@ -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
};
+2 -1
View File
@@ -5,5 +5,6 @@ module.exports = {
lex: require('./lex'),
progress: require('./progress'),
navigation: require('./navigation'),
readme: require('./readme')
readme: require('./readme'),
git: require('./git')
};