2022-12-03 04:23:18 +00:00
|
|
|
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
|
|
|
|
2022-12-03 04:23:18 +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, "");
|
|
|
|
|
}
|
2020-08-07 07:16:23 +00:00
|
|
|
|
2022-12-03 04:23:18 +00:00
|
|
|
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
|
|
|
|
2022-12-03 04:23:18 +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");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-27 21:14:43 +00:00
|
|
|
|
2022-12-03 04:23:18 +00:00
|
|
|
export function getVersion() {
|
|
|
|
|
return fs.readFileSync(path.join("..", "version")).toString().trim();
|
|
|
|
|
}
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2022-12-03 04:23:18 +00:00
|
|
|
/**
|
|
|
|
|
* @param {string} url
|
|
|
|
|
* @param {string} commitHash
|
|
|
|
|
*/
|
|
|
|
|
export function cachebust(url, commitHash) {
|
|
|
|
|
return "/v/" + commitHash + "/" + url;
|
|
|
|
|
}
|