150 lines
4.3 KiB
JavaScript
150 lines
4.3 KiB
JavaScript
var gulp = require('gulp');
|
|
var plugins = require('gulp-load-plugins')({});
|
|
var karma = require('karma');
|
|
var es = require('event-stream');
|
|
var mainBowerFiles = require('main-bower-files');
|
|
var exists = require('path-exists').sync
|
|
|
|
var pipes = {};
|
|
|
|
var paths = {
|
|
appFiles: 'webapp/js/**/*.js',
|
|
cssFiles: 'webapp/css/**/*.css',
|
|
partials: 'webapp/js/**/*.html',
|
|
pages : ['webapp/html/**/*.html', '!webapp/html/index.html'],
|
|
index : 'webapp/html/index.html',
|
|
distDev : 'dist/dev',
|
|
distProd: 'dist/prod'
|
|
}
|
|
|
|
|
|
pipes.bowerFiles = function() {
|
|
return gulp.src(mainBowerFiles({
|
|
overrides : {
|
|
jquery : {
|
|
main: []
|
|
},
|
|
bootstrap : {
|
|
main: [
|
|
"dist/**/*.min.css",
|
|
'./dist/fonts/*.*'
|
|
]
|
|
}
|
|
}
|
|
}),{base: 'webapp/bower_components'});
|
|
}
|
|
|
|
pipes.bowerFilesMinified = function() {
|
|
return pipes.bowerFiles()
|
|
.pipe(plugins.rename(function (path) {
|
|
testpath = 'webapp/bower_components/' + path.dirname + '/' + path.basename + '.min' + path.extname;
|
|
if (exists(testpath)) {
|
|
path.extname = '.min' + path.extname;
|
|
}
|
|
}));
|
|
}
|
|
|
|
pipes.validatedAppScripts = function() {
|
|
return gulp.src(paths.appFiles)
|
|
.pipe(plugins.jshint())
|
|
.pipe(plugins.jshint.reporter('jshint-stylish'));
|
|
}
|
|
|
|
pipes.validatedIndex = function() {
|
|
return gulp.src(paths.index)
|
|
.pipe(plugins.htmlhint())
|
|
.pipe(plugins.htmlhint.reporter());
|
|
}
|
|
|
|
pipes.validatedPartials = function() {
|
|
return gulp.src(paths.partials)
|
|
.pipe(plugins.htmlhint({'doctype-first': false}))
|
|
.pipe(plugins.htmlhint.reporter());
|
|
}
|
|
|
|
pipes.validatedPages = function() {
|
|
return gulp.src(paths.pages)
|
|
.pipe(plugins.htmlhint({'doctype-first': false}))
|
|
.pipe(plugins.htmlhint.reporter());
|
|
}
|
|
|
|
pipes.builtIndexDev = function() {
|
|
var vendorFiles = pipes.bowerFilesMinified()
|
|
.pipe(gulp.dest(paths.distDev + '/vendor'));
|
|
var appScript = pipes.validatedAppScripts()
|
|
.pipe(plugins.angularFilesort())
|
|
.pipe(gulp.dest(paths.distDev + '/js'))
|
|
var appStyle = gulp.src(paths.cssFiles)
|
|
.pipe(gulp.dest(paths.distDev + '/css'))
|
|
|
|
var partials = pipes.validatedPartials()
|
|
.pipe(gulp.dest(paths.distDev + '/js'))
|
|
|
|
var pages = pipes.validatedPages()
|
|
.pipe(gulp.dest(paths.distDev + '/html'))
|
|
|
|
return pipes.validatedIndex()
|
|
.pipe(plugins.inject(vendorFiles, {ignorePath: '/'+ paths.distDev, name:'bower'}))
|
|
.pipe(plugins.inject(es.merge(appStyle,partials,pages), {ignorePath: '/'+ paths.distDev}))
|
|
.pipe(plugins.inject(appScript, {ignorePath: '/'+ paths.distDev}))
|
|
.pipe(gulp.dest(paths.distDev));
|
|
}
|
|
|
|
|
|
pipes.builtIndexProd = function() {
|
|
var filterJS = plugins.filter('**/*.js',{restore: true});
|
|
var vendorFiles = pipes.bowerFiles()
|
|
.pipe(filterJS)
|
|
.pipe(plugins.concat('vendor.min.js'))
|
|
.pipe(plugins.uglify())
|
|
.pipe(filterJS.restore)
|
|
.pipe(gulp.dest(paths.distProd + '/vendor'));
|
|
|
|
|
|
|
|
var appScript = pipes.validatedAppScripts()
|
|
.pipe(plugins.angularFilesort())
|
|
.pipe(plugins.ngAnnotate())
|
|
.pipe(plugins.concat('app.min.js'))
|
|
.pipe(plugins.uglify())
|
|
.pipe(gulp.dest(paths.distProd + '/js'));
|
|
|
|
var appStyle = gulp.src(paths.cssFiles)
|
|
.pipe(plugins.minifyCss())
|
|
.pipe(plugins.rename(function (path) {
|
|
path.extname = '.min'+ path.extname;
|
|
}))
|
|
.pipe(gulp.dest(paths.distProd + '/css'))
|
|
|
|
var partials = pipes.validatedPartials()
|
|
.pipe(gulp.dest(paths.distProd + '/js'))
|
|
|
|
var pages = pipes.validatedPages()
|
|
.pipe(gulp.dest(paths.distProd + '/html'))
|
|
|
|
return pipes.validatedIndex()
|
|
.pipe(plugins.inject(vendorFiles, {ignorePath: '/' + paths.distProd, name : 'bower'}))
|
|
.pipe(plugins.inject(es.merge(appStyle,partials,pages), {ignorePath: '/' + paths.distProd}))
|
|
.pipe(plugins.inject(appScript, {ignorePath: '/' + paths.distProd}))
|
|
.pipe(gulp.dest(paths.distProd));
|
|
|
|
}
|
|
|
|
|
|
gulp.task('test', function(done) {
|
|
server = new karma.Server({
|
|
configFile: __dirname + '/test/karma.conf.js'
|
|
},function(exitCode) {
|
|
console.log('coucou');
|
|
done(exitCode);
|
|
console.log('coucou');
|
|
process.exit(exitCode);
|
|
});
|
|
server.start();
|
|
});
|
|
|
|
|
|
gulp.task('build-dev', pipes.builtIndexDev);
|
|
|
|
gulp.task('build-prod', pipes.builtIndexProd);
|