Created
April 3, 2015 19:57
-
-
Save iCodeForBananas/64304f64549fa5d9b4ea to your computer and use it in GitHub Desktop.
Gulpfile for serpprogress.com
This file contains hidden or 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
| 'use strict'; | |
| var gulp = require('gulp'); | |
| var open = require('open'); | |
| var watch = require('gulp-watch'); | |
| var plumber = require('gulp-plumber'); | |
| var nodemon = require('nodemon'); | |
| var livereload = require('gulp-livereload'); | |
| var htmlmin = require('gulp-htmlmin'); | |
| var concat = require('gulp-concat'); | |
| var uglify = require('gulp-uglify'); | |
| var ngtemplate = require('gulp-ngtemplate'); | |
| var ngAnnotate = require('gulp-ng-annotate'); | |
| var del = require('del'); | |
| var rename = require('gulp-rename'); | |
| var sourcemaps = require('gulp-sourcemaps'); | |
| var sass = require('gulp-ruby-sass'); | |
| var sourcemaps = require('gulp-sourcemaps'); | |
| var imagemin = require('gulp-imagemin'); | |
| var jshint = require('gulp-jshint'); | |
| var stylish = require('jshint-stylish'); | |
| var git = require('gulp-git'); | |
| var runSequence = require('run-sequence'); | |
| // Scripts | |
| gulp.task('scripts', function() { | |
| return gulp.src('.tmp/scripts/**/*.js') | |
| .pipe(sourcemaps.init()) | |
| .pipe(concat('app.js')) | |
| .pipe(uglify()) | |
| .pipe(sourcemaps.write('./')) | |
| .pipe(gulp.dest('public/dist')) | |
| .pipe(livereload()); | |
| }); | |
| gulp.task('vendor', function() { | |
| return gulp.src([ | |
| 'public/bower_components/jquery/dist/jquery.js', | |
| 'public/scripts/highstock.src.js', | |
| 'public/bower_components/moment/moment.js', | |
| 'public/bower_components/bootstrap/dist/js/bootstrap.js', | |
| 'public/bower_components/angular/angular.js', | |
| 'public/bower_components/angular-cookies/angular-cookies.js', | |
| 'public/bower_components/angular-bootstrap/ui-bootstrap-tpls.js', | |
| 'public/bower_components/lodash/dist/lodash.compat.js', | |
| 'public/bower_components/angular-ui-router/release/angular-ui-router.js', | |
| 'public/bower_components/angular-loading-bar/build/loading-bar.min.js', | |
| 'public/bower_components/highcharts-ng/dist/highcharts-ng.min.js' | |
| ]) | |
| .pipe(concat('vendor.js')) | |
| .pipe(uglify()) | |
| .pipe(sourcemaps.write('./')) | |
| .pipe(gulp.dest('public/dist')) | |
| .pipe(livereload()); | |
| }); | |
| // Annotate angular files for uglification | |
| gulp.task('annotate', function() { | |
| return gulp.src('assets/scripts/**/*.js') | |
| .pipe(plumber()) | |
| .pipe(ngAnnotate()) | |
| .pipe(gulp.dest('.tmp/scripts')); | |
| }); | |
| // HTML | |
| gulp.task('html', function() { | |
| return gulp.src('assets/scripts/**/*.html') | |
| .pipe(plumber()) | |
| .pipe(htmlmin({ | |
| collapseWhitespace: true | |
| })) | |
| .pipe(ngtemplate({ | |
| module: 'serpProgress' | |
| })) | |
| .pipe(rename(function (path) { | |
| path.basename += '.html'; | |
| })) | |
| .pipe(gulp.dest('.tmp/scripts')); | |
| }); | |
| // Linting | |
| gulp.task('jshint', function() { | |
| return gulp.src([ | |
| 'assets/scripts/**/*.js' | |
| ]) | |
| .pipe(plumber()) | |
| .pipe(jshint()) | |
| .pipe(jshint.reporter(stylish)); | |
| }); | |
| // Clean | |
| gulp.task('clean', function () { | |
| return del('.tmp/**/*.*'); | |
| }); | |
| // Optimize asset images | |
| gulp.task('optimize', function() { | |
| return gulp.src('assets/**/*.{gif,jpg,png,svg}') | |
| .pipe(plumber()) | |
| .pipe(imagemin({ | |
| progressive: true, | |
| svgoPlugins: [{removeViewBox: false}], | |
| // png optimization | |
| optimizationLevel: 3 | |
| })) | |
| .pipe(gulp.dest('public/images/')); | |
| }); | |
| // Sass | |
| gulp.task('sass', function() { | |
| return gulp.src('assets/styles/**/main.scss') | |
| .pipe(plumber()) | |
| .pipe(sass({ | |
| compass: true, | |
| trace: true | |
| })) | |
| .pipe(gulp.dest('public/styles')) | |
| .pipe(livereload()); | |
| }); | |
| // Deploy to heroku | |
| gulp.task('deploy', function(){ | |
| return git.push('heroku', 'master', function (err) { | |
| if (err) { throw err; } | |
| }); | |
| }); | |
| // Start server | |
| gulp.task('nodemon', function () { | |
| return nodemon({ | |
| script: './bin/www', | |
| ext: 'jade js', | |
| watch: [ | |
| 'bin/**/*.*', | |
| 'config/**/*.*', | |
| 'controllers/**/*.*', | |
| 'lib/**/*.*', | |
| 'models/**/*.*', | |
| 'views/**/*.*', | |
| 'app.js', | |
| 'routes.js' | |
| ] | |
| }) | |
| .on('log', function (event) { | |
| console.log(event.colour); | |
| }) | |
| // opens browser on initial server start | |
| .on('config:update', function () { | |
| setTimeout(function () { | |
| open('http://localhost:3000'); | |
| }, 500); | |
| }); | |
| }); | |
| // Build | |
| gulp.task('build', function() { | |
| return runSequence('jshint', 'html', 'annotate', 'scripts', 'clean'); | |
| }); | |
| // Watch | |
| gulp.task('default', ['nodemon'], function() { | |
| livereload.listen(); | |
| watch('./assets/scripts/**', function() { | |
| gulp.start('build'); | |
| }); | |
| watch('./assets/styles/**', function() { | |
| gulp.start('sass'); | |
| }); | |
| watch('./views/**', function(file) { | |
| setTimeout(function() { | |
| livereload.changed(file.path); | |
| }, 500); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment