feat(build): sync vendored directories from GitHub on start and build

Adds sync-directories.js script that fetches 5chan-directories.json from bitsocialhq/lists and updates the vendored fallback. Runs before generate:assets in prestart and prebuild to ensure the fallback is fresh for every build. Non-fatal: if fetch fails, existing file is kept.
This commit is contained in:
plebeius
2026-02-15 14:14:21 +08:00
parent 44847b7e95
commit 8645f7365a
3 changed files with 147 additions and 5 deletions
+3 -2
View File
@@ -48,8 +48,9 @@
},
"scripts": {
"generate:assets": "node scripts/generate-asset-manifest.js",
"prebuild": "yarn generate:assets",
"prestart": "yarn generate:assets",
"sync:directories": "node scripts/sync-directories.js",
"prebuild": "yarn sync:directories && yarn generate:assets",
"prestart": "yarn sync:directories && yarn generate:assets",
"start": "vite",
"build": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=false vite build",
"build:preload": "vite build --config electron/vite.preload.config.js",
+57
View File
@@ -0,0 +1,57 @@
// Best-effort sync of 5chan-directories.json from GitHub
// Updates the vendored fallback in src/data/ so production builds ship a fresh snapshot.
// Never fails the build — if the fetch fails (offline, rate-limited, etc.), the existing file is kept.
import { writeFileSync, readFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const GITHUB_URL = 'https://raw.githubusercontent.com/bitsocialhq/lists/master/5chan-directories.json';
const OUTPUT_PATH = join(__dirname, '..', 'src', 'data', '5chan-directories.json');
const TIMEOUT_MS = 5000;
const sync = async () => {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS);
const response = await fetch(GITHUB_URL, { signal: controller.signal });
clearTimeout(timeout);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
// Basic sanity check — must have a communities array
if (!Array.isArray(data?.communities) || data.communities.length === 0) {
throw new Error('Invalid data: missing or empty communities array');
}
const formatted = JSON.stringify(data, null, 2) + '\n';
// Only write if content actually changed
let existing = '';
try {
existing = readFileSync(OUTPUT_PATH, 'utf8');
} catch {
// file doesn't exist yet
}
if (formatted === existing) {
console.log('✅ Vendored directories already up to date');
return;
}
writeFileSync(OUTPUT_PATH, formatted, 'utf8');
console.log(`✅ Synced vendored directories (${data.communities.length} communities)`);
} catch (e) {
console.warn(`⚠️ Could not sync directories from GitHub (keeping existing file): ${e.message}`);
}
};
sync();
+87 -3
View File
@@ -1,6 +1,6 @@
{
"title": "5chan directories",
"description": "Each 5chan directory is assigned to a board (subplebbit) handpicked by the team, until DAO curation is implemented.\n\nhttps://github.com/plebbit/temporary-default-subplebbits",
"title": "/all/ - All 5chan Directories",
"description": "Each 5chan directory is assigned to a board handpicked by the team, until DAO curation is implemented.\n\nhttps://github.com/bitsocialhq/lists/blob/master/5chan-directories.json",
"createdAt": 1762179811,
"updatedAt": 1762179811,
"communities": [
@@ -13,7 +13,91 @@
"title": "/biz/ - Business & Finance",
"address": "business-and-finance.eth",
"nsfw": false
},
{
"title": "/sci/ - Science & Math",
"address": "science-and-math.eth",
"nsfw": false
},
{
"title": "/g/ - Technology",
"address": "technology-posting.eth",
"nsfw": false
},
{
"title": "/vg/ - Video Game Generals",
"address": "videogame-generals.eth",
"nsfw": false
},
{
"title": "/fit/ - Fitness",
"address": "fitness-posting.eth",
"nsfw": false
},
{
"title": "/adv/ - Advice",
"address": "advice-posting.eth",
"nsfw": false
},
{
"title": "/wsg/ - Worksafe GIF",
"address": "worksafe-gif.eth",
"nsfw": false
},
{
"title": "/diy/ - Do It Yourself",
"address": "do-it-yourself.eth",
"nsfw": false
},
{
"title": "/out/ - Outdoors",
"address": "outdoors-posting.eth",
"nsfw": false
},
{
"title": "/ic/ - Artwork/Critique",
"address": "artwork-critique.eth",
"nsfw": false
},
{
"title": "/mu/ - Music",
"address": "music-posting.eth",
"nsfw": false
},
{
"title": "/int/ - International",
"address": "international-sfw.eth",
"nsfw": false
},
{
"title": "/lit/ - Literature",
"address": "literature-posting.eth",
"nsfw": false
},
{
"title": "/tv/ - Television & Film",
"address": "television-and-film.eth",
"nsfw": false
},
{
"title": "/vip/ - Very Important Posts",
"address": "very-important-posts.eth",
"nsfw": false
},
{
"title": "/gif/ - Adult GIF",
"address": "adult-gif.eth",
"nsfw": true
},
{
"title": "/bant/ - International/Random",
"address": "international-nsfw.eth",
"nsfw": true
},
{
"title": "/b/ - Random",
"address": "random-nsfw.eth",
"nsfw": true
}
]
}