browserSync = require('browser-sync') gulp = require('gulp') gutil = require('gulp-util') coffee = require("gulp-coffee") sass = require('gulp-sass') minify = require('gulp-minify') zip = require('gulp-zip') concat = require('gulp-concat') rename = require('gulp-rename') rm = require( 'gulp-rm' ) source = require('vinyl-source-stream') fs = require 'fs' path = require 'path' cson = require 'cson' glob = require('glob-fs')({ builtins: false }) mkdirp = require 'mkdirp' reload = browserSync.reload gulp.task('bundle-dist', () -> return gulp.src("./build/game/main.coffee") .pipe(coffee({ bare: true sourcemaps: false })) .pipe(gulp.dest('./build/game')) ) gulp.task('minify-dist', () -> return gulp.src(['./build/game/main.js']) .pipe(minify()) .pipe(gulp.dest('./dist/game/')) ) html = (target, debug) -> return () -> sources = [ 'html/index.html' ] if (debug) sources.push('html/test.html') gulp.src(sources) .pipe(gulp.dest(target)) gulp.src(['node_modules/salet/lib/index.min.js']) .pipe(rename('salet.min.js')) .pipe(gulp.dest(target+"/game")) # Images img = (target) -> return () -> return gulp.src(['img/*.png', 'img/*.jpeg', 'img/*.jpg']).pipe(gulp.dest(target)) # Audio assets audio = (target) -> return () -> return gulp.src(['audio/*.mp3']).pipe(gulp.dest(target)) # Fonts fonts = (target) -> return () -> return gulp.src(['fonts/*']).pipe(gulp.dest(target)) gulp.task('html', html('./build', true)) gulp.task('img', img('./build/img')) gulp.task('audio', audio('./build/audio')) gulp.task('fonts', fonts('./build/fonts')) # SCSS styles gulp.task('sass', () -> gulp.src('sass/main.scss') .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) .pipe(gulp.dest('./build/css')) ) # Autotests gulp.task('tests', () -> gulp.src('test/*.js') .pipe(gulp.dest('./build/test/')) ) gulp.task('procgen', (done) -> #for language in ['ru', 'en'] for language in ['ru'] patterns = glob.readdirSync("game/procgen/#{language}/*.cson", {}) json = {} for filename in patterns snippet = cson.parseCSONString fs.readFileSync(filename) if not snippet.groups? snippet.groups = [] if snippet.phrases? snippet.groups.push({ tags: [], phrases: snippet.phrases }) delete snippet.phrases pattern = path.basename(filename) pattern = pattern.replace(/\..+$/, "") json[pattern] = snippet mkdirp.sync "./build/game/procgen" # we stringify JS object into coffeescript… code = cson.stringify({json}, { format: "coffeescript" indent: " " }) # cut the first line and assign to a var code = "improvdata_#{language} =\n"+code.substring(code.indexOf("\n")+1) # write it as a file fs.writeFileSync "./build/game/procgen/#{language}.coffee", code #and then see concatCoffee task where we compile this return done() ### return gulp.src([ "build/game/procgen/ru.json", #"build/game/procgen/en.json", ]) ### ) gulp.task('concatCoffee', () -> gulp.src([ # language './game/translations/ru.coffee' './build/game/procgen/ru.coffee' ## additional functions './game/mappings.coffee' ## Improv (coffeescript) './game/improv/template.coffee' './game/improv/index.coffee' './game/improv/filters.coffee' ## the actual game './game/1_maze.coffee' # map './game/2_model.coffee' # story logic './game/3_engine.coffee' # engine stuff './game/4_plot.coffee' # plot './game/5_gamepad.coffee' # basic gamepad support './game/6_gamepadinit.coffee' # gamepad initialization ]).pipe(concat('./main.coffee')) .pipe(gulp.dest('./build/game')) ) gulp.task('coffee', gulp.series('procgen', 'concatCoffee', () -> return gulp.src("./build/game/main.coffee") .pipe(coffee({ bare: true sourcemaps: true })) .pipe(gulp.dest('./build/game')) )) gulp.task('build', gulp.parallel( 'html', 'img', 'sass', 'coffee', 'audio', 'fonts', 'tests', )) gulp.task('serve', gulp.series('build', () -> browserSync({ server: { baseDir: 'build' } online: true browser: [] ghostMode: false }) sassListener = () -> reload('./build/css/main.css') gulp.watch(['./test/*.js'], gulp.series('tests')) gulp.watch(['./html/*.html'], gulp.series('html')) gulp.watch(['./sass/*.scss'], gulp.series('sass')) gulp.watch(['./img/*.png', './img/*.jpeg', './img/*.jpg'], gulp.series('img')) gulp.watch([ './game/*.coffee' './game/translations/*.coffee' ], gulp.series('coffee')) gulp.watch([ './game/procgen/*/*.cson' ], gulp.series('procgen')) gulp.watch(['./build/css/main.css'], sassListener) gulp.watch( ['./build/game/bundle.js', './build/img/*', './build/index.html'], browserSync.reload ) )) gulp.task('html-dist', html('./dist', false)) gulp.task('fonts-dist', fonts('./dist/fonts')) gulp.task('img-dist', img('./dist/img')) gulp.task('audio-dist', audio('./dist/audio')) gulp.task('legal-dist', () -> return gulp.src(['LICENSE.txt']) .pipe(gulp.dest("./dist")) ) gulp.task('sass-dist', () -> return gulp.src('./sass/main.scss') .pipe(sass({outputStyle: 'compressed'})) .pipe(gulp.dest('./dist/css')) ) gulp.task('remove-big-bundle-dist', (done) -> return gulp.src([ './dist/game/main-min.js' ]) .pipe(rm()) .on('end', () -> done()) ) gulp.task('rename-min-bundle-dist', (done) -> return gulp.src([ './dist/game/main-min.js' ]) .pipe(rename('main.js')) .pipe(gulp.dest('./dist/game/')) .on('end', () -> done()) ) gulp.task('coffee-dist', gulp.series( 'procgen' 'concatCoffee' 'bundle-dist' 'minify-dist' 'rename-min-bundle-dist' 'remove-big-bundle-dist' ) ) gulp.task('dist', gulp.parallel( 'html-dist', 'img-dist', 'sass-dist', 'coffee-dist', 'audio-dist', 'fonts-dist', 'legal-dist' )) gulp.task('zip', gulp.series('dist', () -> return gulp.src('dist/**') .pipe(zip('dist.zip')) .pipe(gulp.dest('.')) ))