Created
January 26, 2015 19:46
-
-
Save dwelch2344/850dbc043cdf0c51b07b 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
'use strict'; | |
var gulp = require('gulp'), | |
prefix = require('gulp-autoprefixer'), | |
minifyCss = require('gulp-minify-css'), | |
usemin = require('gulp-usemin'), | |
uglify = require('gulp-uglify'), | |
compass = require('gulp-compass'), | |
minifyHtml = require('gulp-minify-html'), | |
livereload = require('gulp-livereload'), | |
imagemin = require('gulp-imagemin'), | |
ngAnnotate = require('gulp-ng-annotate'), | |
jshint = require('gulp-jshint'), | |
rev = require('gulp-rev'), | |
connect = require('gulp-connect'), | |
proxy = require('proxy-middleware'), | |
es = require('event-stream'), | |
flatten = require('gulp-flatten'), | |
clean = require('gulp-clean'), | |
replace = require('gulp-replace'), | |
browserify = require('gulp-browserify'), | |
debug = require('gulp-debug'), | |
flatten = require('gulp-flatten'), | |
rename = require('gulp-rename') | |
; | |
var karma = require('gulp-karma')({configFile: 'src/test/javascript/karma.conf.js'}); | |
function prefixDir(prefix){ | |
return rename(function(path){ | |
path.dirname = prefix + path.dirname; | |
}); | |
} | |
var yeoman = { | |
app: 'src/main/webapp/',//require('./bower.json').appPath || 'app', | |
assets: 'src/main/webapp/WEB-INF/client/', | |
dist: 'src/main/webapp/WEB-INF/dist/', | |
test: 'src/test/javascript/spec/', | |
tmp: '.tmp/', | |
scss: 'src/main/scss/' | |
} | |
gulp.task('clean', function(){ | |
return gulp.src(yeoman.dist, {read: false}). | |
pipe(clean()); | |
}); | |
gulp.task('clean:tmp', function(){ | |
return gulp.src(yeoman.tmp, {read: false}). | |
pipe(clean()); | |
}); | |
gulp.task('test', function(){ | |
karma.once(); | |
}); | |
gulp.task('copy', ['clean'], function(){ | |
return es.merge(gulp.src(yeoman.assets + 'i18n/**'). | |
pipe(gulp.dest(yeoman.dist + 'i18n/')), | |
gulp.src(yeoman.assets + '**/*.{woff,svg,ttf,eot}'). | |
pipe(flatten()). | |
pipe(gulp.dest(yeoman.dist + 'static/fonts/'))); | |
}); | |
gulp.task('images', function(){ | |
return gulp.src(yeoman.assets + 'images/**'). | |
pipe(imagemin({optimizationLevel: 5})). | |
pipe(gulp.dest(yeoman.dist + 'static/images')); | |
}); | |
gulp.task('compass2', function() { | |
return gulp.src(yeoman.scss + '{,*/}*.scss'). | |
pipe(compass({ | |
project: __dirname, | |
sass: 'src/main/scss', | |
css: 'src/main/webapp/styles', | |
generated_images: '.tmp/images/generated', | |
image: 'src/main/webapp/images', | |
javascript: 'src/main/webapp/scripts', | |
font: 'src/main/webapp/styles/fonts', | |
import_path: 'src/main/webapp/bower_components', | |
relative: false | |
})). | |
pipe(gulp.dest(yeoman.tmp + 'styles')); | |
}); | |
gulp.task('compass', function() { | |
return gulp.src(yeoman.scss + '{,*/}*.scss'). | |
pipe(compass({ | |
project: __dirname, | |
sass: 'src/main/scss', | |
css: yeoman.tmp + 'css', | |
generated_images: '.tmp/images/generated', | |
image: 'src/main/webapp/WEB-INF/client/images', | |
javascript: 'src/main/webapp/WEB-INF/client/js', | |
font: 'src/main/webapp/WEB-INF/client/fonts', | |
import_path: 'src/main/webapp/WEB-INF/client/bower_components', | |
relative: false | |
})). | |
pipe(gulp.dest(yeoman.tmp + 'styles')); | |
}); | |
// | |
//gulp.task('compass', function() { | |
// return gulp.src(yeoman.scss + '{,*/}*.scss'). | |
// pipe(compass({ | |
// project: __dirname, | |
// sass: 'src/main/webapp/WEB-INF/client/scss', | |
// css: 'src/main/webapp/WEB-INF/client/css', | |
// generated_images: '.tmp/images/generated', | |
// image: 'src/main/webapp/WEB-INF/client/images', | |
// javascript: 'src/main/webapp/WEB-INF/client/js', | |
// font: 'src/main/webapp/WEB-INF/client/fonts', | |
// import_path: 'src/main/webapp/WEB-INF/client/bower_components', | |
// relative: false | |
// })). | |
// pipe(gulp.dest(yeoman.tmp + 'styles')); | |
//}); | |
gulp.task('styles', [ 'compass'], function() { | |
return gulp.src(yeoman.assets + '{,*/}*.css'). | |
pipe(gulp.dest(yeoman.tmp)); | |
}); | |
gulp.task('build', ['clean', 'copy'], function() { | |
gulp.run('usemin'); | |
}); | |
gulp.task('usemin', ['images', 'styles'], function(){ | |
return gulp.src(yeoman.app + 'WEB-INF/views/{,*/}**.html'). | |
pipe(usemin({ | |
path: 'src/main/webapp', | |
css: [ | |
prefix.apply(), | |
replace(/[0-9a-zA-Z\-_\s\.\/]*\/([a-zA-Z\-_\.0-9]*\.(woff|eot|ttf|svg))/g, '/fonts/$1'), | |
//minifyCss(), | |
'concat', | |
rev() | |
, prefixDir("static/") | |
], | |
html: [ | |
prefixDir("views/") | |
//, minifyHtml({empty: true, conditionals:true}) | |
], | |
js: [ | |
ngAnnotate(), | |
uglify(), | |
'concat', | |
rev() | |
// , prefixDir("static/") | |
] | |
})). | |
pipe(gulp.dest(yeoman.dist)); | |
}); | |
gulp.task('default', function() { | |
gulp.run('test'); | |
gulp.run('build'); | |
}); | |
gulp.task('server', ['watch', 'compass'], function() { | |
connect.server( | |
{ | |
root: [yeoman.app, yeoman.tmp], | |
port: 9000, | |
livereload: true, | |
middleware: function(connect, o) { | |
return [ | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/app'); | |
options.route = '/app'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/oauth'); | |
options.route = '/oauth'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/api-docs'); | |
options.route = '/api-docs'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/metrics'); | |
options.route = '/metrics'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/dump'); | |
options.route = '/dump'; | |
return proxy(options); | |
})() | |
]; | |
} | |
} | |
); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(yeoman.app + 'scripts/**', ['browserify']); | |
gulp.watch(yeoman.scss, ['compass']); | |
gulp.watch('src/images/**', ['images']); | |
livereload(); | |
}); | |
gulp.task('server:dist', ['build'], function() { | |
connect.server( | |
{ | |
root: [yeoman.dist], | |
port: 9000, | |
//livereload: true, | |
middleware: function(connect, o) { | |
return [ | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/app'); | |
options.route = '/app'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/metrics'); | |
options.route = '/metrics'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/dump'); | |
options.route = '/dump'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/api-docs'); | |
options.route = '/api-docs'; | |
return proxy(options); | |
})(), | |
(function() { | |
var url = require('url'); | |
var proxy = require('proxy-middleware'); | |
var options = url.parse('http://localhost:8080/oauth/token'); | |
options.route = '/oauth/token'; | |
return proxy(options); | |
})() | |
]; | |
} | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment