comptes/src/store/modules/config.js

48 lines
1.1 KiB
JavaScript

import { readFile } from 'fs'
import path from 'path'
import yaml from 'js-yaml'
export default {
namespaced: true,
state: {
data_dir: '/home/lafrite/scripts/comptes/data/',
config_dir: '/home/lafrite/scripts/comptes/config/',
config_filename: 'config.yml',
tags: {}
},
getters: {
data_dir: (state) => {
return state.data_dir
},
config_dir: (state) => {
return state.config_dir
},
config_filename: (state) => {
return state.config_filename
},
tags: (state) => {
return state.tags
}
},
mutations: {
SET_TAGS: (state, { tags }) => {
state.tags = tags
}
},
actions: {
load(context) {
readFile(path.join(context.getters.config_dir, context.getters.config_filename), 'utf8', (err, content) => {
if (err) {
console.log(err)
} else {
var parseConfig = {
header: true
}
var parsed = yaml.safeLoad(content, parseConfig)
context.commit('SET_TAGS', { tags: parsed.tags })
}
})
}
}
}