diff --git a/scripts/registry.js b/scripts/registry.js index 9d78c0e..497abcc 100644 --- a/scripts/registry.js +++ b/scripts/registry.js @@ -3,11 +3,13 @@ import { join } from "path"; import { parse } from "jsonc-parser"; const OUTPUT_FILE = "./registry.json"; const OUTPUT_FILE2 = "./versions.json"; //neo: version listing lmao +const OUTPUT_FILE3 = "./plugins.json" //neo: emerald plugins const VALID_CATEGORIES = ["Skin", "Texture", "World", "Mod", "DLC"]; const VALID_CATEGORIES2 = ["Vanilla", "Modded", "Modpack", "Fork", "Random"]; const REQUIRED_FIELDS = ["id", "name", "author", "description", "extended_description", "category", "thumbnail", "zips", "version"]; const REQUIRED_FIELDS2 = ["id", "name", "author", "description", "extended_description", "thumbnail", "url", "version", "logo"]; -const IGNORED_DIRS = [".git", ".github", "scripts", "node_modules", ".00versions"]; +const REQUIRED_FIELDS3 = ["id", "name", "author", "description", "main", "permissions", "extended_description", "version"]; +const IGNORED_DIRS = [".git", ".github", "scripts", "node_modules", ".00versions", ".00plugins"]; function validateMeta(meta, pkgDir) { const errors = []; for (const field of REQUIRED_FIELDS) { @@ -64,14 +66,36 @@ function validateVersionMeta(meta, pkgDir) { return errors; } +function validatePluginMeta(meta, pkgDir) { + const errors = []; + for (const field of REQUIRED_FIELDS3) { + if (meta[field] === undefined || meta[field] === null) { + errors.push(`missing required field: "${field}"`); + } + } + + if (meta.id && meta.id !== pkgDir) { + errors.push(`id "${meta.id}" does not match folder name "${pkgDir}"`); + } + + if (meta.version && !/^\d+\.\d+\.\d+$/.test(meta.version)) { + errors.push(`version "${meta.version}" is not valid semver (expected x.y.z)`); + } + + return errors; +} + const packages = []; const versionlist = []; +const pluginlist = []; const allErrors = []; let entries; let entries2; +let entries3; try { entries = readdirSync("."); entries2 = readdirSync(".00versions"); //neo: dont ask about the name. + entries3 = readdirSync(".00plugins"); //neo: same comment as above. } catch { console.error(`how the hell did you run me if the directory doesn't exist???`); process.exit(1); @@ -134,6 +158,35 @@ for (const entry of entries2) { versionlist.push(meta); } + +for (const entry of entries3) { + const pkgPath = ".00plugins/"+entry; + if (!statSync(pkgPath).isDirectory()) continue; + const metaPath = join(pkgPath, "meta.json"); + let raw; + try { + raw = readFileSync(metaPath, "utf8"); + } catch { + allErrors.push({ package: entry, errors: ["meta.json not found (in plugin)"] }); + continue; + } + let meta; + try { + meta = parse(raw); + } catch (e) { + allErrors.push({ package: entry, errors: [`meta.json is invalid JSON: ${e.message} (in plugin)`] }); + continue; + } + + const errors = validatePluginMeta(meta, entry); + if (errors.length > 0) { + allErrors.push({ package: entry, errors }); + continue; + } + + pluginlist.push(meta); +} + if (allErrors.length > 0) { console.error("Validation failed:\n"); for (const { package: pkg, errors } of allErrors) { @@ -157,7 +210,15 @@ const versions = { versionlist, }; +const plugins = { + generated_at: new Date().toISOString(), + count: pluginlist.length, + pluginlist, +}; + writeFileSync(OUTPUT_FILE, JSON.stringify(registry, null, 2)); console.log(`registry.json generated with ${packages.length} package(s)`); writeFileSync(OUTPUT_FILE2, JSON.stringify(versions, null, 2)); console.log(`versions.json generated with ${versionlist.length} version(s)`); +writeFileSync(OUTPUT_FILE3, JSON.stringify(plugins, null, 2)); +console.log(`plugins.json generated with ${pluginlist.length} plugin(s)`);