Compare commits
20 commits
master
...
publish-br
Author | SHA1 | Date | |
---|---|---|---|
|
47e5e5c376 | ||
|
9f165c208b | ||
|
53d69c7200 | ||
|
ce63e87fd0 | ||
|
a2dbd3f1b9 | ||
|
e0dd4eaa54 | ||
|
fde7245554 | ||
|
e0f90a8ec2 | ||
|
9ac60dfea7 | ||
|
c6cd05dde5 | ||
|
ffc8d6acf5 | ||
|
33815e4cb1 | ||
|
b7e8779c41 | ||
|
f8a7f4cf11 | ||
|
b424c0fdea | ||
|
7bc6da9277 | ||
|
49e48a457a | ||
|
ab5c4e570c | ||
|
fd9e5cf38f | ||
|
d1dbe48527 |
7 changed files with 121 additions and 16 deletions
|
@ -1,6 +1,10 @@
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "4"
|
- "6"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
|
|
|
@ -27,6 +27,8 @@ program
|
||||||
'Remove files that match the given pattern ' +
|
'Remove files that match the given pattern ' +
|
||||||
'(ignored if used together with --add).', '.')
|
'(ignored if used together with --add).', '.')
|
||||||
.option('-n, --no-push', 'Commit only (with no push)')
|
.option('-n, --no-push', 'Commit only (with no push)')
|
||||||
|
.option('-e, --dest <dest>', 'The destination in the target branch', '.')
|
||||||
|
.option('-c, --branchname-as-dest', 'Use a subfolder named after the current as the destination')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
ghpages.publish(path.join(process.cwd(), program.dist), {
|
ghpages.publish(path.join(process.cwd(), program.dist), {
|
||||||
|
@ -41,6 +43,8 @@ ghpages.publish(path.join(process.cwd(), program.dist), {
|
||||||
only: program.remove,
|
only: program.remove,
|
||||||
remote: program.remote,
|
remote: program.remote,
|
||||||
push: !program.noPush,
|
push: !program.noPush,
|
||||||
|
dest: program.dest,
|
||||||
|
branchnameAsDest: program.branchnameAsDest,
|
||||||
logger: function(message) {
|
logger: function(message) {
|
||||||
process.stderr.write(message + '\n');
|
process.stderr.write(message + '\n');
|
||||||
}
|
}
|
||||||
|
|
20
changelog.md
20
changelog.md
|
@ -1,3 +1,23 @@
|
||||||
|
## v0.12.0
|
||||||
|
|
||||||
|
* [#146](https://github.com/tschaub/gh-pages/pull/146) - Updates dependencies ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#138](https://github.com/tschaub/gh-pages/pull/138) - Updated readme.md with svg image ([@sobolevn](https://github.com/sobolevn))
|
||||||
|
* [#142](https://github.com/tschaub/gh-pages/pull/142) - Update globby to version 6.1.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#134](https://github.com/tschaub/gh-pages/pull/134) - Update eslint to version 3.8.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#135](https://github.com/tschaub/gh-pages/pull/135) - Update async to version 2.1.2 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#130](https://github.com/tschaub/gh-pages/pull/130) - Update mocha to version 3.1.1 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#112](https://github.com/tschaub/gh-pages/pull/112) - Update graceful-fs to version 4.1.6 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#106](https://github.com/tschaub/gh-pages/pull/106) - Add a --tag option to the cli ([@donavon](https://github.com/donavon))
|
||||||
|
* [#102](https://github.com/tschaub/gh-pages/pull/102) - Update graceful-fs to version 4.1.5 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#89](https://github.com/tschaub/gh-pages/pull/89) - Update globby to version 5.0.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#87](https://github.com/tschaub/gh-pages/pull/87) - Update eslint-config-tschaub to version 5.0.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#78](https://github.com/tschaub/gh-pages/pull/78) - Use rimraf for cleaning ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#75](https://github.com/tschaub/gh-pages/pull/75) - Expose a "remove" option to the CLI ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#76](https://github.com/tschaub/gh-pages/pull/76) - Update eslint to version 2.8.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#70](https://github.com/tschaub/gh-pages/pull/70) - Update eslint to version 2.7.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#63](https://github.com/tschaub/gh-pages/pull/63) - Update eslint to version 2.4.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
* [#62](https://github.com/tschaub/gh-pages/pull/62) - Update eslint to version 2.3.0 🚀 ([@tschaub](https://github.com/tschaub))
|
||||||
|
|
||||||
## v0.11.0
|
## v0.11.0
|
||||||
|
|
||||||
* [#61](https://github.com/tschaub/gh-pages/pull/61) - Support a custom remote. ([@marco-c](https://github.com/marco-c))
|
* [#61](https://github.com/tschaub/gh-pages/pull/61) - Support a custom remote. ([@marco-c](https://github.com/marco-c))
|
||||||
|
|
|
@ -99,8 +99,7 @@ exports.clone = function clone(repo, dir, branch, options) {
|
||||||
return Q.resolve();
|
return Q.resolve();
|
||||||
} else {
|
} else {
|
||||||
return fs.makeTree(path.dirname(path.resolve(dir))).then(function() {
|
return fs.makeTree(path.dirname(path.resolve(dir))).then(function() {
|
||||||
var args = ['clone', repo, dir, '--branch', branch, '--single-branch',
|
var args = ['clone', repo, dir, '--branch', branch, '--single-branch', '--origin', options.remote];
|
||||||
'--origin', options.remote];
|
|
||||||
if (options.depth) {
|
if (options.depth) {
|
||||||
args.push('--depth', options.depth);
|
args.push('--depth', options.depth);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +206,7 @@ exports.add = function add(files, cwd) {
|
||||||
* @return {Promise} A promise.
|
* @return {Promise} A promise.
|
||||||
*/
|
*/
|
||||||
exports.commit = function commit(message, cwd) {
|
exports.commit = function commit(message, cwd) {
|
||||||
return spawn(git, ['diff-index', '--quiet', 'HEAD', '.'], cwd)
|
return spawn(git, ['diff-index', '--quiet', 'HEAD', '--', '.'], cwd)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
// nothing to commit
|
// nothing to commit
|
||||||
return Q.resolve();
|
return Q.resolve();
|
||||||
|
|
51
lib/index.js
51
lib/index.js
|
@ -35,6 +35,35 @@ function getRemoteUrl(dir, remote) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a promise resolving to the currently checked out branch name.
|
||||||
|
* @param {Object} options The options object
|
||||||
|
* @return {Promise} A promise.
|
||||||
|
*/
|
||||||
|
function getBranchName(options) {
|
||||||
|
var name;
|
||||||
|
return git(['rev-parse', '--abbrev-ref', 'HEAD'], options.repo || process.cwd())
|
||||||
|
.progress(function(chunk) {
|
||||||
|
name = String(chunk).split(/[\n\r]/).shift();
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
if (name) {
|
||||||
|
return Q.resolve(name);
|
||||||
|
} else {
|
||||||
|
return Q.reject(new Error(
|
||||||
|
'Failed to get branch name from options or current directory.'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function(err) {
|
||||||
|
return Q.reject(new Error(
|
||||||
|
'Failed to get branch name (task must either be ' +
|
||||||
|
'run in a git repository or must be configured with the "repo" ' +
|
||||||
|
'option).'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getRepo(options) {
|
function getRepo(options) {
|
||||||
if (options.repo) {
|
if (options.repo) {
|
||||||
return Q.resolve(options.repo);
|
return Q.resolve(options.repo);
|
||||||
|
@ -57,6 +86,8 @@ exports.publish = function publish(basePath, config, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
|
dest: '.',
|
||||||
|
branchnameAsDest: false,
|
||||||
add: false,
|
add: false,
|
||||||
git: 'git',
|
git: 'git',
|
||||||
clone: getCacheDir(),
|
clone: getCacheDir(),
|
||||||
|
@ -129,6 +160,8 @@ exports.publish = function publish(basePath, config, callback) {
|
||||||
|
|
||||||
git.exe(options.git);
|
git.exe(options.git);
|
||||||
|
|
||||||
|
var dest = options.dest;
|
||||||
|
|
||||||
var repoUrl;
|
var repoUrl;
|
||||||
getRepo(options)
|
getRepo(options)
|
||||||
.then(function(repo) {
|
.then(function(repo) {
|
||||||
|
@ -136,6 +169,17 @@ exports.publish = function publish(basePath, config, callback) {
|
||||||
log('Cloning ' + repo + ' into ' + options.clone);
|
log('Cloning ' + repo + ' into ' + options.clone);
|
||||||
return git.clone(repo, options.clone, options.branch, options);
|
return git.clone(repo, options.clone, options.branch, options);
|
||||||
})
|
})
|
||||||
|
.then(function() {
|
||||||
|
if (options.branchnameAsDest) {
|
||||||
|
log('Retrieving current branch name');
|
||||||
|
return getBranchName(options.clone)
|
||||||
|
.then(function(branchname) {
|
||||||
|
dest = './' + branchname;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Q.resolve();
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return getRemoteUrl(options.clone, options.remote)
|
return getRemoteUrl(options.clone, options.remote)
|
||||||
.then(function(url) {
|
.then(function(url) {
|
||||||
|
@ -168,14 +212,17 @@ exports.publish = function publish(basePath, config, callback) {
|
||||||
.then(function() {
|
.then(function() {
|
||||||
if (!options.add) {
|
if (!options.add) {
|
||||||
log('Removing files');
|
log('Removing files');
|
||||||
return git.rm(only.join(' '), options.clone);
|
var outputFiles = only.map(function(file) {
|
||||||
|
return path.join(dest, file);
|
||||||
|
});
|
||||||
|
return git.rm(outputFiles.join(' '), options.clone);
|
||||||
} else {
|
} else {
|
||||||
return Q.resolve();
|
return Q.resolve();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
log('Copying files');
|
log('Copying files');
|
||||||
return copy(files, basePath, options.clone);
|
return copy(files, basePath, path.join(options.clone, dest));
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
log('Adding all');
|
log('Adding all');
|
||||||
|
|
16
package.json
16
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "gh-pages",
|
"name": "gh-pages",
|
||||||
"version": "0.11.0",
|
"version": "0.12.0",
|
||||||
"description": "Publish to a gh-pages branch on GitHub (or any other branch on any other remote)",
|
"description": "Publish to a gh-pages branch on GitHub (or any other branch on any other remote)",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"git",
|
"git",
|
||||||
|
@ -28,17 +28,17 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "2.1.2",
|
"async": "2.1.2",
|
||||||
"commander": "2.9.0",
|
"commander": "2.9.0",
|
||||||
"globby": "^5.0.0",
|
"globby": "^6.1.0",
|
||||||
"graceful-fs": "4.1.6",
|
"graceful-fs": "4.1.10",
|
||||||
"q": "1.4.1",
|
"q": "1.4.1",
|
||||||
"q-io": "1.13.2",
|
"q-io": "1.13.2",
|
||||||
"rimraf": "^2.5.2"
|
"rimraf": "^2.5.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^3.4.1",
|
"chai": "^3.5.0",
|
||||||
"eslint": "3.8.0",
|
"eslint": "^3.10.2",
|
||||||
"eslint-config-tschaub": "5.0.0",
|
"eslint-config-tschaub": "^6.0.0",
|
||||||
"mocha": "^3.1.1"
|
"mocha": "^3.1.2"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"gh-pages": "bin/gh-pages"
|
"gh-pages": "bin/gh-pages"
|
||||||
|
|
35
readme.md
35
readme.md
|
@ -64,7 +64,7 @@ ghpages.publish(path.join(__dirname, 'build'), callback);
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
The default options work for simple cases cases. The options described below let you push to alternate branches, customize your commit messages, and more.
|
The default options work for simple cases. The options described below let you push to alternate branches, customize your commit messages, and more.
|
||||||
|
|
||||||
|
|
||||||
#### <a id="optionssrc">options.src</a>
|
#### <a id="optionssrc">options.src</a>
|
||||||
|
@ -299,6 +299,37 @@ ghpages.publish(path.join(__dirname, 'build'), {
|
||||||
}, callback);
|
}, callback);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### <a id="optionsdest">options.dest</a>
|
||||||
|
* type: `string`
|
||||||
|
* default: `'.'`
|
||||||
|
|
||||||
|
The destination folder within the destination branch/repository.
|
||||||
|
|
||||||
|
Example use of the `dest` option:
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* Place content in the static/project subdirectory of the target
|
||||||
|
* branch/repository. If removing files, only remove static/project.
|
||||||
|
*/
|
||||||
|
ghpages.publish(path.join(__dirname, 'build'), {
|
||||||
|
dest: 'static/project'
|
||||||
|
}, callback);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <a id="optionsdest">options.branchnameAsDest</a>
|
||||||
|
* type: `boolean`
|
||||||
|
* default: `false`
|
||||||
|
|
||||||
|
Use the current branch name as the path to the destination folder within the destination branch/repository. This option overrides the `dest` option.
|
||||||
|
|
||||||
|
Example use of the `dest` option:
|
||||||
|
|
||||||
|
```js
|
||||||
|
ghpages.publish(path.join(__dirname, 'build'), { branchnameAsDest: true }, callback);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Command Line Utility
|
## Command Line Utility
|
||||||
|
|
||||||
Installing the package creates a `gh-pages` command line utility. Run `gh-pages --help` to see a list of supported options.
|
Installing the package creates a `gh-pages` command line utility. Run `gh-pages --help` to see a list of supported options.
|
||||||
|
@ -321,4 +352,4 @@ npm run deploy
|
||||||
|
|
||||||
Note that this plugin requires Git 1.7.6 or higher (because it uses the `--exit-code` option for `git ls-remote`). If you'd like to see this working with earlier versions of Git, please [open an issue](https://github.com/tschaub/gh-pages/issues).
|
Note that this plugin requires Git 1.7.6 or higher (because it uses the `--exit-code` option for `git ls-remote`). If you'd like to see this working with earlier versions of Git, please [open an issue](https://github.com/tschaub/gh-pages/issues).
|
||||||
|
|
||||||
[](https://travis-ci.org/tschaub/gh-pages)
|
[](https://travis-ci.org/tschaub/gh-pages)
|
||||||
|
|
Reference in a new issue