Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
Something went wrong. Try again.
4.4 kB · 95 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import { writeFileSync, mkdirSync } from "node:fs";import { resolve } from "path";import * as z from 'zod';import { clientConfigSchemaMapAsync } from '../common/infrastructure/config/client/clientsMap.ts';import { projectRootDir } from "../common/infrastructure/Atomic.ts";import { aioConfigSchema } from "../common/infrastructure/config/aioConfig.ts";import { generateCommonComponentEnvConfigSchema } from "../common/infrastructure/config/common.ts";import { zodObjectToTableColumns, type TableColumn } from "./ZodUtils.ts";import {markdownTable} from 'markdown-table'import { sourceAIOConfigSchema } from "../common/infrastructure/config/source/sources.ts";import { sourceConfigSchemaMapAsync } from "../common/infrastructure/config/source/sourcesMap.ts";import { clientAIOConfigSchema } from "../common/infrastructure/config/client/clients.ts";
mkdirSync(resolve(projectRootDir, 'docsite/static/schemas'), {recursive: true});
const mdCols = (cols: TableColumn[]): string[][] => cols.map((x) => { const name = `\`${x.title}\``; return [ x.required ? `_**${name}**_` : name, Array.isArray(x.type) ? x.type.join(' OR ') : x.type, (x.default ?? '').toString(), x.description ?? '' ]})
const generateSchema = (schema: z.ZodType, reused: z.core.ToJSONSchemaParams['reused'] = 'inline') => z.toJSONSchema(schema, { io: "input", reused, target: "draft-2020-12", unrepresentable: "any", override: (ctx) => { if(ctx.jsonSchema.anyOf !== undefined && Array.isArray(ctx.jsonSchema.anyOf)) { for(const a of ctx.jsonSchema.anyOf) { if(a.const !== undefined) { a.enum = [a.const]; delete a.const; } } //return; } if(ctx.jsonSchema.oneOf !== undefined) { for(const a of ctx.jsonSchema.oneOf) { if(a.const !== undefined) { a.enum = [a.const]; delete a.const; } } //return; } if(ctx.jsonSchema.const !== undefined) { ctx.jsonSchema.enum = [ctx.jsonSchema.const]; delete ctx.jsonSchema.const; return } } })
const clientEntries = Object.entries(clientConfigSchemaMapAsync);for(const [k,v] of clientEntries) { const [fileSchema, aioSchema, envSchemas] = await v(); writeFileSync(resolve(projectRootDir, `docsite/static/schemas/${k}-client.json`), JSON.stringify(generateSchema(z.array(fileSchema))));
const envSchema = envSchemas; const common = generateCommonComponentEnvConfigSchema(envSchema.prefix.toUpperCase()); const commonCol = zodObjectToTableColumns(z.object(common.shape), 'out'); const col = [...commonCol,...zodObjectToTableColumns(z.object(envSchema.env.shape), envSchemas.pipe ?? 'out')] const tableContent = markdownTable([ ['Environmental Variable', 'Type', 'Default', 'Description'], ...mdCols(col) ]); writeFileSync(resolve(projectRootDir, `docsite/docs/configuration/clients/_env_configs/_${k}.md`), tableContent);}
const sourcesEntries = Object.entries(sourceConfigSchemaMapAsync);for(const [k,v] of sourcesEntries) { const [fileSchema, aioSchema, envSchemas] = await v(); writeFileSync(resolve(projectRootDir, `docsite/static/schemas/${k}-source.json`), JSON.stringify(generateSchema(z.array(fileSchema))));
const envSchema = envSchemas; const common = generateCommonComponentEnvConfigSchema(envSchema.prefix.toUpperCase()); const commonCol = zodObjectToTableColumns(z.object(common.shape), 'out'); const col = [...commonCol,...zodObjectToTableColumns(z.object(envSchema.env.shape), envSchemas.pipe ?? 'out')] const tableContent = markdownTable([ ['Environmental Variable', 'Type', 'Default', 'Description'], ...mdCols(col) ]); writeFileSync(resolve(projectRootDir, `docsite/docs/configuration/sources/_env_configs/_${k}.md`), tableContent);}
const aioStrongConfigSchema = aioConfigSchema.extend({ sources: z.array(sourceAIOConfigSchema).optional(), clients: z.array(clientAIOConfigSchema).optional()})
writeFileSync(resolve(projectRootDir, 'docsite/static/schemas/aio.json'), JSON.stringify(generateSchema(aioStrongConfigSchema, 'ref')));