@beenotung/tslib
Version:
utils library in Typescript
21 lines (20 loc) • 693 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.appendIgnoreLine = appendIgnoreLine;
const fs_1 = require("fs");
function appendIgnoreLine(file, line) {
line = line.trim();
if ((0, fs_1.existsSync)(file)) {
const text = (0, fs_1.readFileSync)(file).toString();
const hasLine = text.split('\n').some(eachLine => {
eachLine = eachLine.trim();
return (eachLine == line || eachLine + '/' == line || eachLine == line + '/');
});
if (hasLine)
return;
if (!text.endsWith('\n')) {
line = '\n' + line;
}
}
(0, fs_1.appendFileSync)(file, line + '\n');
}