|
| 1 | +//TODO: set your AWS profile |
| 2 | +process.env.AWS_PROFILE = 'SET YOUR PROFILE HERE'; |
| 3 | + |
| 4 | +var fs = require('fs'), |
| 5 | + path = require('path'), |
| 6 | + gulp = require('gulp'), |
| 7 | + sass = require('gulp-sass'), |
| 8 | + sourcemaps = require('gulp-sourcemaps'), |
| 9 | + autoprefixer = require('gulp-autoprefixer'), |
| 10 | + filter = require('gulp-filter'), |
| 11 | + removeHtmlComments = require('gulp-remove-html-comments'), |
| 12 | + browserSync = require('browser-sync').create(), |
| 13 | + reload = browserSync.reload, |
| 14 | + watch = require('gulp-watch'), |
| 15 | + del = require('del'), |
| 16 | + jshint = require('gulp-jshint'), |
| 17 | + markdown = require('gulp-markdown'), |
| 18 | + wrap = require('gulp-wrap'), |
| 19 | + extender = require('gulp-html-extend'), |
| 20 | + ejs = require('gulp-ejs'), |
| 21 | + //TODO: set your region |
| 22 | + aws_s3 = require('gulp-s3-upload')({ useIAM: true }, { region: '' }), |
| 23 | + slack = require('gulp-slack')({ |
| 24 | + url: '', //from slack interface |
| 25 | + icon_url: 'http://purefishing.scene7.com/is/image/purefishing/1109403', |
| 26 | + user: 'Gulp', |
| 27 | + channel: '' //from your Slack instance |
| 28 | + }), |
| 29 | + username = require('username'), |
| 30 | + user = username.sync(), |
| 31 | + paths = { |
| 32 | + src : { |
| 33 | + base : __dirname + '/src', |
| 34 | + sass : __dirname + '/src/sass', |
| 35 | + js : __dirname + '/src/js', |
| 36 | + images : __dirname + '/src/images', |
| 37 | + vendor : __dirname + '/src/vendor', |
| 38 | + fonts : __dirname + '/src/css/fonts', |
| 39 | + }, |
| 40 | + dist : { |
| 41 | + base : __dirname + '/build', |
| 42 | + css : __dirname + '/build/css', |
| 43 | + js : __dirname + '/build/js', |
| 44 | + images : __dirname + '/build/images', |
| 45 | + vendor : __dirname + '/build/vendor', |
| 46 | + fonts : __dirname + '/build/css/fonts', |
| 47 | + } |
| 48 | + }, |
| 49 | + mdTemplate = '<!-- @@master /_templates/main.html { "title": "Home Page" } -->\n<!-- @@block content -->\n<%= contents %>\n<!-- @@close -->', |
| 50 | + environments = { |
| 51 | + qc: 'qc.prototype.example.support', |
| 52 | + uat: 'uat.prototype.example.support', |
| 53 | + prod: 'example.com' |
| 54 | + }; |
| 55 | + |
| 56 | + |
| 57 | +/***** |
| 58 | +
|
| 59 | +Lifecycle Management |
| 60 | +
|
| 61 | +*****/ |
| 62 | + |
| 63 | +//Clean |
| 64 | + |
| 65 | +gulp.task('clean', function (cb) { |
| 66 | + del([ |
| 67 | + paths.dist.base + '/**', |
| 68 | + '!' + paths.dist.base, |
| 69 | + ], cb); |
| 70 | +}); |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +//Build |
| 76 | + |
| 77 | + |
| 78 | +gulp.task('md', function () { |
| 79 | + return gulp.src([ |
| 80 | + paths.src.base + '/**/*.md', |
| 81 | + '!' + paths.src.base + '/_templates/**', |
| 82 | + '!' + paths.src.base + '/_components/**', |
| 83 | + '!' + paths.src.base + '/html/**/_*.md' |
| 84 | + ]) |
| 85 | + .pipe(markdown()) |
| 86 | + .pipe(wrap(mdTemplate, {}, { parse: false})) |
| 87 | + .pipe(extender({ |
| 88 | + annotations: false, |
| 89 | + verbose: false, |
| 90 | + root: '/src/' |
| 91 | + })) |
| 92 | + .pipe(removeHtmlComments()) |
| 93 | + .pipe(gulp.dest(paths.dist.base)) |
| 94 | + .pipe(reload({stream: true})); |
| 95 | +}); |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +gulp.task('html', function(){ |
| 100 | + return gulp.src([ |
| 101 | + paths.src.base + '/**/*.html', |
| 102 | + '!' + paths.src.base + '/_templates/**', |
| 103 | + '!' + paths.src.base + '/_components/**', |
| 104 | + '!' + paths.src.base + '/html/**/_*.html' |
| 105 | + ]) |
| 106 | + .pipe(extender({ |
| 107 | + annotations: false, |
| 108 | + verbose: false, |
| 109 | + root: '/src/' |
| 110 | + })) |
| 111 | + .pipe(ejs()) |
| 112 | + .pipe(removeHtmlComments()) |
| 113 | + .pipe(gulp.dest(paths.dist.base)) |
| 114 | + .pipe(reload({stream: true})); |
| 115 | +}); |
| 116 | + |
| 117 | +gulp.task('styles', function () { |
| 118 | + return gulp.src(paths.src.sass + '/site.scss') |
| 119 | + .pipe(sourcemaps.init()) // source map init |
| 120 | + .pipe(sass()) // Sass |
| 121 | + .pipe(autoprefixer('last 2 version')) |
| 122 | + .pipe(sourcemaps.write()) // sourcemap write |
| 123 | + .pipe(gulp.dest( paths.dist.css )) // save css file |
| 124 | + .pipe(filter('**/*.css')) // filter only css files (remove the map file) |
| 125 | + .pipe(reload({stream: true})); // inject the changed css |
| 126 | +}); |
| 127 | + |
| 128 | +gulp.task('images', function () { |
| 129 | + return gulp.src(paths.src.images + '/**/*',{ allowEmpty: true }) |
| 130 | + .pipe(gulp.dest(paths.dist.images)); |
| 131 | +}); |
| 132 | + |
| 133 | +gulp.task('js', function () { |
| 134 | + return gulp.src(paths.src.js + '/**/*.js',{ allowEmpty: true }) |
| 135 | + .pipe(jshint(__dirname + '/.jshintrc')) |
| 136 | + .pipe(jshint.reporter('default')) |
| 137 | + .pipe(gulp.dest(paths.dist.js)); |
| 138 | +}); |
| 139 | + |
| 140 | +gulp.task('fonts', function () { |
| 141 | + return gulp.src(paths.src.fonts + '/**/*',{ allowEmpty: true }) |
| 142 | + .pipe(gulp.dest(paths.dist.fonts)); |
| 143 | +}); |
| 144 | + |
| 145 | +gulp.task('vendor', function () { |
| 146 | + return gulp.src(paths.src.vendor + '/**/*',{ allowEmpty: true }) |
| 147 | + .pipe(gulp.dest(paths.dist.vendor)); |
| 148 | +}); |
| 149 | + |
| 150 | +gulp.task('copy', ['images', 'js', 'fonts', 'vendor']); |
| 151 | + |
| 152 | + |
| 153 | +//Develop |
| 154 | + |
| 155 | +gulp.task('bs', function (cb) { |
| 156 | + browserSync.init({ |
| 157 | + server: { |
| 158 | + baseDir: paths.dist.base, |
| 159 | + index: 'index.html' |
| 160 | + }, |
| 161 | + port : 3000, |
| 162 | + open : 'external', |
| 163 | + host : 'localhost', |
| 164 | + notify: { |
| 165 | + styles: [ |
| 166 | + 'display: none;', |
| 167 | + 'padding: 7px 15px;', |
| 168 | + 'border-radius: 0 0 3px 3px;', |
| 169 | + 'position: fixed;', |
| 170 | + 'font-family: Arial, sans-serif', |
| 171 | + 'font-size: 14px;', |
| 172 | + 'font-weight: normal;', |
| 173 | + 'z-index: 9999;', |
| 174 | + 'right: 0px;', |
| 175 | + 'top: 0px;', |
| 176 | + 'background-color: rgba(30, 30, 30, .7);', |
| 177 | + 'color: #fff', |
| 178 | + 'pointer-events: none;' |
| 179 | + ] |
| 180 | + }, |
| 181 | + ghostMode: { |
| 182 | + clicks: true, |
| 183 | + scroll: true, |
| 184 | + forms: { |
| 185 | + submit: true, |
| 186 | + inputs: true, |
| 187 | + toggles: true |
| 188 | + } |
| 189 | + } |
| 190 | + }, function(err, bs) { |
| 191 | + cb() |
| 192 | + }); |
| 193 | +}); |
| 194 | + |
| 195 | +gulp.task('reload', function (cb) { |
| 196 | + reload(); |
| 197 | + cb(); |
| 198 | +}); |
| 199 | + |
| 200 | +gulp.task('watch', function (cb) { |
| 201 | + gulp.watch([paths.src.sass + '/**/*'], ['styles']); |
| 202 | + gulp.watch([paths.src.js + '/**/*'], ['js']); |
| 203 | + gulp.watch([paths.src.images + '/**/*'], ['images']); |
| 204 | + gulp.watch([paths.src.vendor + '/**/*'], ['vendor']); |
| 205 | + gulp.watch([paths.src.base + '/**/*.html'], ['html']); |
| 206 | + cb(); |
| 207 | +}); |
| 208 | + |
| 209 | +gulp.task('build', ['styles', 'copy', 'html', 'md']); |
| 210 | + |
| 211 | +gulp.task('serve', ['bs', 'build']); |
| 212 | + |
| 213 | + |
| 214 | +//Deploy |
| 215 | + |
| 216 | +//Deploy |
| 217 | +gulp.task('deploy-qc', ['build'], function () { |
| 218 | + console.log('Not configured'); |
| 219 | + return 0; |
| 220 | + return gulp.src(paths.dist.base + '/**') |
| 221 | + .pipe(aws_s3({ |
| 222 | + Bucket: environments.qc, |
| 223 | + ACL: 'public-read' |
| 224 | + })) |
| 225 | + .pipe(slack('Deployed to QC environment by ' + user + '.')); |
| 226 | +}); |
| 227 | + |
| 228 | +//TODO: Implement Staging Deploy |
| 229 | +gulp.task('deploy-uat', ['build'], function () { |
| 230 | + console.log('Not configured'); |
| 231 | + return 0; |
| 232 | + return gulp.src(paths.dist.base + '/**') |
| 233 | + .pipe(aws_s3({ |
| 234 | + Bucket: environments.uat, |
| 235 | + ACL: 'public-read' |
| 236 | + })) |
| 237 | + .pipe(slack('Deployed to UAT environment by ' + user + '.')); |
| 238 | +}); |
| 239 | + |
| 240 | +//TODO: Implement Production Deploy |
| 241 | +gulp.task('deploy-prod', ['build'], function () { |
| 242 | + console.log('Not configured'); |
| 243 | + return 0; |
| 244 | + return gulp.src(paths.dist.base + '/**') |
| 245 | + .pipe(aws_s3({ |
| 246 | + Bucket: environments.prod, |
| 247 | + ACL: 'public-read' |
| 248 | + })) |
| 249 | + .pipe(slack('Deployed to PRODUCTION environment by ' + user + '.')); |
| 250 | +}); |
| 251 | + |
| 252 | + |
| 253 | +gulp.task('default', ['serve', 'watch']); |
0 commit comments