let yauzl_open = util.promisify(yauzl.open)
let build_cache_js = new BuildCache()
-let req_js = async path => {
- let result = await build_cache_js.get(path)
- if (result === undefined) {
+let get_js = async path => await build_cache_js.get(
+ path,
+ async result => {
console.log('compiling', path)
- result = await jstemplate(path)
- build_cache_js.set(path, result)
+ result.value = await jstemplate(path)
}
- return result
-}
+)
let build_cache_json = new BuildCache()
-let req_json = async path => {
- let result = await build_cache_json.get(path)
- if (result === undefined) {
+let get_json = async path => await build_cache_json.get(
+ path,
+ async result => {
console.log('parsing', path)
- result = JSON.parse(await fs_readFile(path))
- build_cache_json.set(path, result)
+ result.value = JSON.parse(await fs_readFile(path))
}
- return result
-}
+)
let build_cache_less = new BuildCache()
-let req_less = async (path, site_root, dir_name) => {
- let result = await build_cache_less.get(path)
- if (result === undefined) {
+let get_less = async (path, site_root, dir_name) => await build_cache_less.get(
+ path,
+ async result => {
console.log('compiling', path)
let render = await less.render(
await fs_readFile(path, {encoding: 'utf-8'}),
//urlArgs: ''
}
)
- result = new Buffer(render.css, 'utf-8')
- build_cache_less.set(path, result, render.imports)
+ result.deps.concat(render.imports)
+ result.value = new Buffer(render.css, 'utf-8')
}
- return result
-}
+)
let build_cache_text = new BuildCache()
-let req_text = async path => {
- let result = await build_cache_text.get(path)
- if (result === undefined) {
+let get_text = async path => await build_cache_text.get(
+ path,
+ async result => {
console.log('reading', path)
- result = await fs_readFile(path, {encoding: 'utf-8'})
- build_cache_text.set(path, result)
+ result.value = await fs_readFile(path, {encoding: 'utf-8'})
}
- return result
-}
+)
let build_cache_zip = new BuildCache()
-let req_zip = async path => {
- let result = await build_cache_zip.get(path)
- if (result === undefined) {
+let get_zip = async path => await build_cache_zip.get(
+ path,
+ async result => {
console.log('decompressing', path)
- result = {}
+ result.value = {}
let zipfile = await yauzl_open(path, {autoClose: false})
let entries = []
await new Promise(
read_stream.pipe(write_stream)
data = await data
console.log('entry path', entries[i].fileName, 'size', data.length)
- result[entries[i].fileName] = data
+ result.value[entries[i].fileName] = data
}
await zipfile.close()
- build_cache_zip.set(path, result)
}
- return result
-}
+)
let build_cache_zet = new BuildCache()
-let req_zet = async path => {
- let result = await build_cache_zet.get(path)
- if (result === undefined) {
+let get_zet = async path => await build_cache_zet.get(
+ path,
+ async result => {
console.log('opening', path)
- result = new zetjs.Index(path)
- build_cache_zet.set(
- path,
- result,
- [
- path + '.map.0',
- path + '.param.0',
- path + '.v.0',
- path + '.vocab.0'
- ]
- )
+ result.deps = [
+ path + '.map.0',
+ path + '.param.0',
+ path + '.v.0',
+ path + '.vocab.0'
+ ]
+ result.value = new zetjs.Index(path)
}
- return result
-}
+)
-exports.req_js = req_js
-exports.req_json = req_json
-exports.req_less = req_less
-exports.req_text = req_text
-exports.req_zip = req_zip
-exports.req_zet = req_zet
+exports.get_js = get_js
+exports.get_json = get_json
+exports.get_less = get_less
+exports.get_text = get_text
+exports.get_zip = get_zip
+exports.get_zet = get_zet
) + str, result
switch (type) {
case undefined:
- result = await (await resources.req_js(path))(env, out, req)
+ result = await (await resources.get_js(path))(env, out, req)
break
case 'js':
- result = await resources.req_js(path)
+ result = await resources.get_js(path)
break
case 'json':
- result = await resources.req_json(path)
+ result = await resources.get_json(path)
break
case 'text':
- result = await resources.req_text(path)
+ result = await resources.get_text(path)
break
case 'zet':
- result = await resources.req_zet(path)
+ result = await resources.get_zet(path)
break
default:
assert(false)
case 'css':
temp = page + '.less'
try {
- let data = await resources.req_less(site_root + temp, site_root, dir_name)
+ let data = await resources.get_less(site_root + temp, site_root, dir_name)
console.log(
site,
'serving',
}
}
- let favicons = await resources.req_zip(site_root + '/favicons.zip')
+ let favicons = await resources.get_zip(site_root + '/favicons.zip')
temp = page.substring(1) // fix this to avoid leading / on all absolute paths
if (favicons.hasOwnProperty(temp)) {
let data = favicons[temp]