UNPKG

@sap/generator-cap-project

Version:

Creates a new SAP Cloud Application Programming Model project.

18 lines (17 loc) 759 B
import assert from 'assert'; import { isFileStateModified, setModifiedFileState } from '../state.js'; export default function write(filepath, contents, stat) { assert(typeof contents === 'string' || Buffer.isBuffer(contents), 'Expected `contents` to be a String or a Buffer'); const file = this.store.get(filepath); const newContents = Buffer.isBuffer(contents) ? contents : Buffer.from(contents); if (!isFileStateModified(file) || !Buffer.isBuffer(file.contents) || !newContents.equals(file.contents) || (stat && file.stat !== stat)) { setModifiedFileState(file); file.contents = newContents; file.stat = stat ?? null; this.store.add(file); } return file.contents.toString(); }