Created
January 29, 2015 06:38
-
-
Save andrewluetgers/b6c70860dfbd3dadc5da to your computer and use it in GitHub Desktop.
Gulp build for riot.js with sourcemaps
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
var es = require('event-stream'), | |
gulp = require('gulp'), | |
riot = require('gulp-riot'), | |
rimraf = require('gulp-rimraf'), | |
jshint = require('gulp-jshint'), | |
stylus = require('gulp-stylus'), | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), | |
notify = require("gulp-notify"), | |
plumber = require('gulp-plumber'), | |
sourcemaps = require('gulp-sourcemaps'); | |
var outName = "app.js", | |
build = './build', | |
dest = build + '/assets', | |
tagSrc = ['./src/*.tag', './src/**/*.tag'], | |
appSrc = ['./src/*.js', './src/**/*.js'], | |
stylSrc = ['./src/*.styl'], | |
copySrc = ['./src/*.html'], | |
libSrc = ['./lib/**/*.js'], | |
opts = {errorHandler: notify.onError("Error: <%= error.message %>")}; | |
function libs() {return gulp.src(libSrc);} | |
function tags() { | |
return gulp.src(tagSrc) | |
.pipe(plumber()) | |
.pipe(riot()); | |
} | |
function app() {return gulp.src(appSrc);} | |
function linted() { | |
return es.merge(tags(), app()) | |
.pipe(plumber(opts)) | |
.pipe(jshint()) | |
.pipe(notify(function (file) { | |
if (!file.jshint.success) { | |
var errors = file.jshint.results.map(function (data) { | |
if (data.error) { | |
return "(" + data.error.line + ':' + data.error.character + ') ' + data.error.reason; | |
} | |
}).join("\n"); | |
return file.relative + " (" + file.jshint.results.length + " errors)\n" + errors; | |
} else { | |
return false; | |
} | |
})) | |
.pipe(jshint.reporter('jshint-stylish')); | |
} | |
gulp.task('js', function() { | |
return es.merge(libs(), linted()) | |
.pipe(plumber(opts)) | |
.pipe(sourcemaps.init()) | |
.pipe(concat(outName)) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest(dest)); | |
}); | |
gulp.task('copy', function () { | |
return gulp.src(copySrc) | |
.pipe(plumber(opts)) | |
.pipe(gulp.dest(build)); | |
}); | |
gulp.task('styl', function () { | |
gulp.src(stylSrc) | |
.pipe(plumber(opts)) | |
.pipe(sourcemaps.init()) | |
.pipe(stylus()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest(dest)); | |
}); | |
gulp.task('clean', function () { | |
return gulp.src('build', {read: false}) | |
.pipe(plumber(opts)) | |
.pipe(rimraf({force: true})); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(copySrc.concat(appSrc, tagSrc, libSrc, stylSrc), ['copy', 'styl', 'js']); | |
}); | |
gulp.task('default', ['copy', 'styl', 'js', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment