This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
159 lines (126 loc) · 3.58 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
const GAME_SCALE = 4;
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
var jsonTransform = require('gulp-json-transform');
var browserSync = require('browser-sync').create();
var del = require('del');
var merge = require('merge-stream');
var rename = require('gulp-rename');
// IMPORTANT
// edit gulp.config.json and customize there your deployment settings
var rsync = require('gulp-rsync');
var config = {};
try {
config = require('./gulp.config.json');
}
catch (e) {
console.warn('Edit or create gulp.config.json to customize your ' +
'deployment settings.');
}
var ghpages = require('gulp-gh-pages');
//
// browserify and js
//
var bundler = browserify([
'./src/js/main.js'
]);
var bundle = function () {
return bundler
.bundle()
.on('error', gutil.log)
.pipe(source('bundle.js'))
.pipe(gulp.dest('.tmp/js/'))
.pipe(browserSync.stream({once: true}));
};
gulp.task('browserify', bundle);
// 3rd party libs that don't play nice with browserify
gulp.task('libs', function () {
var dir = './node_modules/phaser/build/';
return gulp.src(['phaser.min.js', 'phaser.map'], { cwd: dir, base: dir})
.pipe(gulp.dest('./.tmp/js/lib/'));
});
gulp.task('js', ['browserify', 'libs']);
//
// game-related builds
//
gulp.task('build:maps', function () {
gulp.src('src/data/*.json')
.pipe(jsonTransform(function (data) {
return {
width: data.tileswide,
height: data.tileshigh,
tilewidth: data.tilewidth * GAME_SCALE,
tileheight: data.tileheight * GAME_SCALE,
layers: data.layers.filter(x => x !== null).map(function (l) {
return {
data: l.tiles.map(x => x.tile === 0 ? -1 : x.tile),
name: l.name
};
})
};
}), 2)
.pipe(rename({
suffix: '.min',
extname: '.json'
}))
.pipe(gulp.dest('./.tmp/data/'))
.on('error', gutil.log);
});
//
// build and deploy
//
gulp.task('build', ['js', 'build:maps']);
gulp.task('dist', ['build'], function () {
var rawFiles = gulp.src([
'index.html', 'raw.html',
'styles.css', 'fs-icon.svg',
'images/**/*', 'fonts/**/*', 'audio/**/*'
], { cwd: './src', base: './src' })
.pipe(gulp.dest('./dist/'));
var builtFiles = gulp.src([
'js/**/*', 'data/**/*'
], { cwd: '.tmp', base: '.tmp' })
.pipe(gulp.dest('./dist/'));
return merge(rawFiles, builtFiles);
});
gulp.task('clean', function () {
return del(['.tmp', 'dist', '.publish']);
});
gulp.task('deploy:rsync', ['dist'], function () {
return gulp.src('dist')
.pipe(rsync({
root: 'dist',
username: config.deploy.user,
hostname: config.deploy.host,
destination: config.deploy.destination,
recursive: true,
clean: true,
progress: true,
incremental: true
}));
});
gulp.task('deploy:ghpages', ['dist'], function () {
return gulp.src('dist/**/*')
.pipe(ghpages());
});
//
// dev tasks
//
gulp.task('watch', function () {
bundler = watchify(bundler, watchify.args);
bundler.on('update', bundle);
});
gulp.task('run', ['watch', 'build'], function () {
browserSync.init({
server: ['src', '.tmp']
});
gulp.watch('src/**/*.{html,css}').on('change', browserSync.reload);
});
//
// default task
//
gulp.task('default', ['dist']);