import { existsSync , promises as fsAsync } from 'fs' ; import * as ejs from 'ejs' ; import { Injectable } from '@nestjs/common' ; @ Injectable ( ) export class TemplateService { async readFile ( path ) { return fsAsync . readFile ( path , 'utf-8' ) ; } render ( template , values ) { return ejs . render ( template , values ) ; } getFilePath ( fileName , dirPaths ) { return dirPaths . map ( ( dirPath ) => `${ dirPath }/${ fileName }` ) . filter ( ( filePath ) => existsSync ( filePath ) ) . pop ( ) ; } }