mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
refactor: bundle template.js respectively
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import * as _ from './util/underscore.js'
|
||||
import path from 'path'
|
||||
import {anySeries} from './util/promise.js'
|
||||
import {statFileAsync, readFileAsync} from './util/fs.js'
|
||||
|
||||
function lookup (filepath, root, options) {
|
||||
root = options.root.concat(root || [])
|
||||
root = _.uniq(root)
|
||||
const paths = root.map(root => path.resolve(root || location.href, filepath))
|
||||
return anySeries(paths, async path => {
|
||||
try {
|
||||
await statFileAsync(path)
|
||||
return path
|
||||
} catch (e) {
|
||||
e.message = `${e.code}: Failed to lookup ${filepath} in: ${root}`
|
||||
throw e
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function resolve (filepath, root, options) {
|
||||
if (!path.extname(filepath)) {
|
||||
filepath += options.extname
|
||||
}
|
||||
return lookup(filepath, root, options)
|
||||
}
|
||||
|
||||
export async function read (filepath) {
|
||||
return readFileAsync(filepath)
|
||||
}
|
||||
Reference in New Issue
Block a user