|
| 1 | +import { green } from 'colorette' |
| 2 | +import fs from 'fs' |
| 3 | +import * as fsAsync from 'fs/promises' |
| 4 | +import { logger } from '~/config/logger' |
| 5 | + |
| 6 | +const msgType = `${green('filesystem')}` |
| 7 | + |
| 8 | +/** |
| 9 | + * Read HTML file |
| 10 | + * @param filePath - path to HTML file |
| 11 | + * @returns HTML file content |
| 12 | + */ |
| 13 | +export async function readHTMLFile( |
| 14 | + filePath: fs.PathLike | fs.promises.FileHandle |
| 15 | +): Promise<string> { |
| 16 | + try { |
| 17 | + return await fsAsync.readFile(filePath, 'utf-8') |
| 18 | + } catch (err) { |
| 19 | + logger.error(`${msgType} - invalid HTML file path: ${filePath}`) |
| 20 | + throw new Error(`invalid HTML file path: ${filePath}`) |
| 21 | + } |
| 22 | +} |
0 commit comments