Preview: Dev-Modus nur mit dev-Skript waehlbar
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5cb668853
commit
04b45e4207
5 files changed
+159
-7
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// Prueft, ob ein Repo-Branch ein dev-Skript in package.json hat (Dev-Modus nur dann sinnvoll).
|
||||
import { giteaFetch, splitRepo } from './giteaClient.js'
|
||||
|
||||
export const cacheTtlMs = 60 * 1000
|
||||
const cache = new Map()
|
||||
|
||||
export function clearDevScriptCache() { cache.clear() }
|
||||
|
||||
/** true = dev-Skript vorhanden, false = kein package.json oder kein dev-Skript, null = unbekannt (Gitea-Fehler). */
|
||||
export async function repoHasDevScript(repoFullName, branch) {
|
||||
const key = `${repoFullName}@${branch}`
|
||||
const hit = cache.get(key)
|
||||
if (hit && Date.now() - hit.at < cacheTtlMs) return hit.value
|
||||
const value = await lookup(repoFullName, branch)
|
||||
cache.set(key, { at: Date.now(), value })
|
||||
return value
|
||||
}
|
||||
|
||||
async function lookup(repoFullName, branch) {
|
||||
const [owner, repo] = splitRepo(repoFullName)
|
||||
if (!owner || !repo) return null
|
||||
let data
|
||||
try {
|
||||
data = await giteaFetch(`/repos/${owner}/${repo}/contents/package.json?ref=${encodeURIComponent(branch)}`)
|
||||
} catch (err) {
|
||||
return err?.status === 404 ? false : null
|
||||
}
|
||||
try {
|
||||
const pkg = JSON.parse(Buffer.from(data?.content || '', 'base64').toString('utf8'))
|
||||
const dev = pkg?.scripts?.dev
|
||||
return typeof dev === 'string' && dev.trim() !== ''
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user