UNPKG

@coat/cli

Version:

TODO: See #3

35 lines (32 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentFiles = getCurrentFiles; var _fs = require("fs"); /** * Returns the disk content for the given file paths if they exist. * If a file does not exist, the value for the path will be undefined. * * @param filePaths The files that shall be retrieved */ async function getCurrentFiles(filePaths) { const currentFiles = await Promise.all(filePaths.map(async filePath => { // Try to retrieve the file contents try { const content = await _fs.promises.readFile(filePath, "utf-8"); // Return the path and the content as a tuple // to match them back together later in an object return [filePath, content]; } catch (error) { if (error.code === "ENOENT") { // File doesn't exist, return the key with an undefined content return [filePath]; } // A different error occurred, e.g. missing read permissions // This error should be thrown back to the user throw error; } })); return Object.fromEntries(currentFiles); }