mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge branch 'main' into setup-check-if-dir-exists
This commit is contained in:
commit
91473838d2
8 changed files with 68 additions and 62 deletions
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue