Files
indiekit-server/scripts/patch-store-github-error-message.mjs
Sven e0a48dc787
Deploy Indiekit Server / deploy (push) Failing after 4s
fix: update all gitea.giersig.eu refs to git.wildwuchs.work
2026-05-14 19:48:19 +02:00

56 lines
1.5 KiB
JavaScript

import { access, readFile, writeFile } from "node:fs/promises";
const candidates = [
"node_modules/@indiekit/store-github/index.js",
];
const MARKER = "// [patched] store-github-error-message";
const OLD_SNIPPET = ` \`Ensure the GitHub token is not expired and has the necessary permissions\`,
\`You can check your tokens here: https://github.com/settings/tokens\`,`;
const NEW_SNIPPET = ` \`Ensure the Gitea token is not expired and has the necessary permissions\`,
\`You can check your tokens here: https://git.wildwuchs.work/user/settings/applications\`, ${MARKER}`;
async function exists(path) {
try {
await access(path);
return true;
} catch {
return false;
}
}
let checked = 0;
let patched = 0;
for (const filePath of candidates) {
if (!(await exists(filePath))) {
continue;
}
checked += 1;
const source = await readFile(filePath, "utf8");
if (source.includes(MARKER)) {
console.log("[postinstall] store-github error message already patched");
continue;
}
if (!source.includes(OLD_SNIPPET)) {
console.warn("[postinstall] store-github: unexpected source layout, skipping");
continue;
}
const updated = source.replace(OLD_SNIPPET, NEW_SNIPPET);
await writeFile(filePath, updated, "utf8");
patched += 1;
}
if (checked === 0) {
console.log("[postinstall] No store-github index.js found");
} else if (patched > 0) {
console.log(`[postinstall] Patched store-github error message in ${patched} file(s)`);
}