@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands
39 lines (36 loc) • 1.79 kB
JavaScript
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
import { join } from '@visulima/path';
import parseManifest from './parseManifest-Dbp-Q2q3.mjs';
const CONTROL_CHARS = /[\u0000-\u001F\u007F-\u009F]/gu;
const stripControlChars = (value) => value === void 0 ? void 0 : value.replaceAll(CONTROL_CHARS, "");
const listItemDirectories = (root) => readdirSync(root).filter((entry) => {
const full = join(root, entry);
return statSync(full).isDirectory() && existsSync(join(full, "registry.json"));
});
const collectCatalog = (root) => {
const indexPath = join(root, "index.json");
if (existsSync(indexPath)) {
const parsed = JSON.parse(readFileSync(indexPath, "utf8"));
if (Array.isArray(parsed.items)) {
return parsed.items.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.name === "string").map((entry) => {
return { description: stripControlChars(entry.description), name: stripControlChars(entry.name) ?? entry.name };
});
}
}
return listItemDirectories(root).map((name) => {
const raw = JSON.parse(readFileSync(join(root, name, "registry.json"), "utf8"));
return { description: stripControlChars(raw.description), name };
});
};
const buildRegistryIndex = (root) => {
const items = listItemDirectories(root).map((name) => {
const manifest = parseManifest(JSON.parse(readFileSync(join(root, name, "registry.json"), "utf8")), name);
return {
...manifest.description === void 0 ? {} : { description: manifest.description },
name: manifest.name,
...manifest.title === void 0 ? {} : { title: manifest.title }
};
}).toSorted((a, b) => a.name.localeCompare(b.name));
return { items };
};
export { buildRegistryIndex, collectCatalog, listItemDirectories };