1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-22 20:55:03 +03:00
tabby/app/lib/config.ts
2023-10-03 08:06:16 +02:00

34 lines
1014 B
TypeScript

import * as fs from 'fs'
import * as path from 'path'
import * as yaml from 'js-yaml'
import { writeFile } from 'atomically'
export const configPath = path.join(process.env.TABBY_CONFIG_DIRECTORY!, 'config.yaml')
const legacyConfigPath = path.join(process.env.TABBY_CONFIG_DIRECTORY!, '../terminus', 'config.yaml')
export function migrateConfig (): void {
if (fs.existsSync(legacyConfigPath) && (
!fs.existsSync(configPath) ||
fs.statSync(configPath).mtime < fs.statSync(legacyConfigPath).mtime
)) {
fs.writeFileSync(configPath, fs.readFileSync(legacyConfigPath))
}
}
export function loadConfig (): any {
migrateConfig()
if (fs.existsSync(configPath)) {
return yaml.load(fs.readFileSync(configPath, 'utf8'))
} else {
return {}
}
}
export async function saveConfig (content: string): Promise<void> {
await writeFile(configPath, content, { encoding: 'utf8' })
await writeFile(configPath + '.backup', content, { encoding: 'utf8' })
}