Files
RuneStone/scripts/menuSurfaceAudit.mjs
T
Knotty Wyvern 5e1533c371 Make Table Formulas a built-in feature
The formula engine, the rendered results, and the formula help now
come from src/lib/formulas/. The editor and the renderer call this
module directly. The tableFormulas contribution type is removed.

- Add the tableFormulas general setting (default on) and a switch in
  Settings > General. When it is off, formulas show as source text.
- Do not load an installed runestone.table-formulas package. Settings
  > Plug-ins marks it as included with RuneStone and tells the user
  that it can be removed. The user's files stay in place.
- Translate the formula help and the error descriptions into French,
  Japanese, and Simplified Chinese.
- Port the plugin unit tests. Test the setting and use a test-only
  contribution for the generic plugin lifecycle tests.
- Smoke tests load only Terminal. The formula and lifecycle tests use
  the built-in feature and its setting.
- Remove scripts/buildPlugins.mjs, the build:plugins script, and the
  plugin-packages requirement of the smoke runner.
- Remove RuneStone_Table_Formulas from the menu audit scope. It had no
  menu surfaces.
- Update the README, the user guides, and the developer references.
2026-10-28 01:05:43 -07:00

61 lines
3.7 KiB
JavaScript

import { readdir, readFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('../', import.meta.url));
const pluginRepos = process.env.RUNESTONE_PLUGIN_REPOS || path.resolve(root, '..');
export const projects = ['RuneStone', 'RuneStone_Project_Management', 'RuneStone_Terminal', 'RuneStone_Background_Slideshow', 'RuneStone_Local_Autocomplete', 'RuneStone_Git', 'RuneStone_PDF_Viewer', 'RuneStone_CSV_Viewer'];
const patterns = {
action: /\b(?:showActionMenu|actionMenu)\s*\(/g,
svelteMenu: /<ContextMenu\b/g,
nativeChoice: /<select\b|(?:createElement|el)\(\s*['"]select['"]/g,
picker: /rs-picker(?:[\s"']|$)|role=['"]listbox['"]|setAttribute\(\s*['"]role['"],\s*['"]listbox['"]/g,
localPopup: /(?:class|className)\s*=\s*['"][^'"\n]*(?:menu|picker|popup)|\.popover\s*=/g,
};
async function files(dir) {
const entries = await readdir(dir, { withFileTypes: true });
const results = await Promise.all(entries.filter(entry => !entry.isSymbolicLink()).map(entry => entry.isDirectory()
? files(path.join(dir, entry.name)) : /\.(svelte|[cm]?[jt]s)$/.test(entry.name) ? [path.join(dir, entry.name)] : []));
return results.flat();
}
export async function discover() {
const surfaces = {}, missing = [];
for (const project of projects) {
const base = project === 'RuneStone' ? root : path.resolve(pluginRepos, project);
let sources;
try { sources = await files(path.join(base, 'src')); } catch (error) { if (error.code === 'ENOENT') { missing.push(project); continue; } throw error; }
for (const file of sources) {
const source = await readFile(file, 'utf8');
const counts = Object.fromEntries(Object.entries(patterns).map(([name, pattern]) => [name, [...source.matchAll(pattern)].length]).filter(([, count]) => count));
if (Object.keys(counts).length) surfaces[`${project}/${path.relative(base, file).replaceAll('\\', '/')}`] = counts;
}
}
return { surfaces, missing };
}
export async function checkInventory() {
const { surfaces, missing } = await discover();
const inventory = JSON.parse(await readFile(path.join(root, 'docs/menu-surfaces.json'), 'utf8'));
const failures = missing.map(project => `Missing checkout: ${project}`);
for (const [file, counts] of Object.entries(surfaces)) {
const entry = inventory.surfaces[file];
if (!entry) failures.push(`Unreviewed surface: ${file}`);
else if (JSON.stringify(counts) !== JSON.stringify(entry.counts)) failures.push(`Changed entry points: ${file}`);
else if (!entry.design || !entry.check) failures.push(`Missing design or check: ${file}`);
}
for (const file of Object.keys(inventory.surfaces)) if (!(file in surfaces)) failures.push(`Stale inventory: ${file}`);
for (const name of ['actionMenu.ts', 'managedActionMenu.ts', 'IconButton.svelte']) {
try {
const host = await readFile(path.join(root, 'src/lib/ui', name), 'utf8');
const terminal = await readFile(path.resolve(pluginRepos, 'RuneStone_Terminal/vendor/runestone/ui', name), 'utf8');
if (host.replaceAll('\r\n', '\n') !== terminal.replaceAll('\r\n', '\n')) failures.push(`Terminal shared snapshot differs: ${name}`);
} catch (error) { failures.push(`Cannot check Terminal snapshot ${name}: ${error.code}`); }
}
if (failures.length) { console.error(failures.join('\n')); return false; }
console.log(`PASS: ${Object.keys(surfaces).length} source files across ${projects.length} projects match the reviewed menu inventory. Runtime checks remain separate.`);
return true;
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
if (process.argv.includes('--discover')) console.log(JSON.stringify(await discover(), null, 2));
else if (!await checkInventory()) process.exitCode = 1;
}