Files
Web-NibblePoker/scripts/legacy/php-relinker.js
Herwin c8bf68fa2d Moved build scripts into "scripts/", Updated readme
Update .gitignore, compile-clean.cmd, and 38 more files...
2024-04-18 18:00:28 +02:00

26 lines
671 B
JavaScript

const fs = require('fs');
if (process.argv.length < 3) {
console.log('Usage: node php-relinker.js <input_php_file>');
process.exit(1);
}
const inputFilePath = process.argv[2];
console.log(">", inputFilePath);
function replaceExtension(match) {
return match.replace('.php', '.min.php');
}
try {
const content = fs.readFileSync(inputFilePath, 'utf-8');
const modifiedContent = content.replace(/include.*\.php/g, replaceExtension);
fs.writeFileSync(inputFilePath, modifiedContent, 'utf-8');
} catch (error) {
if (error.code === 'ENOENT') {
console.log('> Error: File not found.');
} else {
console.error('> Error: An error occurred =>', error.message);
}
}