import fs from 'fs';import * as ohm from 'ohm-js';import prettier from 'prettier';import {fileURLToPath, URL} from 'url';
import {getActionDecls} from '../../cli/src/helpers/generateTypes.js';
const templatePath = new URL('./data/index.d.ts.template', import.meta.url);const doNotEditBanner = '// DO NOT EDIT! This file is autogenerated from scripts/data/index.d.ts.template.\n';
const render = (template, vars) => template.replace(/{{([^{}]*)}}/g, (_, name) => { if (name.trim().startsWith('!')) return ''; return vars[name]; });
(async function main() { const BuiltInRules = ohm.ohmGrammar.superGrammar; const builtInRuleActions = ['', ...getActionDecls(BuiltInRules)].join('\n ');
const template = await fs.promises.readFile(templatePath, 'utf-8'); const output = render(template, { builtInRuleActions, doNotEditBanner, }); const options = await prettier.resolveConfig(fileURLToPath(templatePath)); const formattedOutput = prettier.format(output, { ...options, parser: 'typescript', }); await fs.promises.writeFile( new URL('../index.d.ts', import.meta.url), formattedOutput, 'utf-8', );})();