main
Caleb
Source for 0.3.0: calculators, schematics, tests, README screenshots, standards register, calculator-standards dev skil…
0788d52
#!/usr/bin/env node
/* Regenerates SOURCES.md: every calculator with its formula, cited reference and drawing status, under the
* hand-maintained standards register in docs/standards.md. Run after any calculator change: node scripts/sources.js */
'use strict';
const fs = require('fs'), path = require('path');
const ROOT = path.join(__dirname, '..');
const H = require(path.join(ROOT, 'calcs.js')), S = require(path.join(ROOT, 'schematics.js')), PKG = require(path.join(ROOT, 'package.json'));
const esc = s => String(s).replace(/\|/g, '\\|').replace(/\n/g, '<br>');
let md = `# Hardware Calculator — sources register\n\nGenerated by \`node scripts/sources.js\` for v${PKG.version}. Do not edit the calculator table by hand;\nedit \`ref\` / \`formula\` in calcs.js and regenerate. The standards register above it is maintained by hand in\n\`docs/standards.md\`.\n\n`;
md += fs.readFileSync(path.join(ROOT, 'docs', 'standards.md'), 'utf8').trim() + '\n\n';
md += `## Calculators (${H.CALCS.length})\n\n| id | Calculator | Drawing | Formula | Reference |\n|---|---|---|---|---|\n`;
for (const c of H.CALCS) md += `| \`${c.id}\` | ${esc(c.title)} | ${S.has(c.id) ? 'yes' : '—'} | \`${esc(c.formula)}\` | ${esc(c.ref)} |\n`;
fs.writeFileSync(path.join(ROOT, 'SOURCES.md'), md);
console.log(`SOURCES.md: ${H.CALCS.length} calculators, ${S.ids.length} drawings`);