Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gh-pages

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gh-pages - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

.cache/file!Users!tschaub!test-gh-pages-remote/works.txt

2

bin/gh-pages-clean.js
#!/usr/bin/env node
var ghpages = require('../lib/index');
const ghpages = require('../lib/index');

@@ -5,0 +5,0 @@ function main() {

#!/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');
const addr = require('email-addresses');
function publish(config) {
return new Promise((resolve, reject) => {
const basePath = path.join(process.cwd(), program.dist);
ghpages.publish(basePath, config, err => {
if (err) {
return reject(err);
}
resolve();
});
});
}
function main(args) {
program
.version(pkg.version)
.option('-d, --dist <dist>', 'Base directory for all source files')
.option(
'-s, --src <src>',
'Pattern used to select which files to publish',
'**/*'
)
.option(
'-b, --branch <branch>',
'Name of the branch you are pushing to',
'gh-pages'
)
.option(
'-e, --dest <dest>',
'Target directory within the destination branch (relative to the root)',
'.'
)
.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('-g, --tag <tag>', 'add tag to commit')
.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(
'-v, --remove <pattern>',
'Remove files that match the given pattern ' +
'(ignored if used together with --add).',
'.'
)
.option('-n, --no-push', 'Commit only (with no push)')
.parse(args);
return Promise.resolve().then(() => {
program
.version(pkg.version)
.option('-d, --dist <dist>', 'Base directory for all source files')
.option(
'-s, --src <src>',
'Pattern used to select which files to publish',
'**/*'
)
.option(
'-b, --branch <branch>',
'Name of the branch you are pushing to',
'gh-pages'
)
.option(
'-e, --dest <dest>',
'Target directory within the destination branch (relative to the root)',
'.'
)
.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('-g, --tag <tag>', 'add tag to commit')
.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(
'-u, --user <address>',
'The name and email of the user (defaults to the git config). Format is "Your Name <email@example.com>".'
)
.option(
'-v, --remove <pattern>',
'Remove files that match the given pattern ' +
'(ignored if used together with --add).',
'.'
)
.option('-n, --no-push', 'Commit only (with no push)')
.parse(args);
ghpages.publish(
path.join(process.cwd(), program.dist),
{
let user;
if (program.user) {
const parts = addr.parseOneAddress(program.user);
if (!parts) {
throw new Error(
`Could not parse name and email from user option "${program.user}" ` +
'(format should be "Your Name <email@example.com>")'
);
}
user = {name: parts.name, email: parts.address};
}
const config = {
repo: program.repo,

@@ -58,18 +86,20 @@ silent: !!program.silent,

remote: program.remote,
push: !!program.push
},
function(err) {
if (err) {
process.stderr.write(err.message + '\n');
return process.exit(1);
}
process.stderr.write('Published\n');
}
);
push: !!program.push,
user: user
};
return publish(config);
});
}
if (require.main === module) {
main(process.argv);
main(process.argv)
.then(() => {
process.stdout.write('Published\n');
})
.catch(err => {
process.stderr.write(`${err.message}\n`, () => process.exit(1));
});
}
module.exports = main;
exports = module.exports = main;

@@ -0,1 +1,12 @@

## v2.0.0
Breaking changes:
* Requires Node 6 and above. If you require support for Node 4, stick with v1.2.0.
* The git user for commits is determined by running `git config user.name` and `git config user.email` in the current working directory when `gh-pages` is run. Ideally, this is what you want. In v1, the git user was determined based on the `gh-pages` install directory. If the package was installed globally, the git user might not have been what you expected when running in a directory with a locally configured git user.
* [#264](https://github.com/tschaub/gh-pages/pull/264) - Better user handling (thanks @holloway for getting this going and @nuklearfiziks and @paulirish for pushing it over the edge)
* [#263](https://github.com/tschaub/gh-pages/pull/263) - Infra: newer syntax and upgrade deps to latest stable versions ([@AviVahl](https://github.com/AviVahl))
## v1.2.0

@@ -2,0 +13,0 @@

@@ -1,5 +0,5 @@

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');

@@ -12,3 +12,3 @@ /**

function ProcessError(code, message) {
var callee = arguments.callee;
const callee = arguments.callee;
Error.apply(this, [message]);

@@ -30,15 +30,15 @@ Error.captureStackTrace(this, callee);

function spawn(exe, args, cwd) {
return new Promise(function(resolve, reject) {
var child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
var buffer = [];
child.stderr.on('data', function(chunk) {
return new Promise((resolve, reject) => {
const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()});
const buffer = [];
child.stderr.on('data', chunk => {
buffer.push(chunk.toString());
});
child.stdout.on('data', function(chunk) {
child.stdout.on('data', chunk => {
buffer.push(chunk.toString());
});
child.on('close', function(code) {
var output = buffer.join('');
child.on('close', code => {
const output = buffer.join('');
if (code) {
var msg = output || 'Process failed: ' + code;
const msg = output || 'Process failed: ' + code;
reject(new ProcessError(code, msg));

@@ -71,8 +71,6 @@ } else {

Git.prototype.exec = function() {
return spawn(this.cmd, [].slice.call(arguments), this.cwd).then(
function(output) {
this.output = output;
return this;
}.bind(this)
);
return spawn(this.cmd, [].slice.call(arguments), this.cwd).then(output => {
this.output = output;
return this;
});
};

@@ -82,3 +80,3 @@

* Initialize repository.
* @return {ChildProcess} Child process.
* @return {Promise} A promise.
*/

@@ -123,19 +121,11 @@ Git.prototype.init = function() {

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
return this.exec('checkout', branch)
.then(
function() {
return this.clean();
}.bind(this)
)
.then(
function() {
return this.reset(remote, branch);
}.bind(this)
);
}.bind(this),
function(error) {
.then(() => this.clean())
.then(() => this.reset(remote, branch));
},
error => {
if (error instanceof ProcessError && error.code === 2) {

@@ -148,3 +138,3 @@ // branch doesn't exist, create an orphan

}
}.bind(this)
}
);

@@ -177,6 +167,4 @@ };

