-
Notifications
You must be signed in to change notification settings - Fork 57
/
build.js
145 lines (123 loc) · 4.08 KB
/
build.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
'use strict';
const compiler = require('./js13k-compiler/src/compiler');
const JS_FILES = require('./config/js');
const CONSTANTS = require('./config/constants');
const MANGLE_SETTINGS = require('./config/mangle');
const optimizeMatrix = require('./macros/optimize-matrix');
const rawFile = require('./macros/raw-file');
function copy(obj) {
return JSON.parse(JSON.stringify(obj));
}
compiler.run((tasks) => {
function buildJS({
mangle,
uglify
}) {
// Manually injecting the DEBUG constant
const constants = copy(CONSTANTS);
constants.DEBUG = !uglify;
// Inject some computed constants
constants.LEVEL_WIDTH = constants.LEVEL_COLS * constants.CELL_SIZE;
constants.LEVEL_HEIGHT = constants.LEVEL_ROWS * constants.CELL_SIZE;
constants.TOWER_BASE_HEIGHT = (constants.CANVAS_HEIGHT - constants.LEVEL_HEIGHT) / 2,
constants.LEVEL_X = constants.CANVAS_WIDTH / 2 - constants.LEVEL_COLS * constants.CELL_SIZE / 2;
const sequence = [
tasks.label('Building JS'),
tasks.loadFiles(JS_FILES),
tasks.concat(),
tasks.macro('optimizeMatrix', optimizeMatrix),
tasks.constants(constants),
tasks.macro('evaluate'),
tasks.macro('nomangle'),
tasks.macro('rawFile', rawFile),
];
if (mangle) {
sequence.push(tasks.mangle(MANGLE_SETTINGS));
}
if (uglify) {
sequence.push(tasks.uglifyES());
}
return tasks.sequence(sequence);
}
function buildCSS(uglify) {
const sequence = [
tasks.label('Building CSS'),
tasks.loadFiles([__dirname + "/src/style.css"]),
tasks.concat()
];
if (uglify) {
sequence.push(tasks.uglifyCSS());
}
return tasks.sequence(sequence);
}
function buildHTML(uglify) {
const sequence = [
tasks.label('Building HTML'),
tasks.loadFiles([__dirname + "/src/index.html"]),
tasks.concat()
];
if (uglify) {
sequence.push(tasks.uglifyHTML());
}
return tasks.sequence(sequence);
}
function buildMain() {
return tasks.sequence([
tasks.block('Building main files'),
tasks.parallel({
'js': buildJS({
'mangle': true,
'uglify': true
}),
'css': buildCSS(true),
'html': buildHTML(true)
}),
tasks.combine(),
tasks.output(__dirname + '/build/index.html'),
tasks.label('Building ZIP'),
tasks.zip('index.html'),
tasks.output(__dirname + '/build/game.zip'),
tasks.checkSize(__dirname + '/build/game.zip'),
tasks.advzip(__dirname + '/build/game.zip'),
tasks.checkSize(__dirname + '/build/game.zip'),
]);
}
function buildDebug({
mangle,
suffix
}) {
return tasks.sequence([
tasks.block('Building debug files'),
tasks.parallel({
// Debug JS in a separate file
'debug_js': tasks.sequence([
buildJS({
'mangle': mangle,
'uglify': false
}),
tasks.output(__dirname + '/build/debug' + suffix + '.js')
]),
// Injecting the debug file
'js': tasks.inject(['debug' + suffix + '.js']),
'css': buildCSS(false),
'html': buildHTML(false)
}),
tasks.combine(),
tasks.output(__dirname + '/build/debug' + suffix + '.html')
]);
}
function main() {
return tasks.sequence([
buildMain(),
buildDebug({
'mangle': false,
'suffix': ''
}),
buildDebug({
'mangle': true,
'suffix': '_mangled'
})
]);
}
return main();
});