better saving schema for model layer

previously, the model layer had a confused interface, where it saved via blueprints, but loaded via a URL logic. This commit modifies Fetchers to save consistently via a URL
This commit is contained in:
Lachlan Kermode
2018-12-07 12:02:40 +00:00
parent 5274ac887d
commit aff9b384d1
4 changed files with 81 additions and 53 deletions

View File

@@ -1,20 +1,19 @@
import fs from 'mz/fs'
import { fmtSheetTitle } from '../lib/util'
import copy from '../copy/en'
const STORAGE_DIRNAME = 'temp'
class StoreJson {
save (bp) {
return Promise.all(
Object.keys(bp.routes).map(route =>
fs.writeFile(
`${STORAGE_DIRNAME}/${fmtSheetTitle(
bp.sheet.name
)}__${fmtSheetTitle(bp.name)}__${route}.json`,
JSON.stringify(bp.routes[route].data)
)
)
index () {
return Promise.resolve({})
}
save (url, data) {
const parts = url.split('/')
return fs.writeFile(
`${STORAGE_DIRNAME}/${parts[0]}__${parts[1]}__${parts[2]}.json`,
JSON.stringify(data)
)
}