forked from tobspr-games/shapez.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildutils.js
44 lines (39 loc) · 1.39 KB
/
buildutils.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
const glob = require("glob");
const execSync = require("child_process").execSync;
const trim = require("trim");
const fs = require("fs");
const path = require("path");
module.exports = {
getRevision: function (useLast = false) {
const commitHash = execSync("git rev-parse --short " + (useLast ? "HEAD^1" : "HEAD")).toString("ascii");
return commitHash.replace(/^\s+|\s+$/g, "");
},
getAllResourceImages() {
return glob
.sync("res/**/*.@(png|svg|jpg)", { cwd: ".." })
.map((f) => f.replace(/^res\//gi, ""))
.filter((f) => {
if (f.indexOf("ui") >= 0) {
// We drop all ui images except for the noinline ones
return f.indexOf("noinline") >= 0;
}
return true;
});
},
getAllAtlasImages() {
return glob.sync("res_built/atlas/*.png", { cwd: ".." }).map((s) => s.replace("res_built/atlas/", "res/"));
},
getAllSounds() {
return glob.sync("res_built/sounds/**/*.mp3", { cwd: ".." }).map((s) => s.replace("res_built/sounds/", "res/sounds/"));
},
getVersion() {
return trim(fs.readFileSync(path.join(__dirname, "version")).toString());
},
/**
* @param {string} url
* @param {string} commitHash
*/
cachebust(url, commitHash) {
return "/v/" + commitHash + "/" + url;
},
};