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

Remove the logger option and use util.debuglog() #174

Merged
merged 2 commits into from
May 8, 2017
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
5 changes: 1 addition & 4 deletions bin/gh-pages
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ function main(args) {
add: !!program.add,
only: program.remove,
remote: program.remote,
push: !!program.push,
logger: function(message) {
process.stderr.write(message + '\n');
}
push: !!program.push
},
function(err) {
if (err) {
Expand Down
26 changes: 11 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
var Git = require('./git');
var base64url = require('base64url');
var copy = require('./util').copy;
var fs = require('fs-extra');
var Git = require('./git');
var globby = require('globby');
var path = require('path');
var base64url = require('base64url');
var util = require('util');

var log = util.debuglog('gh-pages');

function getCacheDir() {
return path.relative(process.cwd(), path.resolve(__dirname, '../.cache'));
Expand Down Expand Up @@ -42,18 +45,11 @@ exports.publish = function publish(basePath, config, callback) {
only: '.',
push: true,
message: 'Updates',
silent: false,
logger: function() {}
silent: false
};

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

function log(message) {
if (!options.silent) {
options.logger(message);
}
}

if (!callback) {
callback = function(err) {
if (err) {
Expand All @@ -66,7 +62,7 @@ exports.publish = function publish(basePath, config, callback) {
try {
callback(err);
} catch (err2) {
log('Publish callback threw: ', err2.message);
log('Publish callback threw: %s', err2.message);
}
}

Expand Down Expand Up @@ -108,7 +104,7 @@ exports.publish = function publish(basePath, config, callback) {
if (!clone) {
clone = path.join(getCacheDir(), base64url(repo));
}
log('Cloning ' + repo + ' into ' + clone);
log('Cloning %s into %s', repo, clone);
return Git.clone(repo, clone, options.branch, options);
})
.then(function(git) {
Expand All @@ -134,11 +130,11 @@ exports.publish = function publish(basePath, config, callback) {
return git.clean();
})
.then(function(git) {
log('Fetching ' + options.remote);
log('Fetching %s', options.remote);
return git.fetch(options.remote);
})
.then(function(git) {
log('Checking out ' + options.remote + '/' + options.branch);
log('Checking out %s/%s ', options.remote, options.branch);
return git.checkout(options.remote, options.branch);
})
.then(function(git) {
Expand Down Expand Up @@ -183,8 +179,8 @@ exports.publish = function publish(basePath, config, callback) {
log('Tagging');
return git.tag(options.tag).catch(function(error) {
// tagging failed probably because this tag alredy exists
log(error);
log('Tagging failed, continuing');
options.logger(error);
return git;
});
} else {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"url": "https://github.com/tschaub/gh-pages/issues"
},
"main": "lib/index.js",
"config": {
"js": "lib test bin plugin.js"
},
"scripts": {
"fix-lint": "eslint --fix lib test bin",
"pretest": "eslint lib test bin",
"fix-lint": "eslint --fix $npm_package_config_js",
"pretest": "eslint $npm_package_config_js",
"test": "mocha --recursive test"
},
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var ghPages = require('./lib/index')
var path = require('path')
var ghPages = require('./lib/index');
var path = require('path');

module.exports = function (pluginConfig, config, callback) {
ghPages.publish(path.join(process.cwd(), config.basePath), config, callback)
}
module.exports = function(pluginConfig, config, callback) {
ghPages.publish(path.join(process.cwd(), config.basePath), config, callback);
};
28 changes: 8 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,26 +264,6 @@ ghpages.publish(path.join(__dirname, 'build'), {
```


#### <a id="optionslogger">options.logger</a>
* type: `function(string)`
* default: `function(){}`

Logger function. The default logging function is a no-op, allowing you to provide a custom logging implementation.

Example use of the `logger` option:

```js
/**
* This configuration will log to the console
*/
ghpages.publish(path.join(__dirname, 'build'), {
logger: function(message) {
console.log(message);
}
}, callback);
```


#### <a id="optionsgit">options.git</a>
* type: `string`
* default: `'git'`
Expand Down Expand Up @@ -337,6 +317,14 @@ And then to publish everything from your `dist` folder to your `gh-pages` branch
npm run deploy
```

## Debugging

To get additional output from the `gh-pages` script, set `NODE_DEBUG=gh-pages`. For example:

```shell
NODE_DEBUG=gh-pages npm run deploy
```

## Dependencies

Note that this plugin requires Git 1.9 or higher (because it uses the `--exit-code` option for `git ls-remote`). If you'd like to see this working with earlier versions of Git, please [open an issue](https://github.com/tschaub/gh-pages/issues).
Expand Down