|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var ghpages = require('gh-pages'); |
| 4 | +var RSVP = require('rsvp'); |
| 5 | + |
| 6 | +module.exports = { |
| 7 | + name: 'ghpages', |
| 8 | + aliases: ['gh-pages'], |
| 9 | + description: 'Publish to any gh-pages branch on GitHub (or any other branch on any other remote). Build the project before publishing!', |
| 10 | + works: 'insideProject', |
| 11 | + |
| 12 | + availableOptions: [{ |
| 13 | + name: 'repo', |
| 14 | + type: String, |
| 15 | + default: undefined, // using gh-pages default -- see readme |
| 16 | + description: 'The commit message to include with the build, must be wrapped in quotes.' |
| 17 | + }, { |
| 18 | + name: 'message', |
| 19 | + type: String, |
| 20 | + default: 'Auto-generated commit', |
| 21 | + description: 'The commit message, must be wrapped in quotes.' |
| 22 | + }, { |
| 23 | + name: 'branch', |
| 24 | + type: String, |
| 25 | + default: 'gh-pages', |
| 26 | + description: 'The git branch to push your pages to' |
| 27 | + }, { |
| 28 | + name: 'name', |
| 29 | + type: String, |
| 30 | + default: undefined, // using gh-pages default -- see readme |
| 31 | + description: 'The git user-name which is associated with this commit' |
| 32 | + }, { |
| 33 | + name: 'email', |
| 34 | + type: String, |
| 35 | + default: undefined, // using gh-pages default -- see readme |
| 36 | + description: 'The git user-email which is associated with this commit' |
| 37 | + }], |
| 38 | + run: function(options, rawArgs) { |
| 39 | + |
| 40 | + var ui = this.ui; |
| 41 | + var root = this.project.root; |
| 42 | + var dir = path.join(root, 'dist'); |
| 43 | + |
| 44 | + options = options || {}; |
| 45 | + if (options['name'] && options['email']) { |
| 46 | + options.user = { |
| 47 | + name: options['name'], |
| 48 | + email: options['email'] |
| 49 | + } |
| 50 | + }; |
| 51 | + options.dotfiles = true; |
| 52 | + options.silent = true; // hides credentials, if provided via repo URL |
| 53 | + |
| 54 | + if (process.env.TRAVIS) { |
| 55 | + options.message += '\n\n' + |
| 56 | + 'Triggered by commit: https://github.com/' + process.env.TRAVIS_REPO_SLUG + '/commit/' + process.env.TRAVIS_COMMIT + '\n' + |
| 57 | + 'Travis build: https://travis-ci.org/' + process.env.TRAVIS_REPO_SLUG + '/builds/' + process.env.TRAVIS_BUILD_ID; |
| 58 | + } |
| 59 | + |
| 60 | + var publish = RSVP.denodeify(ghpages.publish); |
| 61 | + |
| 62 | + return publish(dir, options) |
| 63 | + .then(function(committed) { |
| 64 | + ui.write('Successfully published!\n'); |
| 65 | + }); |
| 66 | + } |
| 67 | +}; |
0 commit comments