|
1 | | -const fs = require('fs'); |
2 | | -const path = require('path'); |
| 1 | +import fs from 'node:fs'; |
| 2 | +import path from 'node:path'; |
| 3 | +import {fileURLToPath} from 'node:url'; |
| 4 | +import {dirname} from 'node:path'; |
| 5 | + |
| 6 | +// __dirname is not available in ESM, so we need to derive it |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
3 | 9 |
|
4 | 10 | function copyFile(sourceFilename, targetFilename) { |
5 | | - const sourcePath = path.join(__dirname, '../../', sourceFilename); |
6 | | - const targetPath = path.join(__dirname, '../', targetFilename); |
7 | | - const md = fs.readFileSync(sourcePath, 'utf-8'); |
8 | | - fs.writeFileSync(targetPath, md); |
| 11 | + const sourcePath = path.join(__dirname, '../../', sourceFilename); |
| 12 | + const targetPath = path.join(__dirname, '../', targetFilename); |
| 13 | + const md = fs.readFileSync(sourcePath, 'utf-8'); |
| 14 | + fs.writeFileSync(targetPath, md); |
9 | 15 | } |
10 | 16 |
|
11 | 17 | function rewriteFile(filename, regex, replacement) { |
12 | | - console.log("Rewriting file: ", filename, " with regex: ", regex, " and replacement: ", replacement) |
13 | | - const content = fs.readFileSync(path.join(__dirname, filename), 'utf-8'); |
14 | | - const newContent = content.replace(regex, replacement); |
15 | | - fs.writeFileSync(path.join(__dirname, filename), newContent); |
| 18 | + console.log("Rewriting file: ", filename, " with regex: ", regex, " and replacement: ", replacement) |
| 19 | + const content = fs.readFileSync(path.join(__dirname, filename), 'utf-8'); |
| 20 | + const newContent = content.replace(regex, replacement); |
| 21 | + fs.writeFileSync(path.join(__dirname, filename), newContent); |
16 | 22 | } |
17 | 23 |
|
18 | 24 | export { |
19 | | - copyFile, |
20 | | - rewriteFile, |
| 25 | + copyFile, |
| 26 | + rewriteFile |
21 | 27 | }; |
0 commit comments