UNPKG

@sap/generator-cap-project

Version:

Creates a new SAP Cloud Application Programming Model project.

27 lines (26 loc) 992 B
import path from 'path'; import normalize from 'normalize-path'; import { minimatch } from 'minimatch'; import { hasClearedState, hasState } from '../state.js'; const defaultDumpFilter = (file) => hasClearedState(file) || hasState(file); export default function (cwd = process.cwd(), filter) { const filterFile = typeof filter === 'string' ? (file) => defaultDumpFilter(file) && minimatch(file.path, filter) : filter ?? defaultDumpFilter; return Object.fromEntries(this.store .all() .filter((file) => filterFile(file, cwd)) .map((file) => { const filePath = normalize(cwd ? path.relative(cwd, file.path) : file.path); const fileDump = { contents: file.contents?.toString() ?? null, }; if (file.state) { fileDump.state = file.state; } if (file.stateCleared) { fileDump.stateCleared = file.stateCleared; } return [filePath, fileDump]; })); }