Last active
March 4, 2023 11:44
-
-
Save hochan222/ac6a6bf9337ed968211aad67d0cd41ef to your computer and use it in GitHub Desktop.
replace /{{bug\((\d+)\)}}/g to [Firefox bug $1](https://bugzil.la/$1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const pattern = /{{\s*[bB]ug\("?(\d+)"?\)\s*}}/g; | |
const replacement = '[Firefox bug $1](https://bugzil.la/$1)'; | |
function processFile(file) { | |
fs.readFile(file, 'utf8', (err, data) => { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
const result = data.replace(pattern, replacement); | |
if (result !== data) { | |
fs.writeFile(file, result, 'utf8', (err) => { | |
if (err) { | |
console.error(err); | |
} else { | |
console.log(`File '${file}' updated.`); | |
} | |
}); | |
} | |
}); | |
} | |
function processDirectory(dir) { | |
const files = fs.readdirSync(dir); | |
files.forEach((file) => { | |
const filePath = path.join(dir, file); | |
const stat = fs.statSync(filePath); | |
if (stat.isDirectory()) { | |
processDirectory(filePath); | |
} else if (stat.isFile()) { | |
processFile(filePath); | |
} | |
}); | |
} | |
const rootDir = process.argv[2] || '.'; | |
processDirectory(rootDir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment