Comparing version 3.2.3 to 4.0.0
#!/usr/bin/env node | ||
const ghpages = require('../lib/index'); | ||
const ghpages = require('../lib/index.js'); | ||
@@ -5,0 +5,0 @@ function main() { |
#!/usr/bin/env node | ||
const ghpages = require('../lib/index'); | ||
const ghpages = require('../lib/index.js'); | ||
const program = require('commander'); | ||
@@ -12,3 +12,3 @@ const path = require('path'); | ||
const basePath = path.resolve(process.cwd(), program.dist); | ||
ghpages.publish(basePath, config, err => { | ||
ghpages.publish(basePath, config, (err) => { | ||
if (err) { | ||
@@ -94,3 +94,3 @@ return reject(err); | ||
const m = require(require.resolve(program.beforeAdd, { | ||
paths: [process.cwd()] | ||
paths: [process.cwd()], | ||
})); | ||
@@ -127,3 +127,3 @@ | ||
user: user, | ||
beforeAdd: beforeAdd | ||
beforeAdd: beforeAdd, | ||
}; | ||
@@ -140,3 +140,3 @@ | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
process.stderr.write(`${err.message}\n`, () => process.exit(1)); | ||
@@ -146,2 +146,3 @@ }); | ||
exports = module.exports = main; | ||
module.exports = main; | ||
exports = module.exports; |
@@ -7,3 +7,3 @@ const cp = require('child_process'); | ||
/** | ||
* @constructor | ||
* @function Object() { [native code] } | ||
* @param {number} code Error code. | ||
@@ -25,3 +25,3 @@ * @param {string} message Error message. | ||
* @param {string} exe Executable. | ||
* @param {Array.<string>} args Arguments. | ||
* @param {Array<string>} args Arguments. | ||
* @param {string} cwd Working directory. | ||
@@ -34,9 +34,9 @@ * @return {Promise} A promise. | ||
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(''); | ||
@@ -56,4 +56,4 @@ if (code) { | ||
* @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] } | ||
*/ | ||
@@ -68,8 +68,8 @@ 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; | ||
@@ -84,3 +84,3 @@ return this; | ||
*/ | ||
Git.prototype.init = function() { | ||
Git.prototype.init = function () { | ||
return this.exec('init'); | ||
@@ -93,3 +93,3 @@ }; | ||
*/ | ||
Git.prototype.clean = function() { | ||
Git.prototype.clean = function () { | ||
return this.exec('clean', '-f', '-d'); | ||
@@ -104,3 +104,3 @@ }; | ||
*/ | ||
Git.prototype.reset = function(remote, branch) { | ||
Git.prototype.reset = function (remote, branch) { | ||
return this.exec('reset', '--hard', remote + '/' + branch); | ||
@@ -114,3 +114,3 @@ }; | ||
*/ | ||
Git.prototype.fetch = function(remote) { | ||
Git.prototype.fetch = function (remote) { | ||
return this.exec('fetch', remote); | ||
@@ -125,3 +125,3 @@ }; | ||
*/ | ||
Git.prototype.checkout = function(remote, branch) { | ||
Git.prototype.checkout = function (remote, branch) { | ||
const treeish = remote + '/' + branch; | ||
@@ -135,3 +135,3 @@ return this.exec('ls-remote', '--exit-code', '.', treeish).then( | ||
}, | ||
error => { | ||
(error) => { | ||
if (error instanceof ProcessError && error.code === 2) { | ||
@@ -150,6 +150,6 @@ // branch doesn't exist, create an orphan | ||
* 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)) { | ||
@@ -163,6 +163,6 @@ files = [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)) { | ||
@@ -179,3 +179,3 @@ files = [files]; | ||
*/ | ||
Git.prototype.commit = function(message) { | ||
Git.prototype.commit = function (message) { | ||
return this.exec('diff-index', '--quiet', 'HEAD').catch(() => | ||
@@ -191,3 +191,3 @@ this.exec('commit', '-m', message) | ||
*/ | ||
Git.prototype.tag = function(name) { | ||
Git.prototype.tag = function (name) { | ||
return this.exec('tag', name); | ||
@@ -203,3 +203,3 @@ }; | ||
*/ | ||
Git.prototype.push = function(remote, branch, force) { | ||
Git.prototype.push = function (remote, branch, force) { | ||
const args = ['push', '--tags', remote, branch]; | ||
@@ -217,5 +217,5 @@ if (force) { | ||
*/ | ||
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(); | ||
@@ -230,3 +230,3 @@ if (repo) { | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
throw new Error( | ||
@@ -246,5 +246,7 @@ 'Failed to get 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); | ||
@@ -262,3 +264,3 @@ }; | ||
Git.clone = function clone(repo, dir, branch, options) { | ||
return fs.exists(dir).then(exists => { | ||
return fs.exists(dir).then((exists) => { | ||
if (exists) { | ||
@@ -278,6 +280,6 @@ return Promise.resolve(new Git(dir, options.git)); | ||
'--depth', | ||
options.depth | ||
options.depth, | ||
]; | ||
return spawn(options.git, args) | ||
.catch(err => { | ||
.catch((err) => { | ||
// try again without branch or depth options | ||
@@ -289,3 +291,3 @@ return spawn(options.git, [ | ||
'--origin', | ||
options.remote | ||
options.remote, | ||
]); | ||
@@ -292,0 +294,0 @@ }) |
const findCacheDir = require('find-cache-dir'); | ||
const Git = require('./git'); | ||
const Git = require('./git.js'); | ||
const filenamify = require('filenamify'); | ||
const copy = require('./util').copy; | ||
const getUser = require('./util').getUser; | ||
const copy = require('./util.js').copy; | ||
const getUser = require('./util.js').getUser; | ||
const fs = require('fs-extra'); | ||
@@ -16,3 +16,3 @@ const globby = require('globby'); | ||
* @param {string} [optPath] Optional path. | ||
* @returns {string} The full path to the cache directory. | ||
* @return {string} The full path to the cache directory. | ||
*/ | ||
@@ -51,3 +51,3 @@ function getCacheDir(optPath) { | ||
message: 'Updates', | ||
silent: false | ||
silent: false, | ||
}; | ||
@@ -60,2 +60,3 @@ | ||
* @param {Function} callback Callback. | ||
* @return {Promise} A promise. | ||
*/ | ||
@@ -76,3 +77,3 @@ exports.publish = function publish(basePath, config, callback) { | ||
if (!callback) { | ||
callback = function(err) { | ||
callback = function (err) { | ||
if (err) { | ||
@@ -105,5 +106,5 @@ log(err.message); | ||
cwd: basePath, | ||
dot: options.dotfiles | ||
dot: options.dotfiles, | ||
}) | ||
.filter(file => { | ||
.filter((file) => { | ||
return !fs.statSync(path.join(basePath, file)).isDirectory(); | ||
@@ -126,5 +127,5 @@ }); | ||
} | ||
return userPromise.then(user => | ||
return userPromise.then((user) => | ||
getRepo(options) | ||
.then(repo => { | ||
.then((repo) => { | ||
repoUrl = repo; | ||
@@ -135,4 +136,4 @@ const clone = getCacheDir(repo); | ||
}) | ||
.then(git => { | ||
return git.getRemoteUrl(options.remote).then(url => { | ||
.then((git) => { | ||
return git.getRemoteUrl(options.remote).then((url) => { | ||
if (url !== repoUrl) { | ||
@@ -153,3 +154,3 @@ const message = | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
// only required if someone mucks with the checkout between builds | ||
@@ -159,11 +160,11 @@ log('Cleaning'); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
log('Fetching %s', options.remote); | ||
return git.fetch(options.remote); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
log('Checking out %s/%s ', options.remote, options.branch); | ||
return git.checkout(options.remote, options.branch); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
if (!options.history) { | ||
@@ -175,3 +176,3 @@ return git.deleteRef(options.branch); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
if (options.add) { | ||
@@ -184,5 +185,5 @@ return git; | ||
.sync(options.remove, { | ||
cwd: path.join(git.cwd, options.dest) | ||
cwd: path.join(git.cwd, options.dest), | ||
}) | ||
.map(file => path.join(options.dest, file)); | ||
.map((file) => path.join(options.dest, file)); | ||
if (files.length > 0) { | ||
@@ -194,6 +195,6 @@ return git.rm(files); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
log('Copying files'); | ||
return copy(files, basePath, path.join(git.cwd, options.dest)).then( | ||
function() { | ||
function () { | ||
return git; | ||
@@ -203,3 +204,3 @@ } | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
return Promise.resolve( | ||
@@ -209,7 +210,7 @@ options.beforeAdd && options.beforeAdd(git) | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
log('Adding all'); | ||
return git.add('.'); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
if (!user) { | ||
@@ -225,10 +226,10 @@ return git; | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
log('Committing'); | ||
return git.commit(options.message); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
if (options.tag) { | ||
log('Tagging'); | ||
return git.tag(options.tag).catch(error => { | ||
return git.tag(options.tag).catch((error) => { | ||
// tagging failed probably because this tag alredy exists | ||
@@ -243,3 +244,3 @@ log(error); | ||
}) | ||
.then(git => { | ||
.then((git) => { | ||
if (options.push) { | ||
@@ -254,3 +255,3 @@ log('Pushing'); | ||
() => done(), | ||
error => { | ||
(error) => { | ||
if (options.silent) { | ||
@@ -257,0 +258,0 @@ error = new Error( |
const path = require('path'); | ||
const Git = require('./git'); | ||
const Git = require('./git.js'); | ||
const async = require('async'); | ||
@@ -8,8 +8,8 @@ const fs = require('fs-extra'); | ||
* Generate a list of unique directory paths given a list of file paths. | ||
* @param {Array.<string>} files List of file paths. | ||
* @return {Array.<string>} List of directory paths. | ||
* @param {Array<string>} files List of file paths. | ||
* @return {Array<string>} List of directory paths. | ||
*/ | ||
const uniqueDirs = (exports.uniqueDirs = function(files) { | ||
function uniqueDirs(files) { | ||
const dirs = {}; | ||
files.forEach(filepath => { | ||
files.forEach((filepath) => { | ||
const parts = path.dirname(filepath).split(path.sep); | ||
@@ -24,3 +24,4 @@ let partial = parts[0] || '/'; | ||
return Object.keys(dirs); | ||
}); | ||
} | ||
exports.uniqueDirs = uniqueDirs; | ||
@@ -34,3 +35,3 @@ /** | ||
*/ | ||
const byShortPath = (exports.byShortPath = (a, b) => { | ||
function byShortPath(a, b) { | ||
const aParts = a.split(path.sep); | ||
@@ -60,12 +61,14 @@ const bParts = b.split(path.sep); | ||
return cmp; | ||
}); | ||
} | ||
exports.byShortPath = byShortPath; | ||
/** | ||
* Generate a list of directories to create given a list of file paths. | ||
* @param {Array.<string>} files List of file paths. | ||
* @return {Array.<string>} List of directory paths ordered by path length. | ||
* @param {Array<string>} files List of file paths. | ||
* @return {Array<string>} List of directory paths ordered by path length. | ||
*/ | ||
const dirsToCreate = (exports.dirsToCreate = function(files) { | ||
function dirsToCreate(files) { | ||
return uniqueDirs(files).sort(byShortPath); | ||
}); | ||
} | ||
exports.dirsToCreate = dirsToCreate; | ||
@@ -77,3 +80,3 @@ /** | ||
*/ | ||
const copyFile = (exports.copyFile = function(obj, callback) { | ||
function copyFile(obj, callback) { | ||
let called = false; | ||
@@ -88,3 +91,3 @@ function done(err) { | ||
const read = fs.createReadStream(obj.src); | ||
read.on('error', err => { | ||
read.on('error', (err) => { | ||
done(err); | ||
@@ -94,3 +97,3 @@ }); | ||
const write = fs.createWriteStream(obj.dest); | ||
write.on('error', err => { | ||
write.on('error', (err) => { | ||
done(err); | ||
@@ -103,3 +106,4 @@ }); | ||
read.pipe(write); | ||
}); | ||
} | ||
exports.copyFile = copyFile; | ||
@@ -112,3 +116,3 @@ /** | ||
function makeDir(path, callback) { | ||
fs.mkdir(path, err => { | ||
fs.mkdir(path, (err) => { | ||
if (err) { | ||
@@ -131,3 +135,3 @@ // check if directory exists | ||
* Copy a list of files. | ||
* @param {Array.<string>} files Files to copy. | ||
* @param {Array<string>} files Files to copy. | ||
* @param {string} base Base directory. | ||
@@ -137,7 +141,7 @@ * @param {string} dest Destination directory. | ||
*/ | ||
exports.copy = function(files, base, dest) { | ||
exports.copy = function (files, base, dest) { | ||
return new Promise((resolve, reject) => { | ||
const pairs = []; | ||
const destFiles = []; | ||
files.forEach(file => { | ||
files.forEach((file) => { | ||
const src = path.resolve(base, file); | ||
@@ -148,3 +152,3 @@ const relative = path.relative(base, src); | ||
src: src, | ||
dest: target | ||
dest: target, | ||
}); | ||
@@ -154,7 +158,7 @@ destFiles.push(target); | ||
async.eachSeries(dirsToCreate(destFiles), makeDir, err => { | ||
async.eachSeries(dirsToCreate(destFiles), makeDir, (err) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
async.each(pairs, copyFile, err => { | ||
async.each(pairs, copyFile, (err) => { | ||
if (err) { | ||
@@ -170,11 +174,11 @@ return reject(err); | ||
exports.getUser = function(cwd) { | ||
exports.getUser = function (cwd) { | ||
return Promise.all([ | ||
new Git(cwd).exec('config', 'user.name'), | ||
new Git(cwd).exec('config', 'user.email') | ||
new Git(cwd).exec('config', 'user.email'), | ||
]) | ||
.then(results => { | ||
.then((results) => { | ||
return {name: results[0].output.trim(), email: results[1].output.trim()}; | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
// git config exits with 1 if name or email is not set | ||
@@ -181,0 +185,0 @@ return null; |
{ | ||
"name": "gh-pages", | ||
"version": "3.2.3", | ||
"version": "4.0.0", | ||
"description": "Publish to a gh-pages branch on GitHub (or any other branch on any other remote)", | ||
@@ -46,8 +46,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"chai": "^4.3.4", | ||
"chai": "^4.3.6", | ||
"dir-compare": "^1.8.0", | ||
"eslint": "^7.27.0", | ||
"eslint-config-tschaub": "^13.1.0", | ||
"mocha": "^8.4.0", | ||
"sinon": "^10.0.0", | ||
"eslint": "^8.15.0", | ||
"eslint-config-tschaub": "^14.0.0", | ||
"mocha": "^10.0.0", | ||
"sinon": "^14.0.0", | ||
"tmp": "^0.2.1" | ||
@@ -60,4 +60,7 @@ }, | ||
"eslintConfig": { | ||
"extends": "tschaub" | ||
"extends": "tschaub", | ||
"rules": { | ||
"jsdoc/check-examples": "off" | ||
} | ||
} | ||
} |
@@ -12,3 +12,3 @@ | ||
This module requires Git `>=1.9`. | ||
This module requires Git >= 1.9 and Node >= 12. | ||
@@ -15,0 +15,0 @@ ## Basic Usage |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
806
36855
8