Merge branch 'main' into setup-check-if-dir-exists

This commit is contained in:
Sander Declerck 2025-09-18 10:27:00 +02:00
commit 91473838d2
No known key found for this signature in database
8 changed files with 68 additions and 62 deletions

View file

@ -23,15 +23,17 @@ export function doesExecutableExistOnSystem(executableName) {
}
}
export function removeLinesMatchingPattern(filePath, pattern) {
export function removeLinesMatchingPattern(filePath, pattern, eol) {
if (!fs.existsSync(filePath)) {
return;
}
eol = eol || os.EOL;
const fileContent = fs.readFileSync(filePath, "utf-8");
const lines = fileContent.split(/[\r\n\u2028\u2029]+/);
const lines = fileContent.split(/[\r\n\u2028\u2029]/);
const updatedLines = lines.filter((line) => !shouldRemoveLine(line, pattern));
fs.writeFileSync(filePath, updatedLines.join(os.EOL), "utf-8");
fs.writeFileSync(filePath, updatedLines.join(eol), "utf-8");
}
const maxLineLength = 100;
@ -63,11 +65,13 @@ function shouldRemoveLine(line, pattern) {
return true;
}
export function addLineToFile(filePath, line) {
export function addLineToFile(filePath, line, eol) {
createFileIfNotExists(filePath);
eol = eol || os.EOL;
const fileContent = fs.readFileSync(filePath, "utf-8");
const updatedContent = fileContent + os.EOL + line + os.EOL;
const updatedContent = fileContent + eol + line + eol;
fs.writeFileSync(filePath, updatedContent, "utf-8");
}