Skip to content

Commit

Permalink
Merge pull request #402 from andig/build-infra
Browse files Browse the repository at this point in the history
Upgraded build infrastructure
  • Loading branch information
andig committed Feb 14, 2016
2 parents 2bd0ad4 + 32f4f24 commit f3e95d0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 70 deletions.
142 changes: 74 additions & 68 deletions gulpfile.js
@@ -1,20 +1,8 @@
// include plug-ins
var gulp = require('gulp');

var del = require('del');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var size = require('gulp-size');
var replace = require('gulp-replace');
var watch = require('gulp-watch');

var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');

var spritesmith = require("gulp.spritesmith");
var imagemin = require('gulp-imagemin');
var uncss = require('gulp-uncss');
var minifyCSS = require('gulp-minify-css');
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'watch', 'del'],
});

// settings
var base = './htdocs/frontend/';
Expand All @@ -31,20 +19,28 @@ var vendor = base + 'vendor/';
var javascripts = base + 'javascripts/';
var flot = base + 'vendor/flot/';
var extensions = base + 'javascripts/jquery/';
var jsfiles = [
'gulpfile.js',
base + 'javascripts/**/*.js',
'!' + base + 'javascripts/canvas/**/*.js',
'!' + base + 'javascripts/jquery/**/*.js',
'!**/*.min.js'
];

/**
* Defaults
*/
gulp.task('default', function() {
// watch for JS changes
gulp.src([
base + 'javascripts/**/*.js',
'!**/*.min.js', // omit minified files
], { read: false })
.pipe(watch())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
gulp.task('default', ['jshint', 'watch']);


/**
* Watch javascripts
*/
gulp.task('watch', function() {
gulp.src(jsfiles)
.pipe($.watch(jsfiles))
.pipe($.jshint())
.pipe($.jshint.reporter('default'));
});


Expand All @@ -54,20 +50,16 @@ gulp.task('default', function() {
gulp.task('build', ['clean', 'jshint', 'scripts', 'sprites']);

gulp.task('clean', function () {
del([
$.del([
build + '**'
]);
});


gulp.task('jshint', function() {
gulp.src([
base + 'javascripts/*.js',
'!**/*.min.js', // omit minified files
])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
gulp.src(jsfiles)
.pipe($.jshint())
.pipe($.jshint.reporter('default'))
.pipe($.jshint.reporter('fail'));
});


Expand All @@ -86,13 +78,13 @@ gulp.task('vz-scripts', function() {
javascripts + 'entity.js',
'!**/options.js', // exclude options
])
.pipe(concat('scripts.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe(size({showFiles: true}))
.pipe(uglify())
.pipe(rename('scripts.min.js'))
.pipe(gulp.dest(javascripts))
.pipe(size({showFiles: true}))
.pipe($.concat('scripts.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe($.size({showFiles: true}))
.pipe($.uglify())
.pipe($.rename('scripts.min.js'))
.pipe(gulp.dest(javascripts))
.pipe($.size({showFiles: true}));
});

gulp.task('flot', function() {
Expand All @@ -111,60 +103,56 @@ gulp.task('flot', function() {
'!**/excanvas*.js', // omit canvas helper
'!**/*.min.js', // omit minified files
])
.pipe(concat('flot.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe(size({showFiles: true}))
.pipe(uglify())
.pipe(rename('flot.min.js'))
.pipe(gulp.dest(flot))
.pipe(size({showFiles: true}))
.pipe($.concat('flot.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe($.size({showFiles: true}))
.pipe($.uglify())
.pipe($.rename('flot.min.js'))
.pipe(gulp.dest(flot))
.pipe($.size({showFiles: true}));
});

gulp.task('jquery-ext', function() {
return gulp.src([
extensions + '**.js',
'!**/*.min.js', // omit minified files
])
.pipe(concat('jquery-ext.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe(size({showFiles: true}))
.pipe(uglify())
.pipe(rename('jquery-ext.min.js'))
.pipe(gulp.dest(extensions))
.pipe(size({showFiles: true}))
.pipe($.concat('jquery-ext.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe($.size({showFiles: true}))
.pipe($.uglify())
.pipe($.rename('jquery-ext.min.js'))
.pipe(gulp.dest(extensions))
.pipe($.size({showFiles: true}));
});


/**
* Sprites
*/
gulp.task('sprites', ['sprites-combine', 'sprites-optimize']);

// Combine images into sprite
gulp.task('sprites-combine', function () {
gulp.task('sprites', function () {
// Combine images into sprite
var spriteData = gulp.src([
images + '!(sprites|blank|ui-|style_|empty)*.png',
images + 'types/*!(32).png'
])
.pipe(spritesmith({
.pipe($.spritesmith({
imgName: '../images/sprites.png', // link to images folder
cssName: 'sprites.css',
algorithm: 'top-down'
algorithm: 'top-down',
padding: 2
}));

spriteData.img
.pipe(imagemin())
.pipe($.imagemin())
.pipe(gulp.dest(images));

spriteData.css
.pipe(gulp.dest(build));
});

// Rewrite sprites.css
gulp.task('sprites-optimize', function () {
// remove dimensions and save as new css file
gulp.src(build + 'sprites.css')
.pipe(replace(/ width: 16px;\n height: 16px;\n/g, ''))
.pipe($.replace(/ width: 16px;\n height: 16px;\n/g, ''))
.pipe(gulp.dest(styles));
});

Expand All @@ -175,9 +163,27 @@ gulp.task('sprites-optimize', function () {
// not used
gulp.task('css-minimize', function () {
gulp.src(styles + '*.css')
.pipe(concat('styles.css'))
.pipe($.concat('styles.css'))
.pipe(gulp.dest(build))
.pipe($.cssnano({
keepBreaks:true
}))
.pipe($.rename('styles.min.css'))
.pipe(gulp.dest(build));
});

// not used
gulp.task('css-strip', function() {
gulp.src(styles + '*.css')
// gulp.src(build + 'styles.min.css')
.pipe($.uncss({
html: [base + 'index.html']
}))
// .pipe($.rename('styles.min.css'))
.pipe(gulp.dest(build))
.pipe(minifyCSS({keepBreaks:true}))
.pipe(cssnano({
keepBreaks:true
}))
.pipe(rename('styles.min.css'))
.pipe(gulp.dest(build));
});
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -15,10 +15,11 @@
"del": "^1.1.1",
"gulp": "^3.8.10",
"gulp-concat": "^2.4.3",
"gulp-cssnano": "^2.1.1",
"gulp-htmlmin": "^1.3.0",
"gulp-imagemin": "^2.1.0",
"gulp-jshint": "^1.9.0",
"gulp-minify-css": "^0.3.11",
"gulp-minify-html": "^0.1.8",
"gulp-load-plugins": "^1.2.0",
"gulp-rename": "^1.2.0",
"gulp-replace": "^0.5.0",
"gulp-size": "^1.1.0",
Expand Down

0 comments on commit f3e95d0

Please sign in to comment.