35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
// Generated, do not edit. sha256:6cbe401d306ec892f1f72668153c40a7ef9e20306ce9e0d40df746e713359910
|
|
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { CONFIG } from '../shared/config.js';
|
|
import { installDir } from './portfolios.mjs';
|
|
|
|
const file = () => join(installDir(), CONFIG.INSTALLATION.SETTINGS_FILE_NAME);
|
|
|
|
function read() {
|
|
try { return JSON.parse(readFileSync(file(), 'utf8')); }
|
|
catch (e) { if (e.code === 'ENOENT') return {}; throw e; }
|
|
}
|
|
|
|
function write(settings) {
|
|
mkdirSync(installDir(), { recursive: true });
|
|
writeFileSync(file(), `${JSON.stringify(settings, null, 2)}\n`);
|
|
}
|
|
|
|
const known = code => Object.hasOwn(CONFIG.LOCALE_TAGS, code);
|
|
|
|
export function installLocale() {
|
|
const { locale } = read();
|
|
return known(locale) ? locale : CONFIG.INSTALLATION.DEFAULT_LOCALE;
|
|
}
|
|
|
|
export function setInstallLocale(code) {
|
|
if (!known(code)) throw new Error(`Unknown locale: '${code}'.`);
|
|
write({ ...read(), locale: code });
|
|
}
|
|
|
|
export function adoptInstallLocale(fromPortfolio) {
|
|
if (known(read().locale)) return;
|
|
setInstallLocale(known(fromPortfolio) ? fromPortfolio : CONFIG.INSTALLATION.DEFAULT_LOCALE);
|
|
}
|