mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 18:31:52 +00:00
28 lines
589 B
JavaScript
Executable File
28 lines
589 B
JavaScript
Executable File
// @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))
|