-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
149 lines (133 loc) · 3.49 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
'use strict';
var gulp = require('gulp');
var panini = require('panini');
var rimraf = require('rimraf');
var yaml = require('js-yaml');
var fs = require('fs');
var argv = require('yargs').argv;
var runSequence = require('run-sequence');
var $ = require('gulp-load-plugins')();
var config = loadConfig();
var production = !!argv.production;
var DIST = 'public';
function loadConfig() {
var config = {};
var ymlFile = fs.readFileSync('./app/data/games.yml', 'utf8');
config.games = yaml.load(ymlFile);
return config;
}
function initGames() {
var copies = [];
for (var key in config.games) {
createGameTask(key)
copies.push(key);
}
return copies;
}
function createGameTask(game) {
var src, dest, imgsrc, assetDest, assetTask;
assetTask = game + '-assets';
assetDest = DIST + '/assets/img/games/' + game;
if (production) {
src = config.games[game].paths.src_release;
} else {
src = config.games[game].paths.src_debug;
}
imgsrc = config.games[game].paths.screenshot;
dest = DIST + '/' + config.games[game].paths.dist;
if (imgsrc) {
gulp.task(assetTask, function() {
return gulp.src(imgsrc)
.pipe($.rename('screenshot.png'))
.pipe(gulp.dest(assetDest));
});
}
if (src.indexOf('.zip') !== -1) {
// source is zip file
gulp.task(game, imgsrc ? [assetTask] : [], function() {
return gulp.src(src)
.pipe($.unzip())
.pipe(gulp.dest(dest));
});
} else {
// source is blob
gulp.task(game, imgsrc ? [assetTask] : [], function() {
return gulp.src(src)
.pipe(gulp.dest(dest));
});
}
}
// Build the "dist" folder by running all of the below tasks
gulp.task('default', ['pages'], function(cb) {
if (production) {
runSequence(initGames(), 'sitemap', cb);
} else {
runSequence(initGames(), cb);
}
});
// Copy page templates into finished HTML files
gulp.task('pages', function() {
return gulp.src('app/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'app/pages/',
layouts: 'app/layouts/',
pageLayouts: {
'learn/abc': 'abc'
},
partials: 'app/partials/',
data: 'app/data/',
helpers: 'app/helpers/'
}))
.pipe($.if(production, $.htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyJS: true,
minifyCSS: true,
processScripts: ["application/ld+json","application/json"]
})))
.pipe($.if(production, $.assetpaths({
newDomain: 'https://www.greenhousegames.com',
oldDomain : 'www.greenhousegames.com',
docRoot : 'public',
filetypes : ['jpg','jpeg','png','ico','gif','js','css']
})))
.pipe(gulp.dest(DIST));
});
gulp.task('sitemap', function() {
return gulp.src([
DIST + '/robots.txt',
DIST + '/**/*.html'
], {
read: false
})
.pipe($.sitemap({
siteUrl: 'https://www.greenhousegames.com'
}))
.pipe(gulp.dest(DIST));
});
gulp.task('finalcopy', function() {
var revFilter = $.filter([
DIST + "/assets/js/**/*",
DIST + "/assets/css/**/*"
], {restore: true});
var imgFilter = $.filter([
DIST + "/assets/img/**/*"
], {restore: true});
var sharedStream = gulp.src([
DIST + '/**/*'
])
.pipe(imgFilter)
.pipe($.imagemin())
.pipe(imgFilter.restore)
.pipe(revFilter)
.pipe($.rev())
.pipe(revFilter.restore)
.pipe($.revReplace());
if (production) {
return sharedStream
.pipe(gulp.dest('dist/release'));
} else {
return sharedStream
.pipe(gulp.dest('dist/debug'));
}
});