-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename.mjs
More file actions
59 lines (51 loc) · 1.65 KB
/
Copy pathrename.mjs
File metadata and controls
59 lines (51 loc) · 1.65 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
import { readdirSync, statSync, readFileSync, writeFileSync, renameSync } from 'fs';
import { join } from 'path';
const IGNORE_DIRS = new Set(['node_modules', '.git', 'dist', 'coverage', '.github', 'reports']);
function walkDir(dir, callback) {
const files = readdirSync(dir);
for (const f of files) {
if (IGNORE_DIRS.has(f)) continue;
const path = join(dir, f);
if (statSync(path).isDirectory()) {
walkDir(path, callback);
} else {
callback(path);
}
}
}
function processFile(path) {
// Skip binary/large files safely by extension
if (path.match(/\.(png|jpg|jpeg|gif|ico|webp|svg|woff|woff2|ttf|eot|tgz|zip|exe|pdf|wav|mp3|sqlite)$/i)) return;
try {
let content = readFileSync(path, 'utf8');
let newContent = content
.split('lyacode').join('lyacode')
.split('Lya Code').join('Lya Code')
.split('LYA_CODE').join('LYA_CODE')
.split('LYACODE').join('LYACODE')
.split('LyaCode').join('LyaCode');
if (content !== newContent) {
writeFileSync(path, newContent, 'utf8');
console.log(`Updated content: ${path}`);
}
} catch(e) {
// Ignore files that can't be read as utf8
}
}
// 1. Process contents
walkDir('.', processFile);
// 2. Rename files
const filesToRename = [];
walkDir('.', (path) => {
if (path.includes('lyacode') || path.includes('LyaCode') || path.includes('Lya Code')) {
filesToRename.push(path);
}
});
for (const path of filesToRename) {
const newPath = path
.split('lyacode').join('lyacode')
.split('Lya Code').join('Lya Code')
.split('LyaCode').join('LyaCode');
renameSync(path, newPath);
console.log(`Renamed: ${path} -> ${newPath}`);
}