-
Notifications
You must be signed in to change notification settings - Fork 761
/
preload.js
55 lines (41 loc) · 1.54 KB
/
preload.js
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
const fs = require('fs');
const path = require('path');
const directoryPath = path.join(__dirname, 'public/3.55/src');
// Function to search for all .js files in the directory and its subdirectories
const getJsFiles = (dir) => {
let jsFiles = [];
const files = fs.readdirSync(dir);
files.forEach((file) => {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
jsFiles = jsFiles.concat(getJsFiles(fullPath));
}
else if (file.endsWith('.js')) {
jsFiles.push(fullPath);
}
});
return jsFiles;
};
// Function to modify files
const modifyFile = (filePath) => {
let fileContent = fs.readFileSync(filePath, 'utf8');
const preloadPattern = /preload\s*\(\s*\)\s*\n\s*{/g;
// Check if file contains 'preload () {'
if (preloadPattern.test(fileContent)) {
console.log(`Modifying file: ${filePath}`);
// Replace 'preload () {' with 'preload () {\n this.load.setBaseURL('https://cdn.phaserfiles.com/v385');'
fileContent = fileContent.replace(preloadPattern, match => `${match}\n this.load.setBaseURL('https://cdn.phaserfiles.com/v355');`);
// Write the modified content back to the file
fs.writeFileSync(filePath, fileContent, 'utf8');
}
};
// Main function to execute the script
const main = () => {
const jsFiles = getJsFiles(directoryPath);
jsFiles.forEach((file) => {
modifyFile(file);
});
console.log('Script has completed.');
};
main();