( directory: string, file: string, )
| 815 | * Retrieves a file from the directory. |
| 816 | */ |
| 817 | export 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 |
no test coverage detected
searching dependent graphs…