added commit date to p2p info

This commit is contained in:
mrfry
2023-04-12 12:05:23 +02:00
parent d99bb0fedc
commit b6215f50fb
4 changed files with 36 additions and 14 deletions
+13 -4
View File
@@ -37,7 +37,7 @@ export default {
renameFile: renameFile,
deleteDir: deleteDir,
formatBytes: formatBytes,
getGitRevision: getGitRevision,
getGitInfo: getGitInfo,
getScriptVersion: getScriptVersion,
}
@@ -314,17 +314,26 @@ function formatBytes(number: number, unit: 'MB' | 'GB' = 'MB'): string {
return `${number} byte`
}
function getGitRevision(dir: string): string {
function getGitInfo(dir: string): { lastCommitDate: number; revision: string } {
try {
return child_process
const revision = child_process
.execSync('git rev-parse HEAD', {
cwd: dir,
stdio: [0, 'pipe', null],
})
.toString()
.trim()
const lastCommitDate = child_process
.execSync(`git show -s --format=%ct ${revision}`, {
cwd: dir,
stdio: [0, 'pipe', null],
})
.toString()
.trim()
return { lastCommitDate: +lastCommitDate, revision: revision }
} catch (e) {
return 'Failed to get revision'
return { lastCommitDate: 0, revision: 'Failed to get revision' }
}
}