-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-rulesets.js
More file actions
40 lines (32 loc) · 1.1 KB
/
generate-rulesets.js
File metadata and controls
40 lines (32 loc) · 1.1 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
const RULES_DIR = './en';
const OUTPUT_FILE = './src/tests-metadata.ts';
function generateRuleset() {
const files = fs.readdirSync(RULES_DIR);
const ruleset = {};
files.forEach((file) => {
if (path.extname(file) === '.md') {
const filePath = path.join(RULES_DIR, file);
const fileContent = fs.readFileSync(filePath, 'utf8');
const { data } = matter(fileContent);
if (data.id) {
ruleset[data.id] = { ...data };
delete ruleset[data.id].id;
delete ruleset[data.id].Title;
const scs =
ruleset[data.id].scs && ruleset[data.id].scs.trim() !== ''
? ruleset[data.id].scs.split(',').map((s) => s.trim())
: [];
ruleset[data.id].scs = scs;
}
}
});
const fileContent = `
import { TestRegistry } from './types';
export const ruleset: TestRegistry = ${JSON.stringify(ruleset, null, 2)};`;
fs.writeFileSync(OUTPUT_FILE, fileContent);
console.log(`✅ Ruleset gerado com sucesso em: ${OUTPUT_FILE}`);
}
generateRuleset();