-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
光弘
committed
Dec 15, 2016
1 parent
af80856
commit 55976f7
Showing
32 changed files
with
1,304 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright | ||
|
||
2014 Micheal Benedict (@micheal) | ||
2015 Shinnosuke Watanabe (@shinnn) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// fork version, see https://github.com/shinnn/gulp-gh-pages/pull/83 for deatils | ||
|
||
|
||
# gulp-gh-pages | ||
|
||
[](https://www.npmjs.com/package/gulp-gh-pages) | ||
[](https://travis-ci.org/shinnn/gulp-gh-pages) | ||
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/gulp-gh-pages) | ||
[](https://coveralls.io/r/shinnn/gulp-gh-pages) | ||
[](https://david-dm.org/shinnn/gulp-gh-pages) | ||
[](https://david-dm.org/shinnn/gulp-gh-pages#info=devDependencies) | ||
|
||
[gulp](http://gulpjs.com/) plugin to publish contents to [Github pages](https://pages.github.com/) | ||
|
||
## Installation | ||
|
||
[Use npm](https://docs.npmjs.com/cli/install). | ||
|
||
```sh | ||
npm install --save-dev gulp-gh-pages | ||
``` | ||
|
||
## Usage | ||
|
||
Define a `deploy` task in your `gulpfile.js` (as below) which can be used to push to `gh-pages` going forward. | ||
|
||
```javascript | ||
var gulp = require('gulp'); | ||
var ghPages = require('gulp-gh-pages'); | ||
|
||
gulp.task('deploy', function() { | ||
return gulp.src('./dist/**/*') | ||
.pipe(ghPages()); | ||
}); | ||
``` | ||
|
||
Now, you should be able to call your task by doing: | ||
|
||
```she | ||
gulp deploy | ||
``` | ||
|
||
## API | ||
|
||
```javascript | ||
var ghPages = require('gulp-gh-pages'); | ||
``` | ||
|
||
### ghPages([*options*]) | ||
|
||
*options*: `Object` | ||
Return: `Object` ([stream.Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform_1)) | ||
|
||
#### options.remoteUrl | ||
|
||
Type: `String` | ||
Default: URL for the remote of the current dir (assumes a git repository) | ||
|
||
By default `gulp-gh-pages` assumes the current working directory is a git repository and uses its remote url. If your `gulpfile.js` is not in a git repository, or if you want to push to a different remote url, you can specify it. Ensure you have write access to the repository. | ||
|
||
#### options.origin | ||
|
||
Type: `String` | ||
Default: `"origin"` | ||
|
||
Git remote. | ||
|
||
#### options.branch | ||
|
||
Type: `String` | ||
Default: `"gh-pages"` | ||
|
||
The branch where deploy will by done. Change to "master" for `username.github.io` projects. | ||
|
||
#### options.cacheDir | ||
|
||
Type: `String` | ||
Default: `.publish` | ||
|
||
Set the directory path to keep a cache of the repository. If it doesn't exist, gulp-gh-pages automatically create it. | ||
|
||
#### options.push | ||
|
||
Type: `Boolean` | ||
Default: `true` | ||
|
||
Allow you to make a build on the defined branch without pushing it to master. Useful for dry run. | ||
|
||
#### options.force | ||
|
||
Type: `Boolean` | ||
Default: `false` | ||
|
||
Force adding files to the `gh-pages` branch, even if they are ignored by `.gitignore` or `.gitignore_global`. | ||
|
||
#### options.message | ||
|
||
Type: `String` | ||
Default: `"Update [timestamp]"` | ||
|
||
Edit commit message. | ||
|
||
## License | ||
|
||
Copyright (c) 2014 [Micheal Benedict](https://github.com/rowoot), 2015 [Shinnosuke Watanabe](https://github.com/shinnn) | ||
|
||
Licensed under [the MIT License](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
'use strict'; | ||
|
||
var git = require('./lib/git'); | ||
var gutil = require('gulp-util'); | ||
var Transform = require('readable-stream/transform'); | ||
var vinylFs = require('vinyl-fs'); | ||
var wrapPromise = require('wrap-promise'); | ||
|
||
/* | ||
* Public: Push to gh-pages branch for github | ||
* | ||
* options - {Object} that contains all the options of the plugin | ||
* - remoteUrl: The {String} remote url (github repository) of the project, | ||
* - origin: The {String} origin of the git repository (default to `"origin"`), | ||
* - branch: The {String} branch where deploy will by done (default to `"gh-pages"`), | ||
* - cacheDir: {String} where the git repo will be located. (default to a temporary folder) | ||
* - push: {Boolean} to know whether or not the branch should be pushed (default to `true`) | ||
* - message: {String} commit message (default to `"Update [timestamp]"`) | ||
* | ||
* Returns `Stream`. | ||
**/ | ||
module.exports = function gulpGhPages(options) { | ||
options = options || {}; | ||
var origin = options.origin || 'origin'; | ||
var branch = options.branch || 'gh-pages'; | ||
var message = options.message || 'Update ' + new Date().toISOString(); | ||
|
||
var files = []; | ||
var TAG; | ||
if (branch !== 'gh-pages') { | ||
TAG = '[gh-pages (' + branch + ')]'; | ||
} else { | ||
TAG = '[gh-pages]'; | ||
} | ||
|
||
return new Transform({ | ||
objectMode: true, | ||
transform: function collectFiles(file, enc, cb) { | ||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
|
||
if (file.isStream()) { | ||
cb(new gutil.PluginError('gulp-gh-pages', 'Stream content is not supported')); | ||
return; | ||
} | ||
|
||
files.push(file); | ||
cb(null, file); | ||
}, | ||
flush: function publish(cb) { | ||
if (files.length === 0) { | ||
gutil.log(TAG, 'No files in the stream.'); | ||
cb(); | ||
return; | ||
} | ||
|
||
var newBranchCreated = false; | ||
|
||
git.prepareRepo(options.remoteUrl, origin, options.cacheDir || '.publish') | ||
.then(function(repo) { | ||
gutil.log(TAG, 'Cloning repo'); | ||
if (repo._localBranches.indexOf(branch) > -1) { | ||
gutil.log(TAG, 'Checkout branch `' + branch + '`'); | ||
return repo.checkoutBranch(branch); | ||
} | ||
|
||
if (repo._remoteBranches.indexOf('origin/' + branch) > -1) { | ||
gutil.log(TAG, 'Checkout remote branch `' + branch + '`'); | ||
return repo.checkoutBranch(branch); | ||
} | ||
|
||
gutil.log(TAG, 'Create branch `' + branch + '` and checkout'); | ||
newBranchCreated = true; | ||
return repo.createAndCheckoutBranch(branch); | ||
}) | ||
.then(function(repo) { | ||
return wrapPromise(function(resolve, reject) { | ||
if (newBranchCreated) { | ||
resolve(repo); | ||
return; | ||
} | ||
|
||
// updating to avoid having local cache not up to date | ||
gutil.log(TAG, 'Updating repository'); | ||
repo._repo.git('pull', function(err) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(repo); | ||
}); | ||
}); | ||
}) | ||
.then(function(repo) { | ||
// remove all files | ||
return wrapPromise(function(resolve, reject) { | ||
repo._repo.remove('.', {r: true}, function(err) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(repo.status()); | ||
}); | ||
}); | ||
}) | ||
.then(function(repo) { | ||
gutil.log(TAG, 'Copying files to repository'); | ||
|
||
return wrapPromise(function(resolve, reject) { | ||
var destStream = vinylFs.dest(repo._repo.path) | ||
.on('error', reject) | ||
.on('end', function() { | ||
resolve(repo); | ||
}) | ||
.resume(); | ||
|
||
files.forEach(function(file) { | ||
destStream.write(file); | ||
}); | ||
|
||
destStream.end(); | ||
}); | ||
}) | ||
.then(function(repo) { | ||
return repo.addFiles('.', {force: options.force || false}); | ||
}) | ||
.then(function(repo) { | ||
var filesToBeCommitted = Object.keys(repo._staged).length; | ||
if (filesToBeCommitted === 0) { | ||
gutil.log(TAG, 'No files have changed.'); | ||
cb(); | ||
return; | ||
} | ||
|
||
gutil.log(TAG, 'Adding ' + filesToBeCommitted + ' files.'); | ||
gutil.log(TAG, 'Committing "' + message + '"'); | ||
repo.commit(message).then(function(newRepo) { | ||
if (options.push === undefined || options.push) { | ||
gutil.log(TAG, 'Pushing to remote.'); | ||
newRepo._repo.git('push', { | ||
'set-upstream': true | ||
}, ['origin', newRepo._currentBranch], function(err) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
cb(); | ||
}); | ||
return; | ||
} | ||
cb(); | ||
}, cb); | ||
}) | ||
.catch(function(err) { | ||
setImmediate(function() { | ||
cb(new gutil.PluginError('gulp-gh-pages', err)); | ||
}); | ||
}); | ||
} | ||
}); | ||
}; |
Oops, something went wrong.