| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/usr/bin/env node
- const fs = require('fs');
- const path = require('path');
- const { CASE_PATTERNS, PATTERN_LIBRARY } = require('../mcp/src/features/tihao-sourcing/brief-rule-patterns');
- function main() {
- const args = parseArgs(process.argv.slice(2));
- const outputDir = path.resolve(args.output || path.join(__dirname, '..', 'docs'));
- fs.mkdirSync(outputDir, { recursive: true });
- const outFile = path.join(outputDir, 'brief-rule-patterns.json');
- fs.writeFileSync(outFile, JSON.stringify({
- generatedAt: new Date().toISOString(),
- caseCount: CASE_PATTERNS.length,
- casePatterns: CASE_PATTERNS,
- patternLibrary: Object.entries(PATTERN_LIBRARY).map(([key, item]) => ({
- key,
- label: item.label,
- note: item.note,
- regex: item.regex.source
- }))
- }, null, 2), 'utf8');
- console.log(JSON.stringify({ outFile, caseCount: CASE_PATTERNS.length, patternCount: Object.keys(PATTERN_LIBRARY).length }, null, 2));
- }
- function parseArgs(argv) {
- const args = {};
- for (let index = 0; index < argv.length; index += 1) {
- const raw = argv[index];
- if (!raw.startsWith('--')) continue;
- const key = raw.slice(2).replace(/-([a-z])/g, (_, char) => char.toUpperCase());
- const next = argv[index + 1];
- if (!next || next.startsWith('--')) args[key] = true;
- else {
- args[key] = next;
- index += 1;
- }
- }
- return args;
- }
- if (require.main === module) {
- try {
- main();
- } catch (error) {
- console.error(error && error.stack ? error.stack : String(error));
- process.exit(1);
- }
- }
- module.exports = { main };
|