Skip to content

Instantly share code, notes, and snippets.

@anissen
Last active January 25, 2024 23:58
Show Gist options
  • Save anissen/8274074 to your computer and use it in GitHub Desktop.
Save anissen/8274074 to your computer and use it in GitHub Desktop.
Example gulpfile for some useful tasks
{
"requireCurlyBraces": ["else", "for", "while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireRightStickedOperators": ["!"],
"requireLeftStickedOperators": [","],
"disallowImplicitTypeConversion": ["string"],
"disallowKeywords": ["with"],
"disallowMultipleLineBreaks": true,
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"requireParenthesesAroundIIFE": true,
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowMultipleVarDecl": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowSpaceAfterObjectKeys": true,
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
}
}
var gulp = require('gulp');
var sources = ['*.js', 'lib/**/*.js', '!gulpfile.js'];
var testSources = ['test/*.js'];
var allSources = sources.concat(testSources);
var dist = './dist/';
gulp.task('lint', function() {
var jshint = require('gulp-jshint');
var jshintStylish = require('jshint-stylish');
gulp.src(sources)
.pipe(jshint())
.pipe(jshint.reporter(jshintStylish));
});
gulp.task('size', function () {
var size = require('gulp-size');
gulp.src(sources)
.pipe(size({ showFiles: true }));
});
gulp.task('compress', function () {
var closureCompiler = require('gulp-closure-compiler');
var bytediff = require('gulp-bytediff');
gulp.src(sources)
.pipe(bytediff.start())
.pipe(closureCompiler())
.pipe(bytediff.stop())
.pipe(gulp.dest(dist + 'compressed'));
});
gulp.task('uglify', function() {
var uglify = require('gulp-uglify');
var bytediff = require('gulp-bytediff');
gulp.src(sources)
.pipe(bytediff.start())
.pipe(uglify())
.pipe(bytediff.stop())
.pipe(gulp.dest(dist + 'uglified'));
});
gulp.task('minify', function() {
var uglify = require('gulp-uglify');
var closureCompiler = require('gulp-closure-compiler');
var bytediff = require('gulp-bytediff');
gulp.src(sources)
.pipe(bytediff.start())
.pipe(closureCompiler())
.pipe(uglify())
.pipe(bytediff.stop())
.pipe(gulp.dest(dist + 'minified'));
});
gulp.task('start_cover', function (cb) {
var istanbul = require("gulp-istanbul");
gulp.src(sources)
.pipe(istanbul())
.on('end', cb);
});
// Run tests and output reports
gulp.task('cover', function () {
var mocha = require("gulp-mocha");
var istanbul = require("gulp-istanbul");
gulp.run('start_cover', function () {
gulp.src(testSources)
.pipe(mocha()) // Run any unit test frameworks here
.pipe(istanbul.writeReports());
});
});
gulp.task('test', function () {
var mocha = require("gulp-mocha");
gulp.src(testSources)
.pipe(mocha({ reporter: 'spec', growl: 'true' }));
});
/*
gulp.task('traceur', function () {
var traceur = require('gulp-traceur');
gulp.src(sources)
.pipe(traceur())
.pipe(gulp.dest('traceured'));
});
*/
gulp.task('dist', function() {
var browserify = require('gulp-browserify');
var concat = require("gulp-concat");
var header = require("gulp-header");
var bytediff = require('gulp-bytediff');
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
var notify = require("gulp-notify");
gulp.src('index.js') // sources
.pipe(browserify()) // { debug: true /* source maps */ }
.pipe(concat('index.js'))
.pipe(rename('bundle.js'))
.pipe(header('/* This is a header for ${name} version ${version}! */\n', { name: 'gulp test', version: '0.0.2' } ))
.pipe(gulp.dest(dist + 'bundle'))
.pipe(rename('bundle.min.js'))
.pipe(bytediff.start())
.pipe(uglify())
.pipe(bytediff.stop())
.pipe(header('/* This is a header for minified ${name} version ${version}! */\n', { name: 'gulp test', version: '0.0.2' } ))
.pipe(gulp.dest(dist + 'bundle'))
.pipe(notify({ message: 'dist task completed' }));
});
gulp.task('watch', function() {
gulp.watch(allSources, function() {
gulp.run('test');
});
});
gulp.task('notify', function() {
var notify = require("gulp-notify");
gulp.src(allSources)
.pipe(notify({
message: "Hello Gulp!"
}));
});
gulp.task('bump', function(){
var bump = require('gulp-bump');
gulp.src('./package.json')
.pipe(bump({version: 'minor'}))
.pipe(gulp.dest('./'));
});
gulp.task('jscs', function () {
var jscs = require('gulp-jscs');
gulp.src(allSources)
.pipe(jscs());
});
gulp.task('header', function () {
var header = require('gulp-header');
gulp.src(allSources)
.pipe(header('This is a header for ${name}!\n', { name : 'gulp test'} ))
.pipe(gulp.dest(dist + 'header'));
});
gulp.task('sloc', function(){
var sloc = require('gulp-sloc');
gulp.src(allSources)
.pipe(sloc());
});
gulp.task('plato', function () {
var plato = require('gulp-plato');
gulp.src(sources)
.pipe(plato('report'));
});
gulp.task('gamedev', function() {
gulp.run('gamedev-server', 'gamedev-scripts');
gulp.watch(sources, function(event) {
gulp.run('gamedev-scripts');
});
});
var lr = require('tiny-lr');
var server = lr();
gulp.task('gamedev-scripts', function() {
var browserify = require('gulp-browserify');
var concat = require('gulp-concat');
var refresh = require('gulp-livereload');
gulp.src(sources)
.pipe(browserify())
.pipe(concat('index.js'))
.pipe(gulp.dest(dist + 'gamedev'))
.pipe(refresh(server));
});
gulp.task('gamedev-server', function() {
var port = 35729;
server.listen(port, function(err) {
if(err) return console.log(err);
console.log('Listening on localhost:%s', port);
console.log('Include <script src="http://localhost:35729/livereload.js"></script> in your HTML');
});
});
// for sequential tasks: https://github.com/OverZealous/gulp-run-sequence
// for an improved watch task use: https://github.com/floatdrop/gulp-watch
gulp.task('default', function(){
// place code for your default task here
});
{
"version": "0.0.2",
"devDependencies": {
"gulp": "~3.4.1",
"gulp-jshint": "~1.3.4",
"jshint-stylish": "~0.1.4",
"gulp-size": "~0.1.0",
"gulp-closure-compiler": "~0.1.0",
"gulp-bytediff": "~0.1.4",
"gulp-uglify": "~0.1.0",
"gulp-istanbul": "~0.1.0",
"gulp-mocha": "~0.2.0",
"gulp-traceur": "~0.1.0",
"gulp-sloc": "~1.0.0",
"gulp-concat": "~2.1.7",
"gulp-rename": "~0.2.1",
"gulp-plato": "~0.1.0",
"gulp-livereload": "~0.1.1",
"tiny-lr": "0.0.5",
"gulp-browserify": "~0.2.4",
"gulp-notify": "~0.3.0",
"gulp-jscs": "~0.3.0",
"gulp-header": "~1.0.2",
"gulp-bump": "~0.1.0"
}
}
@RenuDaffodilsw
Copy link

Unable to generate report in gulp-plato task using sources.
Like:-
var sources = './www/js/*.js';

gulp.task('generate-report', function() {
gulp.src(sources)
.pipe(plato('report'));
});

But if I use source files without regex it work well.
Like:-
var sources = ['./www/js/addProduct.js', './www/js/app.js', './www/js/joinMembership.js'];

gulp.task('generate-report', function() {
gulp.src(sources)
.pipe(plato('report'));
});

How can I use gulp-plato for multiple files without specifying each file in array ?? Please help me with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment