-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
175 lines (149 loc) · 3.96 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const gulp = require('gulp');
const del = require('del');
const minifyLua = require('./tools/luamin');
const compileMoonscript = require('./tools/moonscript');
const optimizeLua = require ('./tools/optimizations');
const discourageLuaMod = require ('./tools/discourageLuaModification');
const lastRunCache = new Map();
function lastRunIgnoreErrors(task) {
const lastRun = gulp.lastRun(task);
if(lastRun) {
lastRunCache.set(task, lastRun);
return lastRun;
}
else {
return lastRunCache.get(task);
}
}
const MATERIAL_GLOBS = [
'src/materials/**/*',
'!src/materials/**/*.svg',
];
const SOUND_GLOBS = [
'src/sound/**/*',
];
const MODEL_GLOBS = [
'src/models/**/*',
];
const METADATA_GLOBS = [
'src/addon.json',
];
/**
* Cleans the build.
*/
function clean() {
return del(['dest/**/*']);
}
clean.description = "Cleans the build.";
/**
* Minifies lua files.
*/
function lua() {
return gulp.src('src/**/*.lua', { since: lastRunIgnoreErrors(lua) })
.pipe(optimizeLua())
.pipe(minifyLua())
.pipe(gulp.dest('dest', { mode: 0777 }));
}
lua.description = "Copies and minifies lua files.";
/**
* Compiles moonscript files.
*/
function moon() {
return gulp.src('src/**/*.moon', { since: lastRunIgnoreErrors(moon) })
.pipe(compileMoonscript())
.pipe(optimizeLua())
.pipe(discourageLuaMod())
// .pipe(minifyLua())
.pipe(gulp.dest('dest', { mode: 0777 }));
}
moon.description = "Compiles moonscript files.";
/**
* Builds the addon scripts.
*/
const scripts = gulp.parallel(lua, moon);
scripts.description = "Builds the addon scripts.";
/**
* Watches lua files and compiles changes.
*/
function watchScripts() {
return gulp.watch(
['src/**/*.lua', 'src/**/*.moon']
, scripts
)
}
watchScripts.displayName = "watch-scripts";
watchScripts.description = "Watches lua and moon files and compiles changes.";
/**
* Copies materials.
*/
function materials() {
return gulp.src(MATERIAL_GLOBS, { since: lastRunIgnoreErrors(materials) })
.pipe(gulp.dest('dest/materials/', { mode: 0777 }));
}
materials.description = "Copies materials.";
/**
* Copies sound files.
*/
function sound() {
return gulp.src(SOUND_GLOBS, { since: lastRunIgnoreErrors(materials) })
.pipe(gulp.dest('dest/sound/', { mode: 0777 }));
}
materials.description = "Copies sound files.";
/**
* Copies model files.
*/
function model() {
return gulp.src(MODEL_GLOBS, { since: lastRunIgnoreErrors(materials) })
.pipe(gulp.dest('dest/models/', { mode: 0777 }));
}
materials.description = "Copies model files.";
/**
* Copies metadata files.
*/
function metadata() {
return gulp.src(METADATA_GLOBS, { since: lastRunIgnoreErrors(materials) })
.pipe(gulp.dest('dest', { mode: 0777 }));
}
materials.description = "Copies metadata files.";
/**
* Generates and moves assets.
*/
const assets = gulp.parallel(materials, sound, model, metadata);
assets.description = "Generates and copies assets.";
/**
* Watches asset files and compiles/copies changes.
*/
function watchAssets() {
return gulp.watch(
[
...MATERIAL_GLOBS,
...SOUND_GLOBS,
...MODEL_GLOBS,
...METADATA_GLOBS,
]
, assets
)
}
watchAssets.displayName = "watch-assets";
watchAssets.description = "Watches assets.";
/**
* Builds everything.
*/
const build = gulp.parallel(scripts, assets);
build.description = "Builds everything.";
/**
* Cleans and builds the project, and then watches files for changes.
*/
const watch = gulp.series(clean, build, gulp.parallel(watchAssets, watchScripts));
watch.description = "Cleans and builds the project, and then watches files for changes.";
exports.clean = clean;
exports.materials = materials;
exports.assets = assets;
exports.watchAssets = watchAssets;
exports.lua = lua;
exports.moon = moon;
exports.scripts = scripts;
exports.watchScripts = watchScripts;
exports.build = build;
exports.watch = watch;
exports.default = watch;