Skip to content

Instantly share code, notes, and snippets.

@totya24
Created October 9, 2014 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totya24/a9cd4944bf88ef9274e0 to your computer and use it in GitHub Desktop.
Save totya24/a9cd4944bf88ef9274e0 to your computer and use it in GitHub Desktop.
My gulpfile
var gulp = require('gulp');
var csslint = require('gulp-csslint');
var gutil = require('gulp-util');
var csscomb = require('gulp-csscomb');
var prefixer = require('gulp-autoprefixer');
var gettext = require('gulp-angular-gettext');
var pngcrush = require('imagemin-pngcrush');
var plato = require('gulp-plato');
var jshint = require('gulp-jshint');
var check = require('gulp-check');
var imagemin = require('gulp-imagemin');
var changed = require('gulp-changed');
var stripDebug = require('gulp-strip-debug');
var watch = require('gulp-watch');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
// this is for gulp chrome extension
module.exports = gulp;
// custom reporter for csshint
var customReporter = function(file) {
gutil.log(gutil.colors.cyan(file.csslint.errorCount)+' errors in '+gutil.colors.magenta(file.path));
file.csslint.results.forEach(function(result) {
gutil.log(result.error.message+gutil.colors.green(' on line '+result.error.line));
});
};
// analyze css
gulp.task('csshint', function() {
gulp.src('webapp/css/main.css')
.pipe(csslint())
.pipe(csslint.reporter(customReporter));
});
// process csscomb and prexixing to main css file
gulp.task('cssprocess', function () {
return gulp.src('webapp/shared/css/styles.css')
.pipe(prefixer([
'Android 2.3',
'Android >= 4',
'Chrome >= 20',
'Firefox >= 24',
'Explorer >= 8',
'iOS >= 6',
'Opera >= 12',
'Safari >= 6']))
.pipe(csscomb())
.pipe(gulp.dest('./build/css'));
});
// js analyzer - see reports/index.html after run
gulp.task('plato', function () {
return gulp.src(['webapp/**/*.js','!./webapp/shared/**'])
.pipe(plato('report', {
jshint: {
options: {
strict: true
}
},
complexity: {
trycatch: true
}
}));
});
// js lint
gulp.task('jslint', function() {
return gulp.src(['./webapp/**/*.js','!./webapp/shared/**'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
// angular gettex - collect strings for translate
gulp.task('pot', function () {
return gulp.src(['webapp/views/*.html', 'webapp/**/*.js', '!./webapp/shared/**'])
.pipe(gettext.extract('template.pot', {}))
.pipe(gulp.dest('po/'));
});
// angular gettext - compile po files to json
gulp.task('translations', function () {
return gulp.src('po/**/*.po')
.pipe(gettext.compile({format: 'json'}))
.pipe(gulp.dest('webapp/locale/'));
});
// remove debug functions from js(console functions)
gulp.task('stripdebug', function () {
return gulp.src(['./webapp/**/*.js','!./webapp/shared/**'])
.pipe(stripDebug())
.pipe(gulp.dest('./webapp'));
});
// minify images
gulp.task('imagemin', function () {
return gulp.src('webapp/shared/img/*')
.pipe(changed('build/img'))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngcrush()]
}))
.pipe(gulp.dest('build/img'));
});
// search "TODO" comments in all own js file
gulp.task('todo', function () {
gulp.src(['./webapp/**/*.js','!./webapp/shared/**'])
.pipe(check(/TODO/))
.on('error', function (err) {
gutil.beep();
gutil.log(gutil.colors.red(err));
});
});
var vendorscripts = [
'webapp/shared/vendor/angular.min.js',
'webapp/shared/vendor/angular-touch.js',
'webapp/shared/vendor/angular-resource.js',
'webapp/shared/vendor/angular-route.js',
'webapp/shared/vendor/angular-gettext.js',
'webapp/shared/vendor/ng-mobile-menu.min.js',
'webapp/shared/vendor/jquery-2.1.1.min.js',
'webapp/shared/vendor/underscore.min.js'
];
gulp.task('vendor', function() {
gulp.src(vendorscripts)
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(gulp.dest('./webapp/shared/vendor'))
});
// default task, who list all the avaiable tasks
gulp.task('default', function() {
gutil.log(gutil.colors.yellow("ConfCat Webapp futtatható taskok listája"));
gutil.log(gutil.colors.yellow("----------------------------------------"));
gutil.log(gutil.colors.green("csshint")+"\t\tCSS kódminőség ellenőrzés");
gutil.log(gutil.colors.green("cssprocess")+"\t\tCSS prefix és csscomb (build/css)");
gutil.log(gutil.colors.green("plato")+"\t\tPLATO - js stat generator");
gutil.log(gutil.colors.green("jslint")+"\t\tJSLint - kódminőség ellenpőrzés");
gutil.log(gutil.colors.green("vendor")+"\t\tÖsszefűz és tömörít minden vendor scriptet");
gutil.log(gutil.colors.green("pot")+"\t\t\tAngular gettext - collect");
gutil.log(gutil.colors.green("translations")+"\t\tAngular gettext fordító po fájlból");
gutil.log(gutil.colors.green("stripdebug")+"\t\tKiszedi a console metódusokat");
gutil.log(gutil.colors.green("imagemin")+"\t\tImage Minify (build/img)");
gutil.log(gutil.colors.green("todo")+"\t\t\tEllenőrzi, maradt-e TODO a js fájlokban");
gutil.log(gutil.colors.green("watch")+"\t\tJs fájlok változását figyeli (haszontalan)");
});
// sample watch task
gulp.task('watch', function () {
watch('./webapp/*.js', function (files) {
gutil.log(gutil.colors.red("változás történt"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment