Repository navigation
Expand file tree
/
Copy pathcheck-tools-order.js
More file actions
65 lines (55 loc) · 1.74 KB
/
Copy pathcheck-tools-order.js
File metadata and controls
65 lines (55 loc) · 1.74 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const filePath = path.join(__dirname, "tools.md");
const content = fs.readFileSync(filePath, "utf8");
// Extract rows from the "Parsers" markdown table.
const parserSectionMatch = content.match(/##\s+Parsers([\s\S]*?)(?=\n##\s+|\n#+\s+|\n<hr>|$)/);
if (!parserSectionMatch) {
console.error("Could not find the 'Parsers' section in tools.md.");
process.exit(1);
}
const section = parserSectionMatch[1];
// Extract language names from the first column of each table row.
const languageRegex = /^\|\s*([^|]+?)\s*\|/gm;
const languages = [];
let match;
while ((match = languageRegex.exec(section)) !== null) {
const language = match[1].trim();
if (!language || language.toLowerCase() === "language") {
continue;
}
// Skip markdown separator rows.
if (/^[:\-\s]+$/.test(language)) {
continue;
}
languages.push(language);
}
if (languages.length === 0) {
console.error("No language rows found in the 'Parsers' table in tools.md.");
process.exit(1);
}
console.log("Languages found:");
languages.forEach((lang, i) => console.log(` ${i + 1}. ${lang}`));
console.log();
// Check alphabetical order (case-insensitive)
let inOrder = true;
for (let i = 1; i < languages.length; i++) {
const prev = languages[i - 1].toLowerCase();
const curr = languages[i].toLowerCase();
if (curr < prev) {
console.error(
`Ordering error: "${languages[i]}" should appear before "${languages[i - 1]}".`,
);
inOrder = false;
}
}
if (inOrder) {
console.log("All languages are listed in alphabetical order.");
} else {
console.error();
console.error(
"The language column in tools.md (Parsers table) must stay in alphabetical order.",
);
process.exit(1);
}