import * as path from 'path' import * as fs from 'fs-extra-promise' import * as Promise from 'bluebird' import { deepMixin } from '@cobalt-engine/utils' import {Storage as Storage} from '../storage' const DEFAULT_CONFIG_PATH = path.resolve(__dirname, '../../../config.json') export class Config{ public static get(): Promise { return Promise.all([fs.readJsonAsync(DEFAULT_CONFIG_PATH), Storage.get()]) .spread((defaultConfig, customConfig) => { return deepMixin(defaultConfig, customConfig || {}) }) } public static getSync(): any { let customConfig: any = Storage.getSync() let defaultConfig: any = fs.readJsonSync(DEFAULT_CONFIG_PATH) return deepMixin(defaultConfig, customConfig) } public static set(newData: any): Promise { return Storage.get() .then(currentConfig => { return deepMixin(currentConfig, newData) }) .then(Storage.set) } public static reset(fields: string[]): Promise{ if(!fields){ return Storage.clear() } return Storage.reset(fields) } }