[web] Change the command to fetch the git SHA

To make the git command work on Windows, changed it to use different commands depending on the platform of the OS.
This commit is contained in:
LI-NA 2024-03-25 20:10:38 +09:00
parent 37dce2bdb5
commit b98da635b6

View file

@ -11,6 +11,7 @@
*/
const cp = require("child_process");
const os = require("os");
/**
* Return the current commit ID if we're running inside a git repository.
@ -18,8 +19,17 @@ const cp = require("child_process");
const gitSHA = () => {
// Allow the command to fail. gitSHA will be an empty string in such cases.
// This allows us to run the build even when we're outside of a git context.
//
// The /dev/null redirection is needed so that we don't print error messages
// if someone is trying to run outside of a git context. Since the way to
// redirect output and ignore failure is different on Windows, the command
// needs to be OS specific.
const command =
os.platform() == "win32"
? "git rev-parse --short HEAD 2> NUL || cd ."
: "git rev-parse --short HEAD 2>/dev/null || true";
const result = cp
.execSync("git rev-parse --short HEAD 2>/dev/null || true", {
.execSync(command, {
cwd: __dirname,
encoding: "utf8",
})