Created
August 1, 2014 03:39
-
-
Save brendanmckenzie/2a323e3c6f12e5161538 to your computer and use it in GitHub Desktop.
This file contains 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'), | |
plugins = require('gulp-load-plugins')({lazy:false}), | |
less = require('gulp-less'), | |
path = require('path'), | |
historyApiFallback = require('connect-history-api-fallback'), | |
inject = require('gulp-inject') | |
mainBowerFiles = require('main-bower-files') | |
jshint = require('gulp-jshint'); | |
gulp.task('scripts-dist', ['copy-index-dist'], function() { | |
var script_files = ['!./app/**/*_test.js','./app/**/*.js']; | |
//combine all js files of the app | |
gulp.src(script_files) | |
.pipe(plugins.jshint()) | |
.pipe(plugins.jshint.reporter('default')) | |
.pipe(plugins.concat('app.js')) | |
.pipe(gulp.dest('./dist')); | |
var target = gulp.src('./dist/index.html'); | |
// It's not necessary to read the files (will speed up things), we're only after their paths: | |
var sources = gulp.src(['./dist/app.js'], {read: false}); | |
return target.pipe(inject(sources)).pipe(gulp.dest('./dist')); | |
}); | |
gulp.task('jshint', function () { | |
var script_files = ['!./app/**/*_test.js','./app/**/*.js']; | |
return gulp.src(script_files) | |
.pipe(jshint('.jshintrc')) | |
.pipe(jshint.reporter('default')); | |
}); | |
gulp.task('scripts', ['jshint', 'copy-index'], function() { | |
var script_files = ['!./app/**/*_test.js','./app/**/*.js']; | |
gulp.src(script_files) | |
.pipe(gulp.dest('./.tmp/app')); | |
var target = gulp.src('./.tmp/index.html'); | |
// It's not necessary to read the files (will speed up things), we're only after their paths: | |
var sources = gulp.src(script_files, {read: false}); | |
return target.pipe(inject(sources)).pipe(gulp.dest('./.tmp')); | |
}); | |
gulp.task('templates',function(){ | |
//combine all template files of the app into a js file | |
gulp.src(['!./app/index.html', | |
'./app/**/*.html']) | |
.pipe(plugins.angularTemplatecache('templates.js',{standalone:true})) | |
.pipe(gulp.dest('./.tmp')); | |
}); | |
gulp.task('styles', function () { | |
gulp.src(['!./app/styles/**/_*.less', './app/styles/**/*.less']) | |
.pipe(less({ paths: [ path.join(__dirname, 'less', 'includes'), path.join(__dirname, 'bower_components', 'bootstrap', 'less') ] })) | |
.pipe(gulp.dest('./.tmp')); | |
}); | |
gulp.task('vendorJS', function(){ | |
//concatenate vendor JS files | |
var files = mainBowerFiles() | |
.filter(function (f) { var ext = f.substr(f.length - 3); return ext == '.js'; }); | |
gulp.src(files) | |
.pipe(plugins.concat('lib.js')) | |
.pipe(gulp.dest('./.tmp')); | |
}); | |
gulp.task('fonts', function () { | |
gulp.src(['./app/fonts/**']) | |
.pipe(gulp.dest('./.tmp/fonts')); | |
}); | |
gulp.task('fonts-dist', function () { | |
gulp.src(['./app/fonts/**']) | |
.pipe(gulp.dest('./dist/fonts')); | |
}); | |
gulp.task('copy-index', function() { | |
return gulp.src('./app/index.html') | |
.pipe(gulp.dest('./.tmp')); | |
}); | |
gulp.task('copy-index-dist', function() { | |
gulp.src('./app/index.html') | |
.pipe(gulp.dest('./dist')); | |
}); | |
gulp.task('watch',function(){ | |
gulp.watch([ | |
'.tmp/**/*.html', | |
'.tmp/**/*.js', | |
'.tmp/**/*.css' | |
], function(event) { | |
return gulp.src(event.path) | |
.pipe(plugins.connect.reload()); | |
}); | |
gulp.watch(['./app/**/*.js','!./app/**/*test.js'],['scripts', 'copy-index']); | |
gulp.watch(['./bower_components/**/*.js','!./app/**/*test.js'],['vendorJS']); | |
gulp.watch(['!./app/index.html','./app/**/*.html'],['templates']); | |
gulp.watch('./app/**/*.less',['styles']); | |
gulp.watch('./app/index.html',['scripts', 'copy-index']); | |
}); | |
gulp.task('connect', plugins.connect.server({ | |
root: ['.tmp'], | |
port: 8080, | |
livereload: true, | |
middleware: function(connect, opt) { | |
return [ historyApiFallback ]; | |
} | |
})); | |
gulp.task('default',['connect','scripts','templates','styles','fonts','copy-index','vendorJS','watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment