Skip to content

Commit

Permalink
Deploy to other remotes more easily (GustavoFernandes#16)
Browse files Browse the repository at this point in the history
* Tweak gh-deploy code to facilitate other deploy targets

* Add some packages...

yarn add --dev yargs
yarn add --dev inquirer
yarn add --dev gulp-sequence

* Add prompt and cmd-line arg to deploy to custom remote

* Only prompt when deploying to official site

* Little fixes

* Move flag check closer to entry point

* Update readme
  • Loading branch information
jonsmithers authored and dumbbillyhardy committed Jun 15, 2017
1 parent 8a82a79 commit 160a568
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 27 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# gulp tasks

| Task | Description |
| ----------------- | -------------------------------------------------------------------------------------------------------- |
| `gulp` | Builds to `dist/`. |
| `gulp serve` | Serves from `src/`. Automatically reloads browsers when you modify soruce. |
| `gulp serve-dist` | Builds and serves from `dist/`. Automatically re-builds and reloads browsers whenever you modify source. |
| `gulp gh-deploy` | Builds and deploys `dist/` to `origin/gh-pages`. |
| `gulp lint` | Check for bad code. |
| Task | Description |
| ----------------- | -------------------------------------------------------------------------------------------------------- |
| `gulp` | Builds to `dist/`. |
| `gulp serve` | Builds and serves from `dist/`. Automatically re-builds and reloads browsers whenever you modify source. |
| `gulp gh-deploy` | Requires a `--remoteUrl="https://...git"` flag. Builds and deploys to the `gh-pages` branch of that remote. |
| `gulp lint` | Check for bad code. |
33 changes: 31 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const dontVulcanizeTheseFiles = [
'./bower_components/webcomponentsjs/custom-elements-es5-adapter.js'
];

var argv = require('yargs').argv;
var babel = require('gulp-babel');
var browserSync = require('browser-sync');
var clean = require('gulp-clean');
Expand All @@ -30,10 +31,12 @@ var ghPages = require('gulp-gh-pages');
var git = require('git-rev-sync');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var inquirer = require('inquirer');
var merge = require('gulp-merge');
var minifyCss = require('gulp-clean-css');
var minifyHtml = require('gulp-minify-html');
var replace = require('gulp-replace');
var sequence = require('gulp-sequence');
var uglify = require('gulp-uglify');
var vulcanize = require('gulp-vulcanize');

Expand Down Expand Up @@ -145,10 +148,36 @@ gulp.task('lint', function () {
.pipe(gulpif(isFixed, gulp.dest('.')));
});

gulp.task('gh-deploy', ['switch-to-src','default'], () => {
gulp.task('gh-deploy', (cb) => {
if (!argv.remoteUrl) {
return Promise.reject('--remoteUrl="..." flag is required');
}
return sequence('gh-deploy-confirm', ['switch-to-src','default'], 'gh-deploy-helper')(cb);
});
gulp.task('gh-deploy-confirm', () => {
if ('https://github.com/MergeMyPullRequest/order-splitter.git' === argv.remoteUrl) {
return inquirer.prompt([
{
type: 'confirm',
name: 'shouldDeploy',
message: 'Are you sure you want to deploy to "mergemypullrequest.github.io/order-splitter"?'
}
]).then(({shouldDeploy}) => {
if (!shouldDeploy) {
throw new Error('cancelled by user');
} else {
remoteUrl = argv.remoteUrl; // add to global scope
}
});
} else {
remoteUrl = argv.remoteUrl; // add to global scope
return Promise.resolve();
}
});
gulp.task('gh-deploy-helper', () => {
return gulp.src(deployDir+'/**')
.pipe(ghPages({
remote: 'origin',
remoteUrl,
branch: 'gh-pages'
}));
});
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
"gulp-merge": "^0.1.1",
"gulp-minify-html": "^1.0.6",
"gulp-replace": "^0.5.4",
"gulp-sequence": "^0.4.6",
"gulp-uglify": "^2.0.1",
"gulp-vulcanize": "^6.1.0"
"gulp-vulcanize": "^6.1.0",
"inquirer": "^3.1.0",
"yargs": "^8.0.2"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 160a568

Please sign in to comment.