1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 09:11:50 +00:00
tobspr_shapez.io/gulp/buildutils.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

import glob from "glob";
import { execSync } from "child_process";
import fs from "fs";
import path from "path/posix";
2020-05-09 14:45:23 +00:00
export function getRevision(useLast = false) {
const commitHash = execSync("git rev-parse --short " + (useLast ? "HEAD^1" : "HEAD")).toString("ascii");
return commitHash.replace(/^\s+|\s+$/g, "");
}
export function 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;
});
}
2020-05-09 14:45:23 +00:00
export function getTag() {
try {
return execSync("git describe --tag --exact-match").toString("ascii");
} catch (e) {
throw new Error("Current git HEAD is not a version tag");
}
}
export function getVersion() {
return fs.readFileSync(path.join("..", "version")).toString().trim();
}
2020-05-09 14:45:23 +00:00
/**
* @param {string} url
* @param {string} commitHash
*/
export function cachebust(url, commitHash) {
return "/v/" + commitHash + "/" + url;
}