-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
101 lines (82 loc) · 2.79 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
const path = require('path');
const del = require('del');
const merge = require('merge-stream');
const { series, src, dest } = require('gulp');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const terser = require('gulp-terser');
const cleanCSS = require('gulp-clean-css');
const htmlreplace = require('gulp-html-replace');
const htmlmin = require('gulp-htmlmin');
const file = require('gulp-file');
const gtag = require('gulp-gtag');
const ghPages = require('gh-pages');
const destDirectory = './build';
const destAssetsDirectory = path.join(destDirectory, 'assets');
function clean() {
return del([destDirectory], { force: true });
}
function assets() {
const addGeneralAssets = src('./src/assets/**/*.{ico,png}').pipe(dest(destAssetsDirectory));
const addAudioAssets = src('./src/assets/audio/**/*.{webm,mp3}').pipe(dest(`${destAssetsDirectory}/audio`));
const addFontAssets = src('./src/assets/fonts/**/*.{woff,woff2}').pipe(dest(`${destAssetsDirectory}/fonts`));
return merge(addGeneralAssets, addAudioAssets, addFontAssets);
}
function styles() {
return src('./src/assets/**/*.css')
.pipe(concat('evader.css'))
.pipe(cleanCSS())
.pipe(rename('evader.min.css'))
.pipe(dest(destAssetsDirectory));
}
function scripts() {
const files = [
'./src/lib/dependencies/iNoBounce.js',
'./src/lib/dependencies/howler.min.js',
'./src/lib/evader/index.js',
'./src/lib/evader/config.js',
'./src/lib/evader/utils.js',
'./src/lib/evader/game.js',
'./src/lib/evader/game.options.js',
'./src/lib/evader/state.js',
'./src/lib/evader/state.persistence.js',
'./src/lib/evader/view.js',
'./src/lib/evader/audio.js',
'./src/lib/evader/init.js',
];
return src(files)
.pipe(concat('evader.js'))
.pipe(terser())
.pipe(rename('evader.min.js'))
.pipe(dest(destAssetsDirectory));
}
function html() {
return src('./src/index.html')
.pipe(
htmlreplace({
css: 'assets/evader.min.css',
js: 'assets/evader.min.js',
})
)
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest(destDirectory));
}
function addGoogleAnalytics() {
const GOOGLE_ANALYTICS_GTAG = 'G-4M7D55BJ47';
return src(`${destDirectory}/index.html`)
.pipe(gtag({ uid: GOOGLE_ANALYTICS_GTAG, minify: true }))
.pipe(dest(destDirectory));
}
function addCNAMERecord() {
const CNAME_RECORD = 'evader.red';
return src(`${destDirectory}/**/*`).pipe(file('CNAME', CNAME_RECORD)).pipe(dest(destDirectory));
}
function publishBuildToGitHubPages(cb) {
const { version } = require('./package.json');
ghPages.publish('build', { message: `Publish v${version} (${new Date().toISOString()})` }, function (err) {
cb(err);
});
}
const build = series(clean, assets, styles, scripts, html);
exports.default = build;
exports.deploy = series(build, addGoogleAnalytics, addCNAMERecord, publishBuildToGitHubPages);