UNPKG

1.02 kBJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const fs = require('fs')
5const PLUGIN_PATH = require('./path').PLUGIN_PATH
6
7const filename = 'config.json'
8const filePath = path.join(PLUGIN_PATH, filename)
9
10const formatBoolean = value => {
11 if (value === 'true') {
12 return true
13 } else if (value === 'false') {
14 return false
15 }
16
17 return value
18}
19const requireFile = () => {
20 return require(filePath)
21}
22
23exports.init = () => {
24 if (!fs.existsSync(filePath)) {
25 const config = {
26 template: 'vue',
27 registry: '',
28 updateCheck: true,
29 github: '',
30 author: ''
31 }
32
33 fs.writeFileSync(filePath, JSON.stringify(config, null, 2))
34 }
35}
36
37exports.get = option => {
38 if (!option) {
39 return requireFile()
40 }
41
42 return requireFile()[option]
43}
44
45exports.set = (option, value) => {
46 const config = requireFile()
47
48 if (config[option] !== undefined) {
49 config[option] = formatBoolean(value)
50 fs.writeFileSync(filePath, JSON.stringify(config, null, 2))
51
52 return true
53 }
54
55 return false
56}