ack-webpack
Version:
A code bundler that drastically reduces setup time by offering an init prompt of project setup questions and includes a fantastic browser reloader.
29 lines (26 loc) • 667 B
JavaScript
const path = require('path')
const fs = require('fs')
const promisePrompt = require('../promisePrompt.function')
const PackHelp = require('./json.help')
module.exports = class JsonHelp{
getJson(){
try{
const file = fs.readFileSync( this.packPath )
const contents = file.toString()
return JSON.parse( contents )
}catch(e){
if(e && e.code=='ENOENT'){
return {}
}
}
}
loadJson(filePath){
if(this.packJson)return this.packJson
return this.packJson = this.getJson()
}
save(){
this.loadJson()
const write = JSON.stringify(this.packJson, null, 2)
fs.writeFileSync(this.packPath, write)
}
}