import * as fsExtra from "fs-extra" ; import * as fs from "fs" ; import { FileSystemAdapter } from "@codotype/core" ; /**
 * LocalFileSystemAdapter
 * FileSystemAdapter for writing to the local file system
 */ export class LocalFileSystemAdapter implements FileSystemAdapter { ensureDir ( dir ) { return new Promise ( ( resolve , reject ) => { fsExtra . ensureDir ( dir ) . then ( ( ) => { resolve ( true ) ; } ) ; } ) ; } readFile ( filepath ) { if ( ! this . fileExists ( filepath ) ) { return Promise . resolve ( null ) ; } return this . readFile ( filepath ) ; } fileExists ( filepath ) { return Promise . resolve ( fs . existsSync ( filepath ) ) ; } writeFile ( dest , compiledTemplate ) { return new Promise ( ( resolve , reject ) => { fs . writeFile ( dest , compiledTemplate , ( err ) => { if ( err ) { return reject ( err ) ; } return resolve ( true ) ; } ) ; } ) ; } }