mirror of
https://github.com/LCE-Hub/LCE-Workshop.git
synced 2026-08-04 09:42:40 +00:00
fix: proper jsonc support
This commit is contained in:
parent
1c300f4b11
commit
c96c0a18e1
|
|
@ -1,11 +1,10 @@
|
|||
import { readdirSync, readFileSync, writeFileSync, statSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
import { parse } from "jsonc-parser";
|
||||
const OUTPUT_FILE = "./registry.json";
|
||||
const VALID_CATEGORIES = ["Skin", "Texture", "World", "Mod", "DLC"];
|
||||
const REQUIRED_FIELDS = ["id", "name", "author", "description", "extended_description", "category", "thumbnail", "zips", "version"];
|
||||
const IGNORED_DIRS = [".git", ".github", "scripts"];
|
||||
|
||||
function validateMeta(meta, pkgDir) {
|
||||
const errors = [];
|
||||
for (const field of REQUIRED_FIELDS) {
|
||||
|
|
@ -33,11 +32,6 @@ function validateMeta(meta, pkgDir) {
|
|||
|
||||
return errors;
|
||||
}
|
||||
|
||||
function stripJsonComments(str) {
|
||||
return str.replace(/\/\/[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
||||
}
|
||||
|
||||
const packages = [];
|
||||
const allErrors = [];
|
||||
let entries;
|
||||
|
|
@ -63,7 +57,7 @@ for (const entry of entries) {
|
|||
|
||||
let meta;
|
||||
try {
|
||||
meta = JSON.parse(stripJsonComments(raw));
|
||||
meta = parse(raw);
|
||||
} catch (e) {
|
||||
allErrors.push({ package: entry, errors: [`meta.json is invalid JSON: ${e.message}`] });
|
||||
continue;
|
||||
|
|
@ -96,4 +90,4 @@ const registry = {
|
|||
};
|
||||
|
||||
writeFileSync(OUTPUT_FILE, JSON.stringify(registry, null, 2));
|
||||
console.log(`registry.json generated with ${packages.length} package(s)`);
|
||||
console.log(`registry.json generated with ${packages.length} package(s)`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue