mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 22:10:41 -07:00
refactor: move fs util into template.js
This commit is contained in:
+6
-2
@@ -1,7 +1,11 @@
|
||||
import * as _ from './util/underscore.js'
|
||||
import path from 'path'
|
||||
import {anySeries} from './util/promise.js'
|
||||
import {statFileAsync, readFileAsync} from './util/fs.js'
|
||||
import fs from 'fs'
|
||||
import {promisify} from 'util'
|
||||
|
||||
const statFileAsync = promisify(fs.stat)
|
||||
const readFileAsync = promisify(fs.readFile)
|
||||
|
||||
export async function resolve (filepath, root, options) {
|
||||
if (!path.extname(filepath)) {
|
||||
@@ -22,5 +26,5 @@ export async function resolve (filepath, root, options) {
|
||||
}
|
||||
|
||||
export async function read (filepath) {
|
||||
return readFileAsync(filepath)
|
||||
return readFileAsync(filepath, 'utf8')
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import fs from 'fs'
|
||||
|
||||
export function readFileAsync (filepath) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.readFile(filepath, 'utf8', function (err, content) {
|
||||
err ? reject(err) : resolve(content)
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
export function statFileAsync (path) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.stat(path, (err, stat) => err ? reject(err) : resolve(stat))
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user