|
|
|
@ -8,20 +8,24 @@ export function getGitTimestamp(file: string) {
|
|
|
|
|
const cached = cache.get(file)
|
|
|
|
|
if (cached) return cached
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(file)) return 0
|
|
|
|
|
|
|
|
|
|
return new Promise<number>((resolve, reject) => {
|
|
|
|
|
const cwd = dirname(file)
|
|
|
|
|
if (!fs.existsSync(cwd)) return resolve(0)
|
|
|
|
|
const fileName = basename(file)
|
|
|
|
|
const child = spawn('git', ['log', '-1', '--pretty="%ai"', fileName], {
|
|
|
|
|
cwd
|
|
|
|
|
})
|
|
|
|
|
const child = spawn(
|
|
|
|
|
'git',
|
|
|
|
|
['log', '-1', '--pretty="%ai"', basename(file)],
|
|
|
|
|
{ cwd: dirname(file) }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let output = ''
|
|
|
|
|
child.stdout.on('data', (d) => (output += String(d)))
|
|
|
|
|
|
|
|
|
|
child.on('close', () => {
|
|
|
|
|
const timestamp = +new Date(output)
|
|
|
|
|
cache.set(file, timestamp)
|
|
|
|
|
resolve(timestamp)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
child.on('error', reject)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|