Push new data
All checks were successful
On Push Deploy / deploy (push) Successful in 37s

This commit is contained in:
Johnny322
2026-02-08 22:10:43 +01:00
parent dfe26530c4
commit 0e243d8faa
136 changed files with 118 additions and 89 deletions

View File

@@ -0,0 +1,68 @@
import fs from 'fs'
import path from 'path'
const projectRoot = process.cwd()
const dataRoot = path.join(projectRoot, 'public', 'Data')
const outputPath = path.join(projectRoot, 'public', 'data.json')
const isDirectory = (target) => {
try {
return fs.statSync(target).isDirectory()
} catch {
return false
}
}
const listDirectories = (target) => {
if (!isDirectory(target)) return []
return fs.readdirSync(target).filter((entry) => isDirectory(path.join(target, entry)))
}
const buildManifest = () => {
const games = []
const gameNames = listDirectories(dataRoot)
gameNames.forEach((gameName) => {
const gamePath = path.join(dataRoot, gameName)
const categories = []
const categoryNames = listDirectories(gamePath)
categoryNames.forEach((categoryName) => {
const songsDir = path.join(gamePath, categoryName, 'Songs')
const answersDir = path.join(gamePath, categoryName, 'Answers')
const clues = []
for (let i = 1; i <= 5; i += 1) {
const songPath = path.join('Data', gameName, categoryName, 'Songs', `${i}.mp3`)
const answerPath = path.join('Data', gameName, categoryName, 'Answers', `${i}.mp3`)
const songExists = fs.existsSync(path.join(dataRoot, gameName, categoryName, 'Songs', `${i}.mp3`))
const answerExists = fs.existsSync(
path.join(dataRoot, gameName, categoryName, 'Answers', `${i}.mp3`)
)
clues.push({
number: i,
points: i * 100,
song: songExists ? `/${songPath.replace(/\\/g, '/')}` : null,
answer: answerExists ? `/${answerPath.replace(/\\/g, '/')}` : null
})
}
categories.push({
name: categoryName,
clues
})
})
games.push({
name: gameName,
categories
})
})
return games
}
const main = () => {
if (!isDirectory(dataRoot)) {
fs.writeFileSync(outputPath, JSON.stringify([], null, 2))
return
}
const manifest = buildManifest()
fs.writeFileSync(outputPath, JSON.stringify(manifest, null, 2))
}
main()