Skip to content

Commit

Permalink
Merge pull request #263 from AviVahl/upgrade-deps
Browse files Browse the repository at this point in the history
Infra: newer syntax and upgrade deps to latest stable versions
  • Loading branch information
tschaub committed Sep 12, 2018
2 parents 62f1496 + 32891c5 commit 32fdb32
Show file tree
Hide file tree
Showing 14 changed files with 974 additions and 723 deletions.
2 changes: 1 addition & 1 deletion bin/gh-pages-clean.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node

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

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

var ghpages = require('../lib/index');
var program = require('commander');
var path = require('path');
var pkg = require('../package.json');
const ghpages = require('../lib/index');
const program = require('commander');
const path = require('path');
const pkg = require('../package.json');

function main(args) {
program
Expand Down
24 changes: 12 additions & 12 deletions lib/git.js
@@ -1,15 +1,15 @@
var cp = require('child_process');
var fs = require('fs-extra');
var path = require('path');
var util = require('util');
const cp = require('child_process');
const fs = require('fs-extra');
const path = require('path');
const util = require('util');

/**
* @constructor
* @param {number} code Error code.
* @param {string} message Error message.
*/
function ProcessError(code, message) {
var callee = arguments.callee;
const callee = arguments.callee;
Error.apply(this, [message]);
Error.captureStackTrace(this, callee);
this.code = code;
Expand All @@ -27,18 +27,18 @@ util.inherits(ProcessError, Error);
*/
function spawn(exe, args, cwd) {
return new Promise(function(resolve, reject) {
var child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
var buffer = [];
const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
const buffer = [];
child.stderr.on('data', function(chunk) {
buffer.push(chunk.toString());
});
child.stdout.on('data', function(chunk) {
buffer.push(chunk.toString());
});
child.on('close', function(code) {
var output = buffer.join('');
const output = buffer.join('');
if (code) {
var msg = output || 'Process failed: ' + code;
const msg = output || 'Process failed: ' + code;
reject(new ProcessError(code, msg));
} else {
resolve(output);
Expand Down Expand Up @@ -116,7 +116,7 @@ Git.prototype.fetch = function(remote) {
* @return {Promise} A promise.
*/
Git.prototype.checkout = function(remote, branch) {
var treeish = remote + '/' + branch;
const treeish = remote + '/' + branch;
return this.exec('ls-remote', '--exit-code', '.', treeish).then(
function() {
// branch exists on remote, hard reset
Expand Down Expand Up @@ -202,7 +202,7 @@ Git.prototype.push = function(remote, branch) {
Git.prototype.getRemoteUrl = function(remote) {
return this.exec('config', '--get', 'remote.' + remote + '.url')
.then(function(git) {
var repo = git.output && git.output.split(/[\n\r]/).shift();
const repo = git.output && git.output.split(/[\n\r]/).shift();
if (repo) {
return repo;
} else {
Expand Down Expand Up @@ -238,7 +238,7 @@ Git.clone = function clone(repo, dir, branch, options) {
return Promise.resolve(new Git(dir, options.git));
} else {
return fs.mkdirp(path.dirname(path.resolve(dir))).then(function() {
var args = [
const args = [
'clone',
repo,
dir,
Expand Down
44 changes: 21 additions & 23 deletions lib/index.js
@@ -1,12 +1,12 @@
var Git = require('./git');
var filenamify = require('filenamify-url');
var copy = require('./util').copy;
var fs = require('fs-extra');
var globby = require('globby');
var path = require('path');
var util = require('util');
const Git = require('./git');
const filenamify = require('filenamify-url');
const copy = require('./util').copy;
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const util = require('util');

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

function getCacheDir() {
return path.relative(process.cwd(), path.resolve(__dirname, '../.cache'));
Expand All @@ -16,7 +16,7 @@ function getRepo(options) {
if (options.repo) {
return Promise.resolve(options.repo);
} else {
var git = new Git(process.cwd(), options.git);
const git = new Git(process.cwd(), options.git);
return git.getRemoteUrl(options.remote);
}
}
Expand All @@ -33,7 +33,7 @@ exports.publish = function publish(basePath, config, callback) {
config = {};
}

var defaults = {
const defaults = {
dest: '.',
add: false,
git: 'git',
Expand All @@ -48,7 +48,7 @@ exports.publish = function publish(basePath, config, callback) {
silent: false
};

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

if (!callback) {
callback = function(err) {
Expand Down Expand Up @@ -76,7 +76,7 @@ exports.publish = function publish(basePath, config, callback) {
return;
}

var files = globby
const files = globby
.sync(options.src, {
cwd: basePath,
dot: options.dotfiles
Expand All @@ -92,15 +92,15 @@ exports.publish = function publish(basePath, config, callback) {
return;
}

var only = globby.sync(options.only, {cwd: basePath}).map(function(file) {
const only = globby.sync(options.only, {cwd: basePath}).map(function(file) {
return path.join(options.dest, file);
});

var repoUrl;
let repoUrl;
return getRepo(options)
.then(function(repo) {
repoUrl = repo;
var clone = options.clone;
let clone = options.clone;
if (!clone) {
clone = path.join(getCacheDir(), filenamify(repo));
}
Expand All @@ -110,7 +110,7 @@ exports.publish = function publish(basePath, config, callback) {
.then(function(git) {
return git.getRemoteUrl(options.remote).then(function(url) {
if (url !== repoUrl) {
var message =
const message =
'Remote url mismatch. Got "' +
url +
'" ' +
Expand Down Expand Up @@ -147,13 +147,11 @@ exports.publish = function publish(basePath, config, callback) {
})
.then(function(git) {
log('Copying files');
return copy(
files,
basePath,
path.join(git.cwd, options.dest)
).then(function() {
return git;
});
return copy(files, basePath, path.join(git.cwd, options.dest)).then(
function() {
return git;
}
);
})
.then(function(git) {
log('Adding all');
Expand Down
52 changes: 26 additions & 26 deletions lib/util.js
@@ -1,20 +1,20 @@
var path = require('path');
const path = require('path');

var async = require('async');
var fs = require('graceful-fs');
const async = require('async');
const fs = require('graceful-fs');

/**
* 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.
*/
var uniqueDirs = (exports.uniqueDirs = function(files) {
var dirs = {};
const uniqueDirs = (exports.uniqueDirs = function(files) {
const dirs = {};
files.forEach(function(filepath) {
var parts = path.dirname(filepath).split(path.sep);
var partial = parts[0] || '/';
const parts = path.dirname(filepath).split(path.sep);
let partial = parts[0] || '/';
dirs[partial] = true;
for (var i = 1, ii = parts.length; i < ii; ++i) {
for (let i = 1, ii = parts.length; i < ii; ++i) {
partial = path.join(partial, parts[i]);
dirs[partial] = true;
}
Expand All @@ -29,19 +29,19 @@ var uniqueDirs = (exports.uniqueDirs = function(files) {
* @param {string} b Second path.
* @return {number} Comparison.
*/
var byShortPath = (exports.byShortPath = function(a, b) {
var aParts = a.split(path.sep);
var bParts = b.split(path.sep);
var aLength = aParts.length;
var bLength = bParts.length;
var cmp = 0;
const byShortPath = (exports.byShortPath = function(a, b) {
const aParts = a.split(path.sep);
const bParts = b.split(path.sep);
const aLength = aParts.length;
const bLength = bParts.length;
let cmp = 0;
if (aLength < bLength) {
cmp = -1;
} else if (aLength > bLength) {
cmp = 1;
} else {
var aPart, bPart;
for (var i = 0; i < aLength; ++i) {
let aPart, bPart;
for (let i = 0; i < aLength; ++i) {
aPart = aParts[i];
bPart = bParts[i];
if (aPart < bPart) {
Expand All @@ -61,7 +61,7 @@ var byShortPath = (exports.byShortPath = function(a, b) {
* @param {Array.<string>} files List of file paths.
* @return {Array.<string>} List of directory paths ordered by path length.
*/
var dirsToCreate = (exports.dirsToCreate = function(files) {
const dirsToCreate = (exports.dirsToCreate = function(files) {
return uniqueDirs(files).sort(byShortPath);
});

Expand All @@ -70,21 +70,21 @@ var dirsToCreate = (exports.dirsToCreate = function(files) {
* @param {Object} obj Object with src and dest properties.
* @param {function(Error)} callback Callback
*/
var copyFile = (exports.copyFile = function(obj, callback) {
var called = false;
const copyFile = (exports.copyFile = function(obj, callback) {
let called = false;
function done(err) {
if (!called) {
called = true;
callback(err);
}
}

var read = fs.createReadStream(obj.src);
const read = fs.createReadStream(obj.src);
read.on('error', function(err) {
done(err);
});

var write = fs.createWriteStream(obj.dest);
const write = fs.createWriteStream(obj.dest);
write.on('error', function(err) {
done(err);
});
Expand Down Expand Up @@ -126,12 +126,12 @@ function makeDir(path, callback) {
*/
exports.copy = function(files, base, dest) {
return new Promise(function(resolve, reject) {
var pairs = [];
var destFiles = [];
const pairs = [];
const destFiles = [];
files.forEach(function(file) {
var src = path.resolve(base, file);
var relative = path.relative(base, src);
var target = path.join(dest, relative);
const src = path.resolve(base, file);
const relative = path.relative(base, src);
const target = path.join(dest, relative);
pairs.push({
src: src,
dest: target
Expand Down

0 comments on commit 32fdb32

Please sign in to comment.