feat: renderSync, parseAndRenderSync and renderFileSync, see #48

This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 8028f82499
commit 7fb01ad69a
66 changed files with 896 additions and 272 deletions
+12 -1
View File
@@ -1,6 +1,6 @@
import * as _ from '../util/underscore'
import { resolve, extname } from 'path'
import { stat, readFile } from 'fs'
import { stat, statSync, readFile, readFileSync } from 'fs'
import IFS from './ifs'
const statAsync = _.promisify(stat)
@@ -13,6 +13,17 @@ const fs: IFS = {
readFile: filepath => {
return readFileAsync(filepath, 'utf8')
},
existsSync: (filepath: string) => {
try {
statSync(filepath)
return true
} catch (err) {
return false
}
},
readFileSync: filepath => {
return readFileSync(filepath, 'utf8')
},
resolve: (root: string, file: string, ext: string) => {
if (!extname(file)) file += ext
return resolve(root, file)