mirror of
https://github.com/rschamp/gh-pages.git
synced 2026-05-02 09:43:58 +08:00
Merge pull request #8 from markdalgleish/improve-publish-api
Make base path required and options optional.
This commit is contained in:
20
lib/index.js
20
lib/index.js
@@ -48,10 +48,13 @@ function getRepo(options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a git branch to a remote (pushes gh-pages by default).
|
* Push a git branch to a remote (pushes gh-pages by default).
|
||||||
* @param {Object} config Publish options.
|
|
||||||
* @param {function(Error)} done Called upon completion.
|
|
||||||
*/
|
*/
|
||||||
exports.publish = function publish(config, done) {
|
exports.publish = function publish(basePath, config, done) {
|
||||||
|
if (typeof config === 'function') {
|
||||||
|
done = config;
|
||||||
|
config = {};
|
||||||
|
}
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
add: false,
|
add: false,
|
||||||
git: 'git',
|
git: 'git',
|
||||||
@@ -59,7 +62,6 @@ exports.publish = function publish(config, done) {
|
|||||||
dotfiles: false,
|
dotfiles: false,
|
||||||
branch: 'gh-pages',
|
branch: 'gh-pages',
|
||||||
remote: 'origin',
|
remote: 'origin',
|
||||||
base: process.cwd(),
|
|
||||||
src: '**/*',
|
src: '**/*',
|
||||||
only: '.',
|
only: '.',
|
||||||
push: true,
|
push: true,
|
||||||
@@ -72,7 +74,7 @@ exports.publish = function publish(config, done) {
|
|||||||
var options = _.extend({}, defaults, config);
|
var options = _.extend({}, defaults, config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!fs.statSync(options.base).isDirectory()) {
|
if (!fs.statSync(basePath).isDirectory()) {
|
||||||
done(new Error('The "base" option must be an existing directory'));
|
done(new Error('The "base" option must be an existing directory'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -82,10 +84,10 @@ exports.publish = function publish(config, done) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var files = glob.sync(options.src, {
|
var files = glob.sync(options.src, {
|
||||||
cwd: options.base,
|
cwd: basePath,
|
||||||
dot: options.dotfiles
|
dot: options.dotfiles
|
||||||
}).filter(function(file) {
|
}).filter(function(file) {
|
||||||
return !fs.statSync(path.join(options.base, file)).isDirectory();
|
return !fs.statSync(path.join(basePath, file)).isDirectory();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!Array.isArray(files) || files.length === 0) {
|
if (!Array.isArray(files) || files.length === 0) {
|
||||||
@@ -93,7 +95,7 @@ exports.publish = function publish(config, done) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var only = glob.sync(options.only, {cwd: options.base});
|
var only = glob.sync(options.only, {cwd: basePath});
|
||||||
|
|
||||||
function log(message) {
|
function log(message) {
|
||||||
if (!options.silent) {
|
if (!options.silent) {
|
||||||
@@ -149,7 +151,7 @@ exports.publish = function publish(config, done) {
|
|||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
log('Copying files');
|
log('Copying files');
|
||||||
return copy(files, options.base, options.clone);
|
return copy(files, basePath, options.clone);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
log('Adding all');
|
log('Adding all');
|
||||||
|
|||||||
Reference in New Issue
Block a user