browserSync = require('browser-sync') gulp = require('gulp') coffee = require("gulp-coffee") sass = require('gulp-sass') zip = require('gulp-zip') concat = require('gulp-concat') reload = browserSync.reload; # Copy assets over without touching them assets = (target) -> return () -> return gulp.src([ 'img/*.png', 'img/*.jpeg', 'img/*.jpg' ]).pipe(gulp.dest(target)) gulp.task('assets', assets('./build')); gulp.task('sass', function () { gulp.src('sass/main.scss') .pipe(sass().on('error', sass.logError)) .pipe(gulp.dest('./build/css')); }); gulp.task('html', html('./build')); gulp.task('concatCoffee', function() { return gulp.src([ './game/begin.coffee', './game/story.coffee', './game/init.coffee', ]) .pipe(concat('./main.coffee')) .pipe(gulp.dest('./build/game')); }); gulp.task('coffee', ['concatCoffee']) bundler.on('update', coffee); bundler.on('log', gutil.log); # Output build logs to terminal gulp.task('build', ['html', 'img', 'sass', 'coffee']) gulp.task('serve', ['build'], () -> browserSync({ server: { baseDir: 'build' } }) sassListener = () -> reload('./build/css/main.css'); gulp.watch(['./html/*.html'], ['html']); gulp.watch(['./sass/*.scss'], ['sass']); gulp.watch(['./build/css/main.css'], sassListener); gulp.watch(['./img/*.png', './img/*.jpeg', './img/*.jpg'], ['img']); gulp.watch(['./game/*.coffee'], ['coffee']); gulp.watch( ['./build/game/bundle.js', './build/img/*', './build/index.html'], browserSync.reload) }) /* Distribution tasks */ var undumDistBundler = browserify(); undumDistBundler.require('undum-commonjs'); gulp.task('undum-dist', function () { return undumDistBundler.bundle().pipe(source('undum.js')) .pipe(buffer()) .pipe(uglify()) .pipe(gulp.dest('./dist/game')); }); gulp.task('html-dist', html('./dist')); gulp.task('img-dist', img('./dist/img')); gulp.task('legal-dist', function () { return gulp.src(['LICENSE.txt']) .pipe(gulp.dest("./dist")); }); gulp.task('sass-dist', function () { return gulp.src('./sass/main.scss') .pipe(sass({outputStyle: 'compressed'})) .pipe(gulp.dest('./dist/css')); }); var distBundler = browserify({ debug: false, entries: ['./build/game/main.coffee'], transform: ['coffeeify'] }); distBundler.external('undum-commonjs'); gulp.task('coffee-dist', ['undum-dist', 'concatCoffee'], function () { return distBundler.bundle() .pipe(source('bundle.js')) .pipe(buffer()) .pipe(uglify()) .on('error', gutil.log) .pipe(gulp.dest('./dist/game')); }); gulp.task('dist', ['html-dist', 'img-dist', 'sass-dist', 'coffee-dist', 'legal-dist'], function () { return; }); gulp.task('zip', ['dist'], function () { return gulp.src('dist/**') .pipe(zip('dist.zip')) .pipe(gulp.dest('.')); });