Git.prototype.commit = function(message) {
return this.exec('diff-index', '--quiet', 'HEAD').catch(
function() {
return this.exec('commit', '-m', message);
}.bind(this)
return this.exec('diff-index', '--quiet', 'HEAD').catch(() =>
this.exec('commit', '-m', message)
);

@@ -211,4 +199,4 @@ };

return this.exec('config', '--get', 'remote.' + remote + '.url')
.then(function(git) {
var repo = git.output && git.output.split(/[\n\r]/).shift();
.then(git => {
const repo = git.output && git.output.split(/[\n\r]/).shift();
if (repo) {

@@ -222,3 +210,3 @@ return repo;

})
.catch(function(err) {
.catch(err => {
throw new Error(

@@ -245,8 +233,8 @@ 'Failed to get remote.' +

Git.clone = function clone(repo, dir, branch, options) {
return fs.exists(dir).then(function(exists) {
return fs.exists(dir).then(exists => {
if (exists) {
return Promise.resolve(new Git(dir, options.git));
} else {
return fs.mkdirp(path.dirname(path.resolve(dir))).then(function() {
var args = [
return fs.mkdirp(path.dirname(path.resolve(dir))).then(() => {
const args = [
'clone',

@@ -264,3 +252,3 @@ repo,

return spawn(options.git, args)
.catch(function(err) {
.catch(err => {
// try again without banch or depth options

@@ -275,5 +263,3 @@ return spawn(options.git, [

})
.then(function() {
return new Git(dir, options.git);
});
.then(() => new Git(dir, options.git));
});

@@ -280,0 +266,0 @@ }

@@ -1,10 +0,11 @@

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 getUser = require('./util').getUser;
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');

@@ -19,3 +20,3 @@ function getCacheDir() {

} else {
var git = new Git(process.cwd(), options.git);
const git = new Git(process.cwd(), options.git);
return git.getRemoteUrl(options.remote);

@@ -37,3 +38,3 @@ }

var defaults = {
const defaults = {
dest: '.',

@@ -53,3 +54,3 @@ add: false,

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

@@ -82,3 +83,3 @@ if (!callback) {

var files = globby
const files = globby
.sync(options.src, {

@@ -88,3 +89,3 @@ cwd: basePath,

})
.filter(function(file) {
.filter(file => {
return !fs.statSync(path.join(basePath, file)).isDirectory();

@@ -100,118 +101,116 @@ });

var only = globby.sync(options.only, {cwd: basePath}).map(function(file) {
const only = globby.sync(options.only, {cwd: basePath}).map(file => {
return path.join(options.dest, file);
});
var repoUrl;
return getRepo(options)
.then(function(repo) {
repoUrl = repo;
var clone = options.clone;
if (!clone) {
clone = path.join(getCacheDir(), filenamify(repo));
}
log('Cloning %s into %s', repo, clone);
return Git.clone(repo, clone, options.branch, options);
})
.then(function(git) {
return git.getRemoteUrl(options.remote).then(function(url) {
if (url !== repoUrl) {
var message =
'Remote url mismatch. Got "' +
url +
'" ' +
'but expected "' +
repoUrl +
'" in ' +
git.cwd +
'. Try running the `gh-pages-clean` script first.';
throw new Error(message);
let repoUrl;
let userPromise;
if (options.user) {
userPromise = Promise.resolve(options.user);
} else {
userPromise = getUser();
}
return userPromise.then(user =>
getRepo(options)
.then(repo => {
repoUrl = repo;
const clone = path.join(getCacheDir(), filenamify(repo));
log('Cloning %s into %s', repo, clone);
return Git.clone(repo, clone, options.branch, options);
})
.then(git => {
return git.getRemoteUrl(options.remote).then(url => {
if (url !== repoUrl) {
const message =
'Remote url mismatch. Got "' +
url +
'" ' +
'but expected "' +
repoUrl +
'" in ' +
git.cwd +
'. Try running the `gh-pages-clean` script first.';
throw new Error(message);
}
return git;
});
})
.then(git => {
// only required if someone mucks with the checkout between builds
log('Cleaning');
return git.clean();
})
.then(git => {
log('Fetching %s', options.remote);
return git.fetch(options.remote);
})
.then(git => {
log('Checking out %s/%s ', options.remote, options.branch);
return git.checkout(options.remote, options.branch);
})
.then(git => {
if (!options.add) {
log('Removing files');
return git.rm(only.join(' '));
} else {
return git;
}
return git;
});
})
.then(function(git) {
// only required if someone mucks with the checkout between builds
log('Cleaning');
return git.clean();
})
.then(function(git) {
log('Fetching %s', options.remote);
return git.fetch(options.remote);
})
.then(function(git) {
log('Checking out %s/%s ', options.remote, options.branch);
return git.checkout(options.remote, options.branch);
})
.then(function(git) {
if (!options.add) {
log('Removing files');
return git.rm(only.join(' '));
} else {
return git;
}
})
.then(function(git) {
log('Copying files');
return copy(
files,
basePath,
path.join(git.cwd, options.dest)
).then(function() {
return git;
});
})
.then(function(git) {
log('Adding all');
return git.add('.');
})
.then(function(git) {
if (options.user) {
return git
.exec('config', 'user.email', options.user.email)
.then(function() {
return git.exec('config', 'user.name', options.user.name);
})
.then(git => {
log('Copying files');
return copy(files, basePath, path.join(git.cwd, options.dest)).then(
function() {
return git;
}
);
})
.then(git => {
log('Adding all');
return git.add('.');
})
.then(git => {
return git.exec('config', 'user.email', user.email).then(() => {
if (!user.name) {
return git;
}
return git.exec('config', 'user.name', user.name);
});
})
.then(git => {
log('Committing');
return git.commit(options.message);
})
.then(git => {
if (options.tag) {
log('Tagging');
return git.tag(options.tag).catch(error => {
// tagging failed probably because this tag alredy exists
log(error);
log('Tagging failed, continuing');
return git;
});
} else {
return git;
}
})
.then(function(git) {
log('Committing');
return git.commit(options.message);
})
.then(function(git) {
if (options.tag) {
log('Tagging');
return git.tag(options.tag).catch(function(error) {
// tagging failed probably because this tag alredy exists
log(error);
log('Tagging failed, continuing');
} else {
return git;
});
} else {
return git;
}
})
.then(function(git) {
if (options.push) {
log('Pushing');
return git.push(options.remote, options.branch);
} else {
return git;
}
})
.then(
function() {
done();
},
function(error) {
if (options.silent) {
error = new Error(
'Unspecified error (run without silent option for detail)'
);
}
done(error);
}
);
})
.then(git => {
if (options.push) {
log('Pushing');
return git.push(options.remote, options.branch);
} else {
return git;
}
})
.then(
() => done(),
error => {
if (options.silent) {
error = new Error(
'Unspecified error (run without silent option for detail)'
);
}
done(error);
}
)
);
};

@@ -218,0 +217,0 @@

@@ -1,6 +0,6 @@

var path = require('path');
const path = require('path');
const Git = require('./git');
const async = require('async');
const fs = require('graceful-fs');
var async = require('async');
var fs = require('graceful-fs');
/**

@@ -11,9 +11,9 @@ * Generate a list of unique directory paths given a list of file paths.

*/
var uniqueDirs = (exports.uniqueDirs = function(files) {
var dirs = {};
files.forEach(function(filepath) {
var parts = path.dirname(filepath).split(path.sep);
var partial = parts[0] || '/';
const uniqueDirs = (exports.uniqueDirs = function(files) {
const dirs = {};
files.forEach(filepath => {
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]);

@@ -33,8 +33,8 @@ dirs[partial] = true;

*/
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 = (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) {

@@ -45,4 +45,4 @@ 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];

@@ -67,3 +67,3 @@ bPart = bParts[i];

*/
var dirsToCreate = (exports.dirsToCreate = function(files) {
const dirsToCreate = (exports.dirsToCreate = function(files) {
return uniqueDirs(files).sort(byShortPath);

@@ -77,4 +77,4 @@ });

*/
var copyFile = (exports.copyFile = function(obj, callback) {
var called = false;
const copyFile = (exports.copyFile = function(obj, callback) {
let called = false;
function done(err) {

@@ -87,12 +87,12 @@ if (!called) {

var read = fs.createReadStream(obj.src);
read.on('error', function(err) {
const read = fs.createReadStream(obj.src);
read.on('error', err => {
done(err);
});
var write = fs.createWriteStream(obj.dest);
write.on('error', function(err) {
const write = fs.createWriteStream(obj.dest);
write.on('error', err => {
done(err);
});
write.on('close', function(ex) {
write.on('close', () => {
done();

@@ -110,6 +110,6 @@ });

function makeDir(path, callback) {
fs.mkdir(path, function(err) {
fs.mkdir(path, err => {
if (err) {
// check if directory exists
fs.stat(path, function(err2, stat) {
fs.stat(path, (err2, stat) => {
if (err2 || !stat.isDirectory()) {

@@ -135,9 +135,9 @@ callback(err);

exports.copy = function(files, base, dest) {
return new Promise(function(resolve, reject) {
var pairs = [];
var destFiles = [];
files.forEach(function(file) {
var src = path.resolve(base, file);
var relative = path.relative(base, src);
var target = path.join(dest, relative);
return new Promise((resolve, reject) => {
const pairs = [];
const destFiles = [];
files.forEach(file => {
const src = path.resolve(base, file);
const relative = path.relative(base, src);
const target = path.join(dest, relative);
pairs.push({

@@ -150,7 +150,7 @@ src: src,

async.eachSeries(dirsToCreate(destFiles), makeDir, function(err) {
async.eachSeries(dirsToCreate(destFiles), makeDir, err => {
if (err) {
return reject(err);
}
async.each(pairs, copyFile, function(err) {
async.each(pairs, copyFile, err => {
if (err) {

@@ -165,1 +165,15 @@ return reject(err);

};
exports.getUser = function(cwd) {
return Promise.all([
new Git(cwd).exec('config', 'user.name'),
new Git(cwd).exec('config', 'user.email')
])
.then(results => {
return {name: results[0].output.trim(), email: results[1].output.trim()};
})
.catch(err => {
// git config exits with 1 if name or email is not set
return null;
});
};
{
"name": "gh-pages",
"version": "1.2.0",
"version": "2.0.0",
"description": "Publish to a gh-pages branch on GitHub (or any other branch on any other remote)",

@@ -30,11 +30,12 @@ "keywords": [

"engines": {
"node": ">=4"
"node": ">=6"
},
"dependencies": {
"async": "2.6.1",
"commander": "2.15.1",
"async": "^2.6.1",
"commander": "^2.18.0",
"email-addresses": "^3.0.1",
"filenamify-url": "^1.0.0",
"fs-extra": "^5.0.0",
"fs-extra": "^7.0.0",
"globby": "^6.1.0",
"graceful-fs": "4.1.11",
"graceful-fs": "^4.1.11",
"rimraf": "^2.6.2"

@@ -45,7 +46,7 @@ },

"dir-compare": "^1.4.0",
"eslint": "^4.19.1",
"eslint-config-tschaub": "^10.0.0",
"mocha": "^5.0.5",
"sinon": "^5.0.1",
"tmp": "0.0.33"
"eslint": "^5.5.0",
"eslint-config-tschaub": "^12.0.1",
"mocha": "^5.2.0",
"sinon": "^6.2.0",
"tmp": "^0.0.33"
},

@@ -52,0 +53,0 @@ "bin": {

@@ -1,3 +0,3 @@

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

@@ -4,0 +4,0 @@ module.exports = function(pluginConfig, config, callback) {

@@ -231,22 +231,2 @@

#### <a id="optionsclone">options.clone</a>
* type: `string`
* default: temporary directory inside the `gh-pages` directory
Path to a directory where your repository will be cloned. If this directory doesn't already exist, it will be created. If it already exists, it is assumed to be a clone of your repository.
Example use of the `clone` option:
```js
/**
* If you already have a temp directory, and want the repository cloned there,
* use the `clone` option as below. To avoid re-cloning every time the task is
* run, this should be a directory that sticks around for a while.
*/
ghpages.publish('dist', {
clone: 'path/to/tmp/dir'
}, callback);
```
#### <a id="optionspush">options.push</a>

@@ -253,0 +233,0 @@ * type: `boolean`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc