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', postes: {} }, getters: { data_dir: (state) => { return state.data_dir }, config_dir: (state) => { return state.config_dir }, config_filename: (state) => { return state.config_filename }, postes: (state) => { return state.postes } }, mutations: { SET_POSTES: (state, { postes }) => { state.postes = postes } }, 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_POSTES', { postes: parsed.postes }) } }) } } }