-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostbuild.js
More file actions
46 lines (35 loc) · 1.1 KB
/
Copy pathpostbuild.js
File metadata and controls
46 lines (35 loc) · 1.1 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
import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
new (class PostBuild {
#fromEscapedRegex;
#emptyDeclRegex;
constructor() {
this.#emptyDeclRegex = /\s{2,4}(static\s+)?(?!return|break)(\w+)\s*;\n?/g;
this.#fromEscapedRegex = /\\u006F/g;
}
#findJsFiles(directory, files = []) {
const entries = readdirSync(directory);
entries.forEach(entry => {
const fullPath = join(directory, entry);
const stat = statSync(fullPath);
if (stat.isDirectory()) {
this.#findJsFiles(fullPath, files);
} else if (entry.endsWith('.js')) {
files.push(fullPath);
}
});
return files;
}
execute() {
const files = this.#findJsFiles('src');
files.forEach(file => {
const originalContent = readFileSync(file, 'utf-8');
const newContent = originalContent
.replaceAll(this.#emptyDeclRegex, '')
.replaceAll(this.#fromEscapedRegex, 'o');
if (newContent !== originalContent) {
writeFileSync(file, newContent, 'utf-8');
}
});
}
})().execute();