UNPKG

@sap/generator-cap-project

Version:

Creates a new SAP Cloud Application Programming Model project.

21 lines (20 loc) 614 B
import { EOL } from 'os'; export default function append(to, contents, options) { options = { trimEnd: true, separator: EOL, ...options, }; if (!this.exists(to) && options.create) { this.write(to, contents); return; } let currentContents = this.read(to); if (!currentContents) { throw new Error(`Error appending to ${to}, file is empty.`); } if (currentContents && options.trimEnd) { currentContents = currentContents.replace(/\s+$/, ''); } this.write(to, currentContents + options.separator + contents.toString()); }