Created
February 17, 2015 02:20
-
-
Save mnbbrown/9efa024f89dfb09e1081 to your computer and use it in GitHub Desktop.
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
var gulp = require('gulp'); | |
var concat = require('gulp-concat'); | |
var sass = require('gulp-sass'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var minifyCSS = require('gulp-minify-css'); | |
var minifyHTML = require('gulp-minify-html'); | |
var uglify = require('gulp-uglify'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var jshint = require('gulp-jshint'); | |
var jscs = require('gulp-jscs'); | |
var symlink = require('gulp-sym'); | |
var karma = require('gulp-karma'); | |
var connect = require('gulp-connect'); | |
var ngAnnotate = require('gulp-ng-annotate'); | |
var htmlify = require('gulp-angular-htmlify'); | |
var minifyHTML = require('gulp-minify-html'); | |
var htmlreplace = require('gulp-html-replace'); | |
var templateCache = require('gulp-angular-templatecache'); | |
var clean = require('gulp-clean'); | |
var size = require('gulp-size'); | |
var vendorLibs = [ | |
'bower_components/zepto/zepto.min.js', | |
'bower_components/angular/angular.min.js', | |
'bower_components/angular-ui-router/release/angular-ui-router.min.js', | |
'bower_components/angular-local-storage/dist/angular-local-storage.min.js' | |
]; | |
gulp.task('serve', function() { | |
connect.server({ | |
livereload: true, | |
root: './build/', | |
}); | |
}); | |
gulp.task('js-app', function() { | |
gulp.src(['js/**/*.js', '!js/**/*.spec.js']) | |
.pipe(sourcemaps.init()) | |
.pipe(ngAnnotate()) | |
.pipe(concat('app.min.js')) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('build/')); | |
}); | |
gulp.task('js-vendor', function() { | |
gulp.src(vendorLibs) | |
.pipe(sourcemaps.init()) | |
.pipe(concat('vendor.min.js')) | |
.pipe(uglify({compress: false})) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('./build/')) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('js', ['js-app', 'js-vendor']); | |
gulp.task('html-index', function() { | |
gulp.src('index.html') | |
.pipe(htmlreplace({ | |
'app' : ['app.min.js', 'templates.min.js'], | |
'vendor' : ['vendor.min.js'], | |
})) | |
.pipe(htmlify()) | |
.pipe(minifyHTML({comments: true, spare: true, quotes: true})) | |
.pipe(gulp.dest('./build/')) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('sass', function() { | |
return gulp.src('scss/*.scss') | |
.pipe(sass({ | |
expanded: true, | |
onError: function(e) { | |
console.log(e); | |
} | |
})) | |
.pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8')) | |
.pipe(sourcemaps.init()) | |
.pipe(concat('style.css')) | |
.pipe(minifyCSS()) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('build/')) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('html-templates', function() { | |
return gulp.src(['js/**/*.view.html']) | |
.pipe(htmlify()) | |
.pipe(minifyHTML({comments: true, spare: true, quotes: true})) | |
.pipe(templateCache('templates.min.js', { | |
module: 'app' | |
})) | |
.pipe(gulp.dest('build/')) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('unit-test', function() { | |
return gulp.src('.foobar') | |
.pipe(karma({ | |
configFile: 'karma.conf.js', | |
action: 'run', | |
})) | |
.on('error', function(err) { | |
console.log(err); | |
this.emit('end'); | |
}); | |
}); | |
gulp.task('lint', function() { | |
return gulp.src([ | |
'**/*.js', '!**/*.min.js', '!node_modules/**', | |
'!bower_components/**', '!build/**', | |
]) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('jshint-stylish')) | |
.pipe(jscs({ | |
'preset': 'google' | |
})); | |
}); | |
gulp.task('setup-githooks', function() { | |
return gulp.src(['.githooks/pre-commit', '.githooks/post-merge']) | |
.pipe(symlink(['.git/hooks/pre-commit', '.git/hooks/post-merge'], { | |
force: true | |
})); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('scss/*.scss', ['sass']); | |
gulp.watch('js/**/*.js', ['lint', 'js-app']); | |
gulp.watch('index.html', ['html-index']); | |
gulp.watch('js/**/*.view.html', ['html-templates']); | |
}); | |
gulp.task('clean', function() { | |
return gulp.src('./build', {read: false}) | |
.pipe(clean()); | |
}); | |
gulp.task('size', function() { | |
return gulp.src(['./build/**/*', '!./build/**/*.map']) | |
.pipe(size({showFiles: true})); | |
}); | |
gulp.task('compile', [ | |
'js-app', | |
'js-vendor', | |
'html-templates', | |
'html-index', | |
'sass' | |
]); | |
gulp.task('test', ['lint', 'unit-test']); | |
gulp.task('default', ['clean', 'compile', 'serve', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment