import * as path from 'path' import * as Promise from 'bluebird' import * as fs from 'fs-extra-promise' interface Settings { id: string, name: string, tag?: string } type SettingsKeys = keyof Settings type SettingsKeysTypes = Settings[SettingsKeys] export default class PresentationSettings { private settingsPath: string constructor(directory: string){ this.settingsPath = path.resolve(directory, 'app', 'settings', 'app.json') } get (key: SettingsKeys): Promise { return this.readSettings() .get(key) } set (key: SettingsKeys, value: SettingsKeysTypes): Promise { return this.readSettings() .then(this.setValue(key, value)) .then(settings => this.outputSettings(settings)) } private readSettings (): Promise { return fs.readJsonAsync(this.settingsPath) } private setValue (key: SettingsKeys, value: SettingsKeysTypes): (settings: Settings) => Promise { return function (settings) { return Promise.resolve({ ...settings, [key]: value }); } } private outputSettings (settings: Settings): Promise { return fs.outputJsonAsync(this.settingsPath, settings) } }