1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-06-15 08:59:18 +00:00

feat: Add an updated field to the card field (#460)

This commit is contained in:
2024-05-12 00:51:56 +02:00
committed by GitHub
parent e4aba3bf1c
commit c476d82618
6 changed files with 76 additions and 5 deletions

View File

@ -1,3 +1,4 @@
import { exec } from 'node:child_process'
import { glob } from 'glob'
import { Card, Set } from '../../../interfaces'
import * as legals from '../../../meta/legals'
@ -79,3 +80,45 @@ export function setIsLegal(type: 'standard' | 'expanded', set: Set): boolean {
}
return false
}
function runCommand(command: string): Promise<string> {
return new Promise<string>((res, rej) => {
exec(command, (err, out) => {
if (err) {
rej(err)
return
}
res(out)
})
})
}
let lastEditsCache: Record<string, string> = {}
export async function loadLastEdits() {
const firstCommand = 'git ls-tree -r --name-only HEAD ../data'
const files = (await runCommand(firstCommand)).split('\n')
console.log('Loaded files tree', files.length, 'files')
console.log('Loading their last edit time')
let processed = 0
for (let file of files) {
file = file.replace(/"/g, '').replace("\\303\\251", "é")
try {
lastEditsCache[file] = await runCommand(`git log -1 --pretty="format:%cd" --date=iso-strict "${file}"`)
} catch {
console.warn('could not load file', file, 'hope it does not break everything else lol')
}
processed++
if (processed % 1000 === 0) {
console.log('loaded', processed, 'out of', files.length, 'files')
}
}
console.log('done loading files')
}
export function getLastEdit(path: string): string {
const date = lastEditsCache[path]
if (!date) {
throw new Error(`edit date not found for file ${path}`)
}
return date
}