| 1 |
const fs = require('fs'); |
| 2 |
|
| 3 |
function getArgs() { |
| 4 |
const args = {}; |
| 5 |
process.argv.slice(2).forEach((arg, index, array) => { |
| 6 |
if (arg.startsWith('-')) { |
| 7 |
args[arg] = array[index + 1]; |
| 8 |
} |
| 9 |
}); |
| 10 |
return args; |
| 11 |
} |
| 12 |
|
| 13 |
const args = getArgs(); |
| 14 |
|
| 15 |
const inputFilePath = args['-i']; |
| 16 |
const outputFilePath = args['-o']; |
| 17 |
|
| 18 |
if (!inputFilePath || !outputFilePath) { |
| 19 |
console.error('Please provide both input and output file paths using -i and -o flags.'); |
| 20 |
process.exit(1); |
| 21 |
} |
| 22 |
|
| 23 |
fs.readFile(inputFilePath, 'utf8', (err, data) => { |
| 24 |
if (err) { |
| 25 |
console.error('Error reading the input file:', err); |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
// Replace all occurrences of "args=[]" with "args" |
| 30 |
const modifiedData = data.replace(/args=\[\]/g, 'args'); |
| 31 |
|
| 32 |
fs.writeFile(outputFilePath, modifiedData, 'utf8', (err) => { |
| 33 |
if (err) { |
| 34 |
console.error('Error writing to the output file:', err); |
| 35 |
return; |
| 36 |
} |
| 37 |
console.log('File successfully updated and saved to', outputFilePath); |
| 38 |
}); |
| 39 |
}); |