Skip to content

Commit

Permalink
Updated dev dependencies and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed May 10, 2022
1 parent 75809af commit 4430720
Show file tree
Hide file tree
Showing 17 changed files with 1,697 additions and 1,771 deletions.
2 changes: 1 addition & 1 deletion bin/gh-pages-clean.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node

const ghpages = require('../lib/index');
const ghpages = require('../lib/index.js');

function main() {
ghpages.clean();
Expand Down
13 changes: 7 additions & 6 deletions bin/gh-pages.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node

const ghpages = require('../lib/index');
const ghpages = require('../lib/index.js');
const program = require('commander');
const path = require('path');
const pkg = require('../package.json');
Expand All @@ -9,7 +9,7 @@ const addr = require('email-addresses');
function publish(config) {
return new Promise((resolve, reject) => {
const basePath = path.resolve(process.cwd(), program.dist);
ghpages.publish(basePath, config, err => {
ghpages.publish(basePath, config, (err) => {
if (err) {
return reject(err);
}
Expand Down Expand Up @@ -90,7 +90,7 @@ function main(args) {
let beforeAdd;
if (program.beforeAdd) {
const m = require(require.resolve(program.beforeAdd, {
paths: [process.cwd()]
paths: [process.cwd()],
}));

if (typeof m === 'function') {
Expand Down Expand Up @@ -122,7 +122,7 @@ function main(args) {
push: !!program.push,
history: !!program.history,
user: user,
beforeAdd: beforeAdd
beforeAdd: beforeAdd,
};

return publish(config);
Expand All @@ -134,9 +134,10 @@ if (require.main === module) {
.then(() => {
process.stdout.write('Published\n');
})
.catch(err => {
.catch((err) => {
process.stderr.write(`${err.message}\n`, () => process.exit(1));
});
}

exports = module.exports = main;
module.exports = main;
exports = module.exports;
66 changes: 34 additions & 32 deletions lib/git.js
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const util = require('util');

/**
* @constructor
* @function Object() { [native code] }
* @param {number} code Error code.
* @param {string} message Error message.
*/
Expand All @@ -21,21 +21,21 @@ util.inherits(ProcessError, Error);
/**
* Util function for handling spawned processes as promises.
* @param {string} exe Executable.
* @param {Array.<string>} args Arguments.
* @param {Array<string>} args Arguments.
* @param {string} cwd Working directory.
* @return {Promise} A promise.
*/
function spawn(exe, args, cwd) {
return new Promise((resolve, reject) => {
const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
const buffer = [];
child.stderr.on('data', chunk => {
child.stderr.on('data', (chunk) => {
buffer.push(chunk.toString());
});
child.stdout.on('data', chunk => {
child.stdout.on('data', (chunk) => {
buffer.push(chunk.toString());
});
child.on('close', code => {
child.on('close', (code) => {
const output = buffer.join('');
if (code) {
const msg = output || 'Process failed: ' + code;
Expand All @@ -50,8 +50,8 @@ function spawn(exe, args, cwd) {
/**
* Create an object for executing git commands.
* @param {string} cwd Repository directory.
* @param {string} exe Git executable (full path if not already on path).
* @constructor
* @param {string} cmd Git executable (full path if not already on path).
* @function Object() { [native code] }
*/
function Git(cwd, cmd) {
this.cwd = cwd;
Expand All @@ -61,12 +61,12 @@ function Git(cwd, cmd) {

/**
* Execute an arbitrary git command.
* @param {string} var_args Arguments (e.g. 'remote', 'update').
* @param {Array<string>} args Arguments (e.g. ['remote', 'update']).
* @return {Promise} A promise. The promise will be resolved with this instance
* or rejected with an error.
*/
Git.prototype.exec = function() {
return spawn(this.cmd, [...arguments], this.cwd).then(output => {
Git.prototype.exec = function (...args) {
return spawn(this.cmd, [...args], this.cwd).then((output) => {
this.output = output;
return this;
});
Expand All @@ -76,15 +76,15 @@ Git.prototype.exec = function() {
* Initialize repository.
* @return {Promise} A promise.
*/
Git.prototype.init = function() {
Git.prototype.init = function () {
return this.exec('init');
};

/**
* Clean up unversioned files.
* @return {Promise} A promise.
*/
Git.prototype.clean = function() {
Git.prototype.clean = function () {
return this.exec('clean', '-f', '-d');
};

Expand All @@ -94,7 +94,7 @@ Git.prototype.clean = function() {
* @param {string} branch Branch name.
* @return {Promise} A promise.
*/
Git.prototype.reset = function(remote, branch) {
Git.prototype.reset = function (remote, branch) {
return this.exec('reset', '--hard', remote + '/' + branch);
};

Expand All @@ -103,7 +103,7 @@ Git.prototype.reset = function(remote, branch) {
* @param {string} remote Remote alias.
* @return {Promise} A promise.
*/
Git.prototype.fetch = function(remote) {
Git.prototype.fetch = function (remote) {
return this.exec('fetch', remote);
};

Expand All @@ -113,7 +113,7 @@ Git.prototype.fetch = function(remote) {
* @param {string} branch Branch name.
* @return {Promise} A promise.
*/
Git.prototype.checkout = function(remote, branch) {
Git.prototype.checkout = function (remote, branch) {
const treeish = remote + '/' + branch;
return this.exec('ls-remote', '--exit-code', '.', treeish).then(
() => {
Expand All @@ -122,7 +122,7 @@ Git.prototype.checkout = function(remote, branch) {
.then(() => this.clean())
.then(() => this.reset(remote, branch));
},
error => {
(error) => {
if (error instanceof ProcessError && error.code === 2) {
// branch doesn't exist, create an orphan
return this.exec('checkout', '--orphan', branch);
Expand All @@ -136,10 +136,10 @@ Git.prototype.checkout = function(remote, branch) {

/**
* Remove all unversioned files.
* @param {string|string[]} files Files argument.
* @param {string | Array<string>} files Files argument.
* @return {Promise} A promise.
*/
Git.prototype.rm = function(files) {
Git.prototype.rm = function (files) {
if (!Array.isArray(files)) {
files = [files];
}
Expand All @@ -148,10 +148,10 @@ Git.prototype.rm = function(files) {

/**
* Add files.
* @param {string|string[]} files Files argument.
* @param {string | Array<string>} files Files argument.
* @return {Promise} A promise.
*/
Git.prototype.add = function(files) {
Git.prototype.add = function (files) {
if (!Array.isArray(files)) {
files = [files];
}
Expand All @@ -163,7 +163,7 @@ Git.prototype.add = function(files) {
* @param {string} message Commit message.
* @return {Promise} A promise.
*/
Git.prototype.commit = function(message) {
Git.prototype.commit = function (message) {
return this.exec('diff-index', '--quiet', 'HEAD').catch(() =>
this.exec('commit', '-m', message)
);
Expand All @@ -174,7 +174,7 @@ Git.prototype.commit = function(message) {
* @param {string} name Name of tag.
* @return {Promise} A promise.
*/
Git.prototype.tag = function(name) {
Git.prototype.tag = function (name) {
return this.exec('tag', name);
};

Expand All @@ -185,7 +185,7 @@ Git.prototype.tag = function(name) {
* @param {boolean} force Force push.
* @return {Promise} A promise.
*/
Git.prototype.push = function(remote, branch, force) {
Git.prototype.push = function (remote, branch, force) {
const args = ['push', '--tags', remote, branch];
if (force) {
args.push('--force');
Expand All @@ -198,9 +198,9 @@ Git.prototype.push = function(remote, branch, force) {
* @param {string} remote Remote alias.
* @return {Promise<string>} A promise for the remote URL.
*/
Git.prototype.getRemoteUrl = function(remote) {
Git.prototype.getRemoteUrl = function (remote) {
return this.exec('config', '--get', 'remote.' + remote + '.url')
.then(git => {
.then((git) => {
const repo = git.output && git.output.split(/[\n\r]/).shift();
if (repo) {
return repo;
Expand All @@ -210,7 +210,7 @@ Git.prototype.getRemoteUrl = function(remote) {
);
}
})
.catch(err => {
.catch((err) => {
throw new Error(
'Failed to get remote.' +
remote +
Expand All @@ -225,9 +225,11 @@ Git.prototype.getRemoteUrl = function(remote) {

/**
* Delete ref to remove branch history
* @param {string} branch
* @param {string} branch The branch name.
* @return {Promise} A promise. The promise will be resolved with this instance
* or rejected with an error.
*/
Git.prototype.deleteRef = function(branch) {
Git.prototype.deleteRef = function (branch) {
return this.exec('update-ref', '-d', 'refs/heads/' + branch);
};

Expand All @@ -240,7 +242,7 @@ Git.prototype.deleteRef = function(branch) {
* @return {Promise<Git>} A promise.
*/
Git.clone = function clone(repo, dir, branch, options) {
return fs.exists(dir).then(exists => {
return fs.exists(dir).then((exists) => {
if (exists) {
return Promise.resolve(new Git(dir, options.git));
} else {
Expand All @@ -255,17 +257,17 @@ Git.clone = function clone(repo, dir, branch, options) {
'--origin',
options.remote,
'--depth',
options.depth
options.depth,
];
return spawn(options.git, args)
.catch(err => {
.catch((err) => {
// try again without branch or depth options
return spawn(options.git, [
'clone',
repo,
dir,
'--origin',
options.remote
options.remote,
]);
})
.then(() => new Git(dir, options.git));
Expand Down

0 comments on commit 4430720

Please sign in to comment.