chore: Converting a bash script into a javascript file

This commit is contained in:
J M
2022-02-21 15:17:28 -07:00
committed by Aiden McClelland
parent 42e1a02a61
commit b64785250f
3 changed files with 29 additions and 9 deletions

27
frontend/update-git-hash.js Executable file
View File

@@ -0,0 +1,27 @@
// @ts-check
const fs = require('fs')
const childProcess = require('child_process')
const gitHash = String(childProcess.execSync('git rev-parse HEAD')).trim()
/**
* @template T
* @param {() => T} fn
* @param {T} defaultValue
* @returns
*/
function catchDefault(fn, defaultValue) {
try {
return fn()
} catch {
return defaultValue
}
}
const origConfig = catchDefault(
/** @returns {{gitHash?: string}} */
() => JSON.parse(fs.readFileSync('./config.json')),
{},
)
origConfig.gitHash = gitHash
fs.writeFileSync('./config.json', JSON.stringify(origConfig, null, 2))