1
0
Fork 0
mirror of https://github.com/Oreolek/shooter.git synced 2024-05-17 00:08:15 +03:00
shooter/Gulpfile.js

188 lines
4.6 KiB
JavaScript
Raw Normal View History

2015-12-01 08:42:52 +02:00
'use strict';
/* Imports */
var watchify = require('watchify'),
browserify = require('browserify'),
browserSync = require('browser-sync'),
gulp = require('gulp'),
source = require('vinyl-source-stream'),
gutil = require('gulp-util'),
coffeify = require('coffeeify'),
less = require('gulp-less'),
minifyCSS = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
buffer = require('vinyl-buffer'),
zip = require('gulp-zip'),
2015-12-08 09:57:24 +02:00
_ = require('lodash'),
concat = require('gulp-concat');
2015-12-01 08:42:52 +02:00
var reload = browserSync.reload;
/* Tasks */
/* Trivial file copies */
function html (target) {
return function () {
return gulp.src(['html/index.html','html/en.html'])
2015-12-01 08:42:52 +02:00
.pipe(gulp.dest(target));
};
}
function img (target) {
return function () {
return gulp.src(['img/*.png', 'img/*.jpeg', 'img/*.jpg'])
.pipe(gulp.dest(target));
};
}
2015-12-02 09:20:18 +02:00
function audio (target) {
return function () {
return gulp.src(['audio/*.mp3'])
.pipe(gulp.dest(target));
};
}
2015-12-01 08:42:52 +02:00
gulp.task('html', html('./build'));
gulp.task('img', img('./build/img'));
2015-12-02 09:20:18 +02:00
gulp.task('audio', audio('./build/audio'));
2015-12-01 08:42:52 +02:00
/* Less */
gulp.task('less', function () {
gulp.src('less/main.less')
.pipe(less())
.pipe(gulp.dest('./build/css'));
});
/* Bundle libraries */
var undumBundler = browserify({debug: true});
undumBundler.require('undum-commonjs');
gulp.task('buildUndum', function () {
return undumBundler.bundle().pipe(source('undum.js')).pipe(gulp.dest('./build/game'));
});
/* Generate JavaScript with browser sync. */
2015-12-08 12:55:34 +02:00
var sources = [
'./game/begin.coffee',
'./game/gameplay.coffee',
'./game/story.coffee',
'./game/end.coffee',
]
var opts = _.assign({}, watchify.args, {
entries: ["./build/game/main.coffee"],
2015-12-01 08:42:52 +02:00
debug: true,
transform: [coffeify]
2015-12-08 12:55:34 +02:00
});
2015-12-01 08:42:52 +02:00
var bundler = watchify(browserify(opts));
bundler.external('undum-commonjs');
function bundle () {
return bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/game'));
};
2015-12-08 09:57:24 +02:00
gulp.task('copyTranslations', [], function() {
gulp.src('./game/translations/*.coffee')
.pipe(gulp.dest('./build/game/translations'));
});
gulp.task('concatCoffee', ['copyTranslations'], function() {
2015-12-08 12:55:34 +02:00
return gulp.src(sources)
2015-12-08 09:57:24 +02:00
.pipe(concat('./main.coffee'))
.pipe(gulp.dest('./build/game'));
});
// `gulp coffee` will generate bundle
gulp.task('coffee', ['buildUndum', 'concatCoffee'], bundle);
bundler.on('update', bundle); // Re-bundle on dep updates
bundler.on('log', gutil.log); // Output build logs to terminal
2015-12-01 08:42:52 +02:00
/* Make a development build */
2015-12-02 09:20:18 +02:00
gulp.task('build', ['html', 'img', 'less', 'coffee', 'audio'], function () {
2015-12-01 08:42:52 +02:00
});
/* Start a development server */
gulp.task('serve', ['build'], function () {
browserSync({
server: {
baseDir: 'build'
}
});
var lessListener = function () {
reload('./build/css/main.css');
}
gulp.watch(['./html/*.html'], ['html']);
gulp.watch(['./less/*.less'], ['less']);
gulp.watch(['./img/*.png', './img/*.jpeg', './img/*.jpg'], ['img']);
2015-12-08 14:06:56 +02:00
gulp.watch(['./game/*.coffee', './game/translations/*.coffee'], ['coffee']);
2015-12-01 08:42:52 +02:00
gulp.watch(['./build/css/main.css'], lessListener);
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'));
2015-12-03 07:06:22 +02:00
gulp.task('audio-dist', audio('./dist/audio'));
2015-12-01 08:42:52 +02:00
gulp.task('less-dist', function () {
return gulp.src('./less/main.less')
.pipe(less())
.pipe(minifyCSS())
.pipe(gulp.dest('./dist/css'));
});
var distBundler = browserify({
debug: false,
entries: ['./game/main.coffee'],
transform: ['coffeeify']
});
distBundler.external('undum-commonjs');
gulp.task('coffee-dist', ['undum-dist'], function () {
return distBundler.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(uglify())
.on('error', gutil.log)
.pipe(gulp.dest('./dist/game'));
});
2015-12-02 09:20:18 +02:00
gulp.task('dist', ['html-dist', 'img-dist', 'less-dist', 'coffee-dist', 'audio-dist'],
2015-12-01 08:42:52 +02:00
function () {
return;
});
gulp.task('zip', ['dist'], function () {
return gulp.src('dist/**')
.pipe(zip('dist.zip'))
.pipe(gulp.dest('.'));
});