File size: 1,791 Bytes
bad179a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // compares every command string of a platform.js with the backticked strings of SPEC.md §6 (and §3 wrap text)
const fs = require('fs'), path = require('path');
const root = process.argv[2], plat = require(path.join(root, 'core/platform.js'));
const spec = fs.readFileSync(path.join(process.env.HOME, '.local/share/sm-dev/SPEC.md'), 'utf8');
const sec6 = spec.slice(spec.indexOf('## 6.'), spec.indexOf('## 7.'));
const ticks = [...sec6.matchAll(/`([^`]+)`/g)].map(m => m[1].replace(/\\\|/g, '|'));
const have = new Set();
for (const k of ['procActions', 'priorities', 'serviceActions', 'diagnostics', 'systemActions']) for (const c of plat.ui[k]) have.add(c.cmd), have.add(c.label);
for (const a of ['kill_pid', 'renice', 'restart_service', 'restart_failed', 'drop_caches']) { const c = plat.command(a, 'ARG'); if (c) have.add(c.replace(/'ARG'/g, '{q}').replace(/\b0\b/, '{n}')); }
have.add(plat.cleanup), have.add(plat.power(true)), have.add(plat.power(false));
have.add(plat.serviceLogs('ARG', 123).replace(/'ARG'/g, '{q}').replace('123', '{n}'));
const all = [...have].join('\n');
let miss = 0;
for (const t of ticks) {
if (t.length < 12 || /^(C\+\+|\{|Model|Session|Tabs)/.test(t)) continue;
const ok = all.includes(t) || all.includes(t.replace('<v>', 'Idle')) || all.includes(t.replace('<verb>', 'start'));
if (!ok) ++miss, console.log('NOT FOUND:', t);
}
console.log(`${ticks.length} backticked strings in §6, ${miss} not found in ${plat.ui.name} platform.js`);
console.log('rule actions:', plat.ui.ruleActions.map(a => a[0]).join(' '));
console.log('wrap:', JSON.stringify(plat.wrap('CMD', true)));
console.log('shell:', plat.shell(3).join(' '));
console.log('collector head:', JSON.stringify(plat.collector(3).slice(0, 40)));
console.log('quote:', plat.quote("a'b"));
|