Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default value for git option #312

Merged
merged 1 commit into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions bin/gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,35 @@ function main(args) {
.option(
'-s, --src <src>',
'Pattern used to select which files to publish',
'**/*'
ghpages.defaults.src
)
.option(
'-b, --branch <branch>',
'Name of the branch you are pushing to',
'gh-pages'
ghpages.defaults.branch
)
.option(
'-e, --dest <dest>',
'Target directory within the destination branch (relative to the root)',
'.'
ghpages.defaults.dest
)
.option('-a, --add', 'Only add, and never remove existing files')
.option('-x, --silent', 'Do not output the repository url')
.option('-m, --message <message>', 'commit message', 'Updates')
.option(
'-m, --message <message>',
'commit message',
ghpages.defaults.message
)
.option('-g, --tag <tag>', 'add tag to commit')
.option('--git <git>', 'Path to git executable')
.option('--git <git>', 'Path to git executable', ghpages.defaults.git)
.option('-t, --dotfiles', 'Include dotfiles')
.option('-r, --repo <repo>', 'URL of the repository you are pushing to')
.option('-p, --depth <depth>', 'depth for clone', 1)
.option('-o, --remote <name>', 'The name of the remote', 'origin')
.option('-p, --depth <depth>', 'depth for clone', ghpages.defaults.depth)
.option(
'-o, --remote <name>',
'The name of the remote',
ghpages.defaults.remote
)
.option(
'-u, --user <address>',
'The name and email of the user (defaults to the git config). Format is "Your Name <[email protected]>".'
Expand All @@ -55,7 +63,7 @@ function main(args) {
'-v, --remove <pattern>',
'Remove files that match the given pattern ' +
'(ignored if used together with --add).',
'.'
ghpages.defaults.only
)
.option('-n, --no-push', 'Commit only (with no push)')
.parse(args);
Expand All @@ -81,6 +89,7 @@ function main(args) {
message: program.message,
tag: program.tag,
git: program.git,
depth: program.depth,
dotfiles: !!program.dotfiles,
add: !!program.add,
only: program.remove,
Expand Down
32 changes: 16 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ function getRepo(options) {
}
}

exports.defaults = {
dest: '.',
add: false,
git: 'git',
depth: 1,
dotfiles: false,
branch: 'gh-pages',
remote: 'origin',
src: '**/*',
only: '.',
push: true,
message: 'Updates',
silent: false
};

/**
* Push a git branch to a remote (pushes gh-pages by default).
* @param {string} basePath The base path.
Expand All @@ -34,22 +49,7 @@ exports.publish = function publish(basePath, config, callback) {
config = {};
}

const defaults = {
dest: '.',
add: false,
git: 'git',
depth: 1,
dotfiles: false,
branch: 'gh-pages',
remote: 'origin',
src: '**/*',
only: '.',
push: true,
message: 'Updates',
silent: false
};

const options = Object.assign({}, defaults, config);
const options = Object.assign({}, exports.defaults, config);

if (!callback) {
callback = function(err) {
Expand Down
15 changes: 1 addition & 14 deletions test/bin/gh-pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,11 @@ describe('gh-pages', () => {
ghpages.publish.restore();
});

const defaults = {
repo: undefined,
silent: false,
branch: 'gh-pages',
src: '**/*',
dest: '.',
message: 'Updates',
dotfiles: false,
add: false,
remote: 'origin',
push: true
};

const scenarios = [
{
args: ['--dist', 'lib'],
dist: 'lib',
config: defaults
config: ghpages.defaults
},
{
args: ['--dist', 'lib', '-n'],
Expand Down