Skip to content

Commit

Permalink
Grunt -> gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
UltCombo committed Dec 24, 2014
1 parent 80bab63 commit b105641
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 126 deletions.
111 changes: 0 additions & 111 deletions Gruntfile.js

This file was deleted.

14 changes: 14 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
srcBase: 'src/',
src: {
js: ['**/*.js', '!bin/skeleton/**', '!bin/client/**']
},
distBase: 'dist/',
config: {
jscs: { configPath: '.jscsrc', esnext: true },
'6to5': { blacklist: ['generators'] },
mocha: { bail: true, timeout: 5000 }
}
};
112 changes: 112 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use strict';

// [TEMP] workaround gulp-jscs Windows issue - https://github.com/es6rocks/slush-es6/issues/4
if (require('os').platform() === 'win32') process.argv.push('--no-color');

var path = require('path'),
gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
rimraf = require('rimraf'),
through = require('through'),
mergeStream = require('merge-stream'),
reverseStream = require('reversepoint'),
uniqueStream = require('unique-stream'),
lazypipe = require('lazypipe'),
chalk = require('chalk'),
build = require('./build'),
copySrc = ['**'].concat(negateGlobs(build.src.js)),
writePipe = lazypipe()
.pipe(gulp.dest, build.distBase),
jsPipe = lazypipe()
.pipe(plugins.jshint)
.pipe(plugins.jshint.reporter, 'jshint-stylish')
.pipe(plugins.jshint.reporter, 'fail')
.pipe(plugins.jscs, build.config.jscs)
.pipe(plugins['6to5'], build.config['6to5'])
.pipe(writePipe),
runTests = lazypipe()
.pipe(gulp.src, build.distBase + 'test/*.js', { read: false })
.pipe(plugins.mocha, build.config.mocha);

function negateGlobs(globs) {
return globs.map(function(glob) {
return ~glob.lastIndexOf('!', 0)glob.slice(1) : '!' + glob;
});
}

function prefixGlobs(globs, prefix) {
return globs.map(function(glob) {
return ~glob.lastIndexOf('!', 0) ? '!' + prefix + glob.slice(1) : prefix + glob;
});
}

function runAfterEnd(cb) {
// This is basically a passThrough stream for the callback's stream.
// It waits until all data is finished being piped into it and discards this data,
// then passes through the data from the stream provided by the callback.
return through(function() {}, function() {
var cbStream = cb();
['data', 'end'/*, 'error'*/].forEach(function(event) {
cbStream.on(event, this.emit.bind(this, event));
}, this);
});
}

gulp.task('build', function() {
rimraf.sync(build.distBase);
return mergeStream(
gulp.src(prefixGlobs(build.src.js, build.srcBase), { base: build.srcBase }).pipe(jsPipe()),
gulp.src(prefixGlobs(copySrc, build.srcBase), { base: build.srcBase }).pipe(writePipe())
)
.pipe(runAfterEnd(runTests));
});

// `neverEnd` receives a task conclusion callback which is never called as to signal that this watch task should never end.
// We don't return gulp-watch's endless stream as it would fail the task in the first stream error.
gulp.task('default', ['build'], function(neverEnd) {
// The odd indentation here is to better illustrate the stream branching/forking flow.
// Diagram reference: https://github.com/es6rocks/slush-es6/issues/5#issue-52701608
var uniqueFilter = lazypipe()
.pipe(reverseStream)
.pipe(uniqueStream, 'path'),

existsFilter = lazypipe()
.pipe(plugins.filter, filterEvent.bind(null, ['changed', 'added'])),

handleJs = lazypipe()
.pipe(plugins.filter, build.src.js)
.pipe(jsPipe),

handleCopy = lazypipe()
.pipe(plugins.filter, copySrc)
.pipe(writePipe),

handleDeletion = lazypipe()
.pipe(plugins.filter, filterEvent.bind(null, ['deleted']))
.pipe(plugins.rename, function(filePath) {
// we can't change/remove the filePath's `base`, so cd out of it in the dirname
filePath.dirname = path.join(path.relative(build.srcBase, '.'), build.distBase, filePath.dirname);
})
.pipe(plugins.rimraf);

function filterEvent(events, file) {
return ~events.indexOf(file.event);
}

plugins.watch(build.srcBase + '**', { base: build.srcBase }, plugins.batch(function(files) {
files = files.pipe(uniqueFilter());
var existingFiles = files.pipe(existsFilter());

return mergeStream(
existingFiles.pipe(handleJs()),
existingFiles.pipe(handleCopy()),
files.pipe(handleDeletion())
)
.pipe(runAfterEnd(runTests));
}, function(err) {
// [TEMP] makeshift error reporting for gulp-jscs until gulp-jscs implements proper reporters
console.error(err.message);
})).on('ready', function() {
plugins.util.log('Watching ' + chalk.magenta(build.srcBase) + ' directory for changes...');
});
});
37 changes: 23 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"co": "~3.0.5",
"co-prompt": "^1.0.0",
"commander": "~2.2.0",
"gulp-6to5": "^1.0.2",
"less": "^1.7.5",
"markdown-extra": "^0.1.0",
"marked": "~0.3.2",
Expand All @@ -40,23 +41,31 @@
"v8-argv": "^0.2.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-6to5": "^1.0.1",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-jscs": "^0.8.1",
"grunt-mocha-test": "^0.12.2",
"load-grunt-tasks": "^1.0.0",
"should": "^4.0.4"
"chalk": "^0.5.1",
"gulp": "^3.8.10",
"gulp-batch": "^1.0.4",
"gulp-filter": "^1.0.2",
"gulp-jscs": "^1.3.1",
"gulp-jshint": "^1.9.0",
"gulp-load-plugins": "^0.8.0",
"gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-rimraf": "^0.1.1",
"gulp-util": "^3.0.1",
"gulp-watch": "^3.0.0",
"jshint-stylish": "^1.0.0",
"lazypipe": "^0.2.2",
"merge-stream": "^0.1.6",
"reversepoint": "^0.2.1",
"should": "^4.4.1",
"through": "^2.3.6",
"unique-stream": "^1.0.0"
},
"author": "Jaydson Gomes <[email protected]> (http://jaydson.org/)",
"license": "MIT",
"scripts": {
"dev": "grunt",
"prepublish": "npm i grunt-6to5 && npm test",
"test": "grunt build"
"dev": "node --harmony ./node_modules/gulp/bin/gulp",
"prepublish": "npm i gulp-6to5 && npm test",
"test": "node --harmony ./node_modules/gulp/bin/gulp build"
}
}
2 changes: 1 addition & 1 deletion src/bin/cli/program.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('grunt-6to5/node_modules/6to5/polyfill');
require('gulp-6to5/node_modules/6to5/polyfill');
var program = require('commander');

import { version } from '../config';
Expand Down

0 comments on commit b105641

Please sign in to comment.