generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
18 lines (17 loc) • 582 B
JavaScript
import fs from 'fs';
import { doesFileExist } from '../utils/file-utils.js';
export function readFiles(iterable) {
if (!iterable) {
throw new Error('The passed files must not be nil.');
}
return iterable.map(path => readFile(path));
}
export function readFile(path) {
if (!path) {
throw new Error('The passed file must not be nil to be read.');
}
if (!doesFileExist(path)) {
throw new Error(`The passed file '${path}' must exist and must not be a directory to be read.`);
}
return fs.readFileSync(path, 'utf-8').toString();
}