Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
277
node_modules/gh-pages/lib/git.js
generated
vendored
Normal file
277
node_modules/gh-pages/lib/git.js
generated
vendored
Normal file
|
@ -0,0 +1,277 @@
|
|||
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) {
|
||||
const callee = arguments.callee;
|
||||
Error.apply(this, [message]);
|
||||
Error.captureStackTrace(this, callee);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.name = callee.name;
|
||||
}
|
||||
util.inherits(ProcessError, Error);
|
||||
|
||||
/**
|
||||
* Util function for handling spawned processes as promises.
|
||||
* @param {string} exe Executable.
|
||||
* @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 => {
|
||||
buffer.push(chunk.toString());
|
||||
});
|
||||
child.stdout.on('data', chunk => {
|
||||
buffer.push(chunk.toString());
|
||||
});
|
||||
child.on('close', code => {
|
||||
const output = buffer.join('');
|
||||
if (code) {
|
||||
const msg = output || 'Process failed: ' + code;
|
||||
reject(new ProcessError(code, msg));
|
||||
} else {
|
||||
resolve(output);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function Git(cwd, cmd) {
|
||||
this.cwd = cwd;
|
||||
this.cmd = cmd || 'git';
|
||||
this.output = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an arbitrary git command.
|
||||
* @param {string} var_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 => {
|
||||
this.output = output;
|
||||
return this;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize repository.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.init = function() {
|
||||
return this.exec('init');
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up unversioned files.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.clean = function() {
|
||||
return this.exec('clean', '-f', '-d');
|
||||
};
|
||||
|
||||
/**
|
||||
* Hard reset to remote/branch
|
||||
* @param {string} remote Remote alias.
|
||||
* @param {string} branch Branch name.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.reset = function(remote, branch) {
|
||||
return this.exec('reset', '--hard', remote + '/' + branch);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch from a remote.
|
||||
* @param {string} remote Remote alias.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.fetch = function(remote) {
|
||||
return this.exec('fetch', remote);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checkout a branch (create an orphan if it doesn't exist on the remote).
|
||||
* @param {string} remote Remote alias.
|
||||
* @param {string} branch Branch name.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.checkout = function(remote, branch) {
|
||||
const treeish = remote + '/' + branch;
|
||||
return this.exec('ls-remote', '--exit-code', '.', treeish).then(
|
||||
() => {
|
||||
// branch exists on remote, hard reset
|
||||
return this.exec('checkout', branch)
|
||||
.then(() => this.clean())
|
||||
.then(() => this.reset(remote, branch));
|
||||
},
|
||||
error => {
|
||||
if (error instanceof ProcessError && error.code === 2) {
|
||||
// branch doesn't exist, create an orphan
|
||||
return this.exec('checkout', '--orphan', branch);
|
||||
} else {
|
||||
// unhandled error
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove all unversioned files.
|
||||
* @param {string|string[]} files Files argument.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.rm = function(files) {
|
||||
if (!Array.isArray(files)) {
|
||||
files = [files];
|
||||
}
|
||||
return this.exec('rm', '--ignore-unmatch', '-r', '-f', ...files);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add files.
|
||||
* @param {string|string[]} files Files argument.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.add = function(files) {
|
||||
if (!Array.isArray(files)) {
|
||||
files = [files];
|
||||
}
|
||||
return this.exec('add', ...files);
|
||||
};
|
||||
|
||||
/**
|
||||
* Commit (if there are any changes).
|
||||
* @param {string} message Commit message.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.commit = function(message) {
|
||||
return this.exec('diff-index', '--quiet', 'HEAD').catch(() =>
|
||||
this.exec('commit', '-m', message)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add tag
|
||||
* @param {string} name Name of tag.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.tag = function(name) {
|
||||
return this.exec('tag', name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Push a branch.
|
||||
* @param {string} remote Remote alias.
|
||||
* @param {string} branch Branch name.
|
||||
* @param {boolean} force Force push.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
Git.prototype.push = function(remote, branch, force) {
|
||||
const args = ['push', '--tags', remote, branch];
|
||||
if (force) {
|
||||
args.push('--force');
|
||||
}
|
||||
return this.exec.apply(this, args);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the URL for a remote.
|
||||
* @param {string} remote Remote alias.
|
||||
* @return {Promise<string>} A promise for the remote URL.
|
||||
*/
|
||||
Git.prototype.getRemoteUrl = function(remote) {
|
||||
return this.exec('config', '--get', 'remote.' + remote + '.url')
|
||||
.then(git => {
|
||||
const repo = git.output && git.output.split(/[\n\r]/).shift();
|
||||
if (repo) {
|
||||
return repo;
|
||||
} else {
|
||||
throw new Error(
|
||||
'Failed to get repo URL from options or current directory.'
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
throw new Error(
|
||||
'Failed to get remote.' +
|
||||
remote +
|
||||
'.url (task must either be ' +
|
||||
'run in a git repository with a configured ' +
|
||||
remote +
|
||||
' remote ' +
|
||||
'or must be configured with the "repo" option).'
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete ref to remove branch history
|
||||
* @param {string} branch
|
||||
*/
|
||||
Git.prototype.deleteRef = function(branch) {
|
||||
return this.exec('update-ref', '-d', 'refs/heads/' + branch);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clone a repo into the given dir if it doesn't already exist.
|
||||
* @param {string} repo Repository URL.
|
||||
* @param {string} dir Target directory.
|
||||
* @param {string} branch Branch name.
|
||||
* @param {options} options All options.
|
||||
* @return {Promise<Git>} A promise.
|
||||
*/
|
||||
Git.clone = function clone(repo, dir, branch, options) {
|
||||
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(() => {
|
||||
const args = [
|
||||
'clone',
|
||||
repo,
|
||||
dir,
|
||||
'--branch',
|
||||
branch,
|
||||
'--single-branch',
|
||||
'--origin',
|
||||
options.remote,
|
||||
'--depth',
|
||||
options.depth
|
||||
];
|
||||
return spawn(options.git, args)
|
||||
.catch(err => {
|
||||
// try again without branch or depth options
|
||||
return spawn(options.git, [
|
||||
'clone',
|
||||
repo,
|
||||
dir,
|
||||
'--origin',
|
||||
options.remote
|
||||
]);
|
||||
})
|
||||
.then(() => new Git(dir, options.git));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Git;
|
255
node_modules/gh-pages/lib/index.js
generated
vendored
Normal file
255
node_modules/gh-pages/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,255 @@
|
|||
const findCacheDir = require('find-cache-dir');
|
||||
const Git = require('./git');
|
||||
const filenamify = require('filenamify');
|
||||
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');
|
||||
|
||||
const log = util.debuglog('gh-pages');
|
||||
|
||||
/**
|
||||
* Get the cache directory.
|
||||
* @param {string} [optPath] Optional path.
|
||||
* @returns {string} The full path to the cache directory.
|
||||
*/
|
||||
function getCacheDir(optPath) {
|
||||
const dir = findCacheDir({name: 'gh-pages'});
|
||||
if (!optPath) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
return path.join(dir, filenamify(optPath));
|
||||
}
|
||||
exports.getCacheDir = getCacheDir;
|
||||
|
||||
function getRepo(options) {
|
||||
if (options.repo) {
|
||||
return Promise.resolve(options.repo);
|
||||
} else {
|
||||
const git = new Git(process.cwd(), options.git);
|
||||
return git.getRemoteUrl(options.remote);
|
||||
}
|
||||
}
|
||||
|
||||
exports.defaults = {
|
||||
dest: '.',
|
||||
add: false,
|
||||
git: 'git',
|
||||
depth: 1,
|
||||
dotfiles: false,
|
||||
branch: 'gh-pages',
|
||||
remote: 'origin',
|
||||
src: '**/*',
|
||||
remove: '.',
|
||||
push: true,
|
||||
history: true,
|
||||
message: 'Updates',
|
||||
silent: false
|
||||
};
|
||||
|
||||
/**
|
||||
* Push a git branch to a remote (pushes gh-pages by default).
|
||||
* @param {string} basePath The base path.
|
||||
* @param {Object} config Publish options.
|
||||
* @param {Function} callback Callback.
|
||||
*/
|
||||
exports.publish = function publish(basePath, config, callback) {
|
||||
if (typeof config === 'function') {
|
||||
callback = config;
|
||||
config = {};
|
||||
}
|
||||
|
||||
const options = Object.assign({}, exports.defaults, config);
|
||||
|
||||
// For backward compatibility before fixing #334
|
||||
if (options.only) {
|
||||
options.remove = options.only;
|
||||
}
|
||||
|
||||
if (!callback) {
|
||||
callback = function(err) {
|
||||
if (err) {
|
||||
log(err.message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function done(err) {
|
||||
try {
|
||||
callback(err);
|
||||
} catch (err2) {
|
||||
log('Publish callback threw: %s', err2.message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!fs.statSync(basePath).isDirectory()) {
|
||||
done(new Error('The "base" option must be an existing directory'));
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
done(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const files = globby
|
||||
.sync(options.src, {
|
||||
cwd: basePath,
|
||||
dot: options.dotfiles
|
||||
})
|
||||
.filter(file => {
|
||||
return !fs.statSync(path.join(basePath, file)).isDirectory();
|
||||
});
|
||||
|
||||
if (!Array.isArray(files) || files.length === 0) {
|
||||
done(
|
||||
new Error('The pattern in the "src" property didn\'t match any files.')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
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 = getCacheDir(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.history) {
|
||||
return git.deleteRef(options.branch);
|
||||
} else {
|
||||
return git;
|
||||
}
|
||||
})
|
||||
.then(git => {
|
||||
if (options.add) {
|
||||
return git;
|
||||
}
|
||||
|
||||
log('Removing files');
|
||||
const files = globby
|
||||
.sync(options.remove, {
|
||||
cwd: path.join(git.cwd, options.dest)
|
||||
})
|
||||
.map(file => path.join(options.dest, file));
|
||||
if (files.length > 0) {
|
||||
return git.rm(files);
|
||||
} else {
|
||||
return git;
|
||||
}
|
||||
})
|
||||
.then(git => {
|
||||
log('Copying files');
|
||||
return copy(files, basePath, path.join(git.cwd, options.dest)).then(
|
||||
function() {
|
||||
return git;
|
||||
}
|
||||
);
|
||||
})
|
||||
.then(git => {
|
||||
return Promise.resolve(
|
||||
options.beforeAdd && options.beforeAdd(git)
|
||||
).then(() => git);
|
||||
})
|
||||
.then(git => {
|
||||
log('Adding all');
|
||||
return git.add('.');
|
||||
})
|
||||
.then(git => {
|
||||
if (!user) {
|
||||
return 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(git => {
|
||||
if (options.push) {
|
||||
log('Pushing');
|
||||
return git.push(options.remote, options.branch, !options.history);
|
||||
} else {
|
||||
return git;
|
||||
}
|
||||
})
|
||||
.then(
|
||||
() => done(),
|
||||
error => {
|
||||
if (options.silent) {
|
||||
error = new Error(
|
||||
'Unspecified error (run without silent option for detail)'
|
||||
);
|
||||
}
|
||||
done(error);
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean the cache directory.
|
||||
*/
|
||||
exports.clean = function clean() {
|
||||
fs.removeSync(getCacheDir());
|
||||
};
|
169
node_modules/gh-pages/lib/util.js
generated
vendored
Normal file
169
node_modules/gh-pages/lib/util.js
generated
vendored
Normal file
|
@ -0,0 +1,169 @@
|
|||
const path = require('path');
|
||||
const Git = require('./git');
|
||||
const async = require('async');
|
||||
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.
|
||||
*/
|
||||
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 (let i = 1, ii = parts.length; i < ii; ++i) {
|
||||
partial = path.join(partial, parts[i]);
|
||||
dirs[partial] = true;
|
||||
}
|
||||
});
|
||||
return Object.keys(dirs);
|
||||
});
|
||||
|
||||
/**
|
||||
* Sort function for paths. Sorter paths come first. Paths of equal length are
|
||||
* sorted alphanumerically in path segment order.
|
||||
* @param {string} a First path.
|
||||
* @param {string} b Second path.
|
||||
* @return {number} Comparison.
|
||||
*/
|
||||
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) {
|
||||
cmp = -1;
|
||||
} else if (aLength > bLength) {
|
||||
cmp = 1;
|
||||
} else {
|
||||
let aPart, bPart;
|
||||
for (let i = 0; i < aLength; ++i) {
|
||||
aPart = aParts[i];
|
||||
bPart = bParts[i];
|
||||
if (aPart < bPart) {
|
||||
cmp = -1;
|
||||
break;
|
||||
} else if (aPart > bPart) {
|
||||
cmp = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cmp;
|
||||
});
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const dirsToCreate = (exports.dirsToCreate = function(files) {
|
||||
return uniqueDirs(files).sort(byShortPath);
|
||||
});
|
||||
|
||||
/**
|
||||
* Copy a file.
|
||||
* @param {Object} obj Object with src and dest properties.
|
||||
* @param {function(Error)} callback Callback
|
||||
*/
|
||||
const copyFile = (exports.copyFile = function(obj, callback) {
|
||||
let called = false;
|
||||
function done(err) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
const read = fs.createReadStream(obj.src);
|
||||
read.on('error', err => {
|
||||
done(err);
|
||||
});
|
||||
|
||||
const write = fs.createWriteStream(obj.dest);
|
||||
write.on('error', err => {
|
||||
done(err);
|
||||
});
|
||||
write.on('close', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
read.pipe(write);
|
||||
});
|
||||
|
||||
/**
|
||||
* Make directory, ignoring errors if directory already exists.
|
||||
* @param {string} path Directory path.
|
||||
* @param {function(Error)} callback Callback.
|
||||
*/
|
||||
function makeDir(path, callback) {
|
||||
fs.mkdir(path, err => {
|
||||
if (err) {
|
||||
// check if directory exists
|
||||
fs.stat(path, (err2, stat) => {
|
||||
if (err2 || !stat.isDirectory()) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a list of files.
|
||||
* @param {Array.<string>} files Files to copy.
|
||||
* @param {string} base Base directory.
|
||||
* @param {string} dest Destination directory.
|
||||
* @return {Promise} A promise.
|
||||
*/
|
||||
exports.copy = function(files, base, dest) {
|
||||
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({
|
||||
src: src,
|
||||
dest: target
|
||||
});
|
||||
destFiles.push(target);
|
||||
});
|
||||
|
||||
async.eachSeries(dirsToCreate(destFiles), makeDir, err => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
async.each(pairs, copyFile, err => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
} else {
|
||||
return resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
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;
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue