51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
/**
|
|
* Script to remove orphaned commas and fix JSON structure in game mode files
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const gameModeFiles = [
|
|
'src/data/modes/trainingGameData.js',
|
|
'src/data/modes/humiliationGameData.js',
|
|
'src/data/modes/dressUpGameData.js',
|
|
'src/data/modes/enduranceGameData.js'
|
|
];
|
|
|
|
function cleanOrphanedCommas(filePath) {
|
|
console.log(`Cleaning orphaned commas in: ${filePath}`);
|
|
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
|
|
// Remove lines that are just commas with whitespace
|
|
content = content.replace(/^\s*,\s*$/gm, '');
|
|
|
|
// Remove double commas
|
|
content = content.replace(/,,+/g, ',');
|
|
|
|
// Fix lines where comma is separated from the property
|
|
// Find patterns like: property: "value"\n,\n and fix to property: "value",\n
|
|
content = content.replace(/(["\w]+:\s*"[^"]*")\s*\n\s*,\s*\n/g, '$1,\n');
|
|
content = content.replace(/(["\w]+:\s*\d+)\s*\n\s*,\s*\n/g, '$1,\n');
|
|
content = content.replace(/(["\w]+:\s*'[^']*')\s*\n\s*,\s*\n/g, '$1,\n');
|
|
|
|
fs.writeFileSync(filePath, content);
|
|
console.log(`Cleaned orphaned commas in: ${filePath}`);
|
|
}
|
|
|
|
function main() {
|
|
console.log('Cleaning orphaned commas in game mode files...');
|
|
|
|
gameModeFiles.forEach(file => {
|
|
const fullPath = path.join(process.cwd(), file);
|
|
if (fs.existsSync(fullPath)) {
|
|
cleanOrphanedCommas(fullPath);
|
|
} else {
|
|
console.log(`File not found: ${fullPath}`);
|
|
}
|
|
});
|
|
|
|
console.log('All orphaned commas cleaned!');
|
|
}
|
|
|
|
main(); |