-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.js
116 lines (96 loc) · 3.13 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
'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');
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;
const sequence = [
tasks.label('Building JS'),
tasks.loadFiles(JS_FILES),
tasks.concat(),
tasks.constants(constants),
tasks.macro('evaluate'),
tasks.macro('nomangle')
];
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(true, 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, 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(false, ''),
buildDebug(true, '_mangled')
]);
}
return main();
});