Skip to content

Commit b5a3fad

Browse files
committed
chore: added replace-brackets back
1 parent 4d7ae2d commit b5a3fad

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

scripts/replace-brackets.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
function processFile(filePath) {
5+
try {
6+
const content = fs.readFileSync(filePath, "utf8");
7+
// Preserve brackets inside code fences (```...```)
8+
const modifiedContent = content.replace(/```[\s\S]*?```|[{}]/g, (match) => {
9+
// If match contains newlines or starts with ```, it's a code block - preserve it
10+
return match.includes("\n") || match.startsWith("```") ? match : "";
11+
});
12+
fs.writeFileSync(filePath, modifiedContent, "utf8");
13+
console.log(`Processed: ${filePath}`);
14+
} catch (error) {
15+
console.error(`Error processing ${filePath}: ${error.message}`);
16+
}
17+
}
18+
19+
function crawlDirectory(dirPath) {
20+
try {
21+
const items = fs.readdirSync(dirPath);
22+
23+
for (const item of items) {
24+
const itemPath = path.join(dirPath, item);
25+
const stats = fs.statSync(itemPath);
26+
27+
if (stats.isDirectory()) {
28+
crawlDirectory(itemPath);
29+
} else if (stats.isFile()) {
30+
processFile(itemPath);
31+
}
32+
}
33+
} catch (error) {
34+
console.error(`Error crawling directory ${dirPath}: ${error.message}`);
35+
}
36+
}
37+
38+
// Start crawling from current directory or specify a path
39+
const targetPath = process.argv[2] || ".";
40+
crawlDirectory(targetPath);

0 commit comments

Comments
 (0)