This repository has been archived on 2021-02-20. You can view files and clone it, but cannot push or open issues or pull requests.
shapez.io/gulp/buildutils.js

48 lines
1.3 KiB
JavaScript

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;
});
},
getTag() {
try {
return execSync("git describe --tag --exact-match").toString("ascii");
} catch (e) {
throw new Error('Current git HEAD is not a version tag');
}
},
getVersion() {
return trim(fs.readFileSync(path.join(__dirname, "..", "version")).toString());
},
/**
* @param {string} url
* @param {string} commitHash
*/
cachebust(url, commitHash) {
return "/v/" + commitHash + "/" + url;
},
};