MCPcopy Create free account
hub / github.com/firebase/firebase-tools / readFileFromDirectory

Function readFileFromDirectory

src/utils.ts:817–842  ·  view source on GitHub ↗
(
  directory: string,
  file: string,
)

Source from the content-addressed store, hash-verified

815 * Retrieves a file from the directory.
816 */
817export function readFileFromDirectory(
818 directory: string,
819 file: string,
820): Promise<{ source: string; sourceDirectory: string }> {
821 return new Promise<string>((resolve, reject) => {
822 fs.readFile(path.resolve(directory, file), "utf8", (err, data) => {
823 if (err) {
824 if (err.code === "ENOENT") {
825 return reject(
826 new FirebaseError(`Could not find "${file}" in "${directory}"`, { original: err }),
827 );
828 }
829 reject(
830 new FirebaseError(`Failed to read file "${file}" in "${directory}"`, { original: err }),
831 );
832 } else {
833 resolve(data);
834 }
835 });
836 }).then((source) => {
837 return {
838 source,
839 sourceDirectory: directory,
840 };
841 });
842}
843
844/**
845 * Wrapps `yaml.safeLoad` with an error handler to present better YAML parsing

Callers 7

readDataConnectYamlFunction · 0.90
readConnectorYamlFunction · 0.90
loadFromFileMethod · 0.90
upsertFileMethod · 0.90
parseTestFilesRecursiveFunction · 0.90
readExtensionYamlFunction · 0.90
readPostinstallFunction · 0.90

Calls 2

resolveFunction · 0.85
rejectFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…