mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-26 14:32:04 -04:00
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import fs from 'fs/promises';
|
|
|
|
// import { createGenerator } from 'ts-json-schema-generator';
|
|
|
|
import type { Config } from '~~/locale/config.ts';
|
|
import localeDescriptions from '~~/locale/locales.ts';
|
|
import { loadSuml } from '~~/server/loader.ts';
|
|
|
|
const __dirname = new URL('.', import.meta.url).pathname;
|
|
|
|
// const generateJsonSchema = async (path: string, typeName: string) => {
|
|
// const schema = createGenerator({
|
|
// path,
|
|
// tsconfig: `${__dirname}/../.nuxt/tsconfig.node.json`,
|
|
// strictTuples: true,
|
|
// markdownDescription: true,
|
|
// // speed up schema generation; type checking happens separately
|
|
// skipTypeCheck: true,
|
|
// }).createSchema(typeName);
|
|
|
|
// await fs.writeFile(
|
|
// `${__dirname}/${typeName[0].toLowerCase()}${typeName.substring(1)}.schema.json`,
|
|
// `${JSON.stringify(schema, null, 4)}\n`,
|
|
// );
|
|
// };
|
|
|
|
const generateFontsModule = async () => {
|
|
const configByLocale = Object.fromEntries(await Promise.all(localeDescriptions.map(async (locale) => {
|
|
return [locale.code, await loadSuml<Config>(`locale/${locale.code}/config.suml`)] as const;
|
|
})));
|
|
|
|
const fontHeadingsByLocale = Object.fromEntries(Object.entries(configByLocale)
|
|
.map(([localeCode, config]) => [localeCode, config.style.fontHeadings]));
|
|
|
|
await fs.writeFile(
|
|
`${__dirname}/fonts.ts`,
|
|
`export const fontHeadingsByLocale: Record<string, string[]> = ${JSON.stringify(fontHeadingsByLocale)}`,
|
|
);
|
|
};
|
|
|
|
await Promise.all([
|
|
// ! throws errors
|
|
// generateJsonSchema(`${__dirname}/config.ts`, 'Config'),
|
|
// generateJsonSchema(`${__dirname}/../src/nouns.ts`, 'NounsData'),
|
|
generateFontsModule(),
|
|
]);
|