(resave = true)
| 4 | import { I18nConfig, parseI18nConfig } from "@lingo.dev/_spec"; |
| 5 | |
| 6 | export function getConfig(resave = true): I18nConfig | null { |
| 7 | const configFilePath = _getConfigFilePath(); |
| 8 | |
| 9 | const configFileExists = fs.existsSync(configFilePath); |
| 10 | if (!configFileExists) { |
| 11 | return null; |
| 12 | } |
| 13 | |
| 14 | const fileContents = fs.readFileSync(configFilePath, "utf8"); |
| 15 | const rawConfig = JSON.parse(fileContents); |
| 16 | |
| 17 | const result = parseI18nConfig(rawConfig); |
| 18 | const didConfigChange = !_.isEqual(rawConfig, result); |
| 19 | |
| 20 | if (resave && didConfigChange) { |
| 21 | // Ensure the config is saved with the latest version / schema |
| 22 | saveConfig(result); |
| 23 | } |
| 24 | |
| 25 | return result; |
| 26 | } |
| 27 | |
| 28 | export function saveConfig(config: I18nConfig) { |
| 29 | const configFilePath = _getConfigFilePath(); |
no test coverage detected