Skip to content

Commit

Permalink
switch out grunt for gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Mar 8, 2015
1 parent 9332b2e commit efd3833
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ components/
bower_components/
node_modules/
build/
**/fonts/
73 changes: 0 additions & 73 deletions Gruntfile.js

This file was deleted.

1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"tests",
"changelog.md",
"Gruntfile.js",
"gulpfile.js",
"package.json",
"sandbox"
]
Expand Down
148 changes: 148 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*jshint node: true, strict: false */

var fs = require('fs');
var gulp = require('gulp');

// ----- lint ----- //

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

gulp.task( 'lint-js', function() {
return gulp.src('draggabilly.js')
.pipe( jshint() )
.pipe( jshint.reporter('default') );
});

gulp.task( 'lint-test', function() {
return gulp.src('test/unit/*.js')
.pipe( jshint() )
.pipe( jshint.reporter('default') );
});

gulp.task( 'lint-task', function() {
return gulp.src('gulpfile.js')
.pipe( jshint() )
.pipe( jshint.reporter('default') );
});

var jsonlint = require('gulp-json-lint');

gulp.task( 'lint-json', function() {
return gulp.src( '*.json' )
.pipe( jsonlint() )
.pipe( jsonlint.report('verbose') );
});

gulp.task( 'lint', [ 'lint-js', 'lint-test', 'lint-task', 'lint-json' ] );

// -------------------------- dist -------------------------- //
// RequireJS makes pkgd

// refactored from gulp-requirejs-optimize
// https://www.npmjs.com/package/gulp-requirejs-optimize/

var gutil = require('gulp-util');
var through2 = require('through2');
var requirejs = require('requirejs');

function rjsOptimize( options ) {
var stream;

requirejs.define( 'node/print', [], function() {
return function(msg) {
gutil.log( msg );
};
});

options = options || {};

stream = through2.obj( function ( file, enc, cb ) {
if ( file.isNull() ) {
this.push( file );
return cb();
}

options.logLevel = 2;

options.out = function( text ) {
var outFile = new gutil.File({
path: file.relative,
contents: new Buffer( text )
});
cb( null, outFile );
};

gutil.log('RequireJS optimizing');
requirejs.optimize( options, null, function( err ) {
var gulpError = new gutil.PluginError( 'requirejsOptimize', err.message );
stream.emit( 'error', gulpError );
});
});

return stream;
}

// regex for banner comment
var reBannerComment = new RegExp('^\\s*(?:\\/\\*[\\s\\S]*?\\*\\/)\\s*');

function getBanner() {
var src = fs.readFileSync( 'draggabilly.js', 'utf8' );
var matches = src.match( reBannerComment );
var banner = matches[0].replace( 'Draggabilly', 'Draggabilly PACKAGED' );
return banner;
}

var replace = require('gulp-replace');
var rename = require('gulp-rename');

function addBanner( str ) {
return replace( /^/, str );
}

gulp.task( 'requirejs', function() {
var banner = getBanner();
// HACK src is not needed
// should refactor rjsOptimize to produce src
return gulp.src('draggabilly.js')
.pipe( rjsOptimize({
baseUrl: 'bower_components',
optimize: 'none',
include: [
'jquery-bridget/jquery.bridget',
'draggabilly/draggabilly'
],
paths: {
draggabilly: '../',
jquery: 'empty:'
}
}) )
// add banner
.pipe( addBanner( banner ) )
.pipe( rename('draggabilly.pkgd.js') )
.pipe( gulp.dest('dist') );
});

// ----- uglify ----- //

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

gulp.task( 'uglify', function() {
var banner = getBanner();
return gulp.src('dist/draggabilly.pkgd.js')
.pipe( uglify() )
// add banner
.pipe( addBanner( banner ) )
.pipe( rename('draggabilly.pkgd.min.js') )
.pipe( gulp.dest('dist') );
});

// ----- dist ----- //

gulp.task( 'dist', [ 'requirejs', 'uglify' ] );

// ----- default ----- //

gulp.task( 'default', [
'lint',
'dist'
]);
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"unidragger": "~1.1.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.5.0",
"grunt-requirejs": "^0.4.2"
"gulp": "^3.8.11",
"through2": "^0.6.3",
"gulp-replace": "^0.5.3",
"gulp-uglify": "^1.1.0",
"requirejs": "^2.1.16",
"gulp-jshint": "^1.9.2",
"gulp-json-lint": "^0.1.0",
"gulp-rename": "^1.2.0",
"gulp-util": "^3.0.4"
},
"scripts": {
"test": "grunt travis"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit efd3833

Please sign in to comment.