matrix-dimension/scripts/convert-newlines.js
2020-04-09 09:45:23 +02:00

23 lines
589 B
JavaScript

const fs = require('fs');
const util = require('util');
(async function () {
if (process.argv.length !== 3) {
console.error('Wrong number of arguments');
process.exit(-1);
}
const filePath = process.argv.pop();
const fileExists = await util.promisify(fs.exists)(filePath);
if (fileExists) {
const file = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
await fs.promises.writeFile(
filePath,
file
.replace(/\r\n/g, '\n')
.replace(/\r/, '\n'),
);
}
})();