-let BuildCache = require('@ndcode/build_cache')
let JSONCache = require('@ndcode/json_cache')
+let JSONCacheRW = require('@ndcode/json_cache_rw')
let JSTCache = require('@ndcode/jst_cache')
let LessCSSCache = require('@ndcode/less_css_cache')
let MinCSSCache = require('@ndcode/min_css_cache')
let TextCache = require('@ndcode/text_cache')
let ZipCache = require('@ndcode/zip_cache')
let assert = require('assert')
-let disk_build = require('@ndcode/disk_build')
let fs = require('fs')
-let path = require('path')
let util = require('util')
let fs_mkdir = util.promisify(fs.mkdir)
let fs_readFile = util.promisify(fs.readFile)
let fs_stat = util.promisify(fs.stat)
-let fs_writeFile = util.promisify(fs.writeFile)
let SiteRoot = function(server, root) {
if (!this instanceof SiteRoot)
Site.call(this, server)
this.root = root
- this.build_cache_json = new BuildCache()
this.json_cache = new JSONCache(true)
+ this.json_cache_rw = new JSONCacheRW(true)
this.jst_cache = new JSTCache(root, {_server: server, _site: this}, true)
this.less_css_cache = new LessCSSCache(root, true)
this.min_css_cache = new MinCSSCache(true)
SiteRoot.prototype = Object.create(Site.prototype)
-// this is for read-only JSON files
-// they will be reloaded from disk if modified
-SiteRoot.prototype.internal_get_json = function(pathname) {
- return /*await*/ this.build_cache_json.get(
- pathname,
- async result => {
- let text = await fs_readFile(pathname, {encoding: 'utf-8'})
- console.log('getting', pathname, 'as json')
- result.value = JSON.parse(text)
- }
- )
-}
-
SiteRoot.prototype.internal_ensure_dir = async function(pathname) {
try {
await fs_mkdir(pathname)
}
}
-// this is for read/write JSON files
-// they will not be reloaded from disk if modified
-SiteRoot.prototype.internal_read_json =
- async function(pathname, default_value) {
- return /*await*/ this.json_cache.read(
- pathname,
- default_value
- )
- }
-SiteRoot.prototype.internal_write_json =
- async function(pathname, value, timeout) {
- return /*await*/ this.json_cache.write(
- pathname,
- value,
- timeout
- )
- }
-SiteRoot.prototype.internal_modify_json =
- async function(pathname, default_value, modify_func, timeout) {
- return /*await*/ this.json_cache.modify(
- pathname,
- default_value,
- modify_func,
- timeout
- )
- }
-
SiteRoot.prototype.get_json = function(pathname) {
- return /*await*/ this.internal_get_json(this.root + pathname)
+ return /*await*/ this.json_cache.get(this.root + pathname)
}
SiteRoot.prototype.get_jst = function(pathname) {
// this is for read/write JSON files
// they will not be reloaded from disk if modified
SiteRoot.prototype.read_json = async function(pathname, default_value) {
- return /*await*/ this.internal_read_json(
+ return /*await*/ this.json_cache_rw.read(
this.root + pathname,
default_value
)
}
SiteRoot.prototype.write_json = async function(pathname, value, timeout) {
- return /*await*/ this.internal_write_json(
+ return /*await*/ this.json_cache_rw.write(
this.root + pathname,
value,
timeout
SiteRoot.prototype.modify_json =
async function(pathname, default_value, modify_func, timeout) {
- return /*await*/ this.internal_modify_json(
+ return /*await*/ this.json_cache_rw.modify(
this.root + pathname,
default_value,
modify_func,
"main": "index.js",
"directories": {},
"dependencies": {
- "@ndcode/build_cache": "^0.1.0",
- "@ndcode/disk_build": "^0.1.1",
"@ndcode/less_css_cache": "^0.1.0",
"@ndcode/min_css_cache": "^0.1.0",
"@ndcode/min_js_cache": "^0.1.0",
"@ndcode/min_html_cache": "^0.1.0",
"@ndcode/min_svg_cache": "^0.1.0",
- "@ndcode/json_cache": "^0.1.1",
+ "@ndcode/json_cache": "^0.1.2",
+ "@ndcode/json_cache_rw": "^0.1.0",
"@ndcode/jst_cache": "^0.1.0",
"commander": "^2.18.0",
"fs": "^0.0.1-security",