Files
pnpm/lib/fs/store_json_controller.js
Zoltan Kochan 9bc97e76d4 style: use more ES6 syntax
Use lebab to transpile ES5 code to ES6.
Use eslint to fix styling issues afterwards.
Run all js in strict mode to allow let/const
in Node 4.
2016-08-23 21:12:01 +03:00

22 lines
530 B
JavaScript

'use strict'
const join = require('path').join
const writeFileSync = require('fs').writeFileSync
const readFileSync = require('fs').readFileSync
module.exports = function storeJsonController (storePath) {
const storeJsonPath = join(storePath, 'store.json')
return {
read () {
try {
return JSON.parse(readFileSync(storeJsonPath, 'utf8'))
} catch (err) {
return {}
}
},
save (storeJson) {
writeFileSync(storeJsonPath, JSON.stringify(storeJson, null, 2), 'utf8')
}
}
}