-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
126 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters