better config typings... made it way better XD

This commit is contained in:
Adam Matthiesen 2024-03-05 00:11:03 -08:00
parent 30ad4ac355
commit b50e8882cc
7 changed files with 27 additions and 23 deletions

View File

@ -177,10 +177,10 @@ export default defineIntegration({
// Setup GhostCMS Theme Provider // Setup GhostCMS Theme Provider
localIntegration( localIntegration(
!options.ThemeProvider?.disableThemeProvider, !options.ThemeProvider.disableThemeProvider,
"Theme Provider", "Theme Provider",
ghostThemeProvider({ ghostThemeProvider({
theme: options.ThemeProvider?.theme, theme: options.ThemeProvider.theme,
verbose, verbose,
}) })
); );

View File

@ -6,7 +6,7 @@ import c from "picocolors";
export default defineIntegration({ export default defineIntegration({
name: "@matthiesenxyz/astro-ghostcms-rss", name: "@matthiesenxyz/astro-ghostcms-rss",
optionsSchema: z.object({ optionsSchema: z.object({
verbose: z.boolean().optional().default(false), verbose: z.coerce.boolean().optional(),
}), }),
plugins: [...corePlugins], plugins: [...corePlugins],
setup({ options }) { setup({ options }) {

View File

@ -6,7 +6,7 @@ import c from "picocolors";
export default defineIntegration({ export default defineIntegration({
name: "@matthiesenxyz/astro-ghostcms-satoriog", name: "@matthiesenxyz/astro-ghostcms-satoriog",
optionsSchema: z.object({ optionsSchema: z.object({
verbose: z.boolean().optional().default(false), verbose: z.coerce.boolean().optional(),
}), }),
plugins: [...corePlugins], plugins: [...corePlugins],
setup({ options }) { setup({ options }) {

View File

@ -6,16 +6,15 @@ import c from "picocolors";
export default defineIntegration({ export default defineIntegration({
name: "@matthiesenxyz/astro-ghostcms-themeprovider", name: "@matthiesenxyz/astro-ghostcms-themeprovider",
optionsSchema: z.object({ optionsSchema: z.object({
theme: z theme: z.string(),
.string() verbose: z.coerce.boolean().optional(),
.optional()
.default("@matthiesenxyz/astro-ghostcms-theme-default"),
verbose: z.boolean().optional().default(false),
}), }),
plugins: [...corePlugins], plugins: [...corePlugins],
setup({ options }) { setup({ options }) {
const { resolve } = createResolver(import.meta.url); const { resolve } = createResolver(import.meta.url);
const DEFAULT_THEME = "@matthiesenxyz/astro-ghostcms-theme-default";
return { return {
"astro:config:setup": ({ watchIntegration, injectRoute, logger }) => { "astro:config:setup": ({ watchIntegration, injectRoute, logger }) => {
watchIntegration(resolve()); watchIntegration(resolve());
@ -37,7 +36,7 @@ export default defineIntegration({
); );
if (options.theme === "@matthiesenxyz/astro-ghostcms-theme-default") { if (options.theme === DEFAULT_THEME) {
verboseLogsInfo( verboseLogsInfo(
c.blue("No theme is set, injecting default theme"), c.blue("No theme is set, injecting default theme"),
); );

View File

@ -13,6 +13,7 @@ describe("GhostUserConfigSchema", () => {
enableRSSFeed: true, enableRSSFeed: true,
enableOGImages: true, enableOGImages: true,
verbose: false, verbose: false,
Integrations: {},
}; };
const result = GhostUserConfigSchema.safeParse(validConfig); const result = GhostUserConfigSchema.safeParse(validConfig);

View File

@ -13,34 +13,38 @@ export const GhostUserConfigSchema = z.object({
* }) * })
* ], * ],
* }); */ * }); */
ghostURL: z.string().url().optional(), ghostURL: z.coerce.string().url("Must be a URL").optional(),
/** OPTIONAL - Configure the Theme Provider
* @ This option allows the user to configure the Theme Provider
*/
ThemeProvider: z ThemeProvider: z
.object({ .object({
/** OPTIONAL - Disable the theme provider /** OPTIONAL - Disable the theme provider
* @default false * @default false
*/ */
disableThemeProvider: z.boolean().optional().default(false), disableThemeProvider: z.coerce.boolean(),
/** OPTIONAL - Set the theme you want to use /** OPTIONAL - Set the theme you want to use
* @default "@matthiesenxyz/astro-ghostcms-theme-default" * @default "@matthiesenxyz/astro-ghostcms-theme-default"
*/ */
theme: z theme: z.string(),
.string()
.optional()
.default("@matthiesenxyz/astro-ghostcms-theme-default"),
}) })
.optional(), .optional()
.default({
disableThemeProvider: false,
theme: "@matthiesenxyz/astro-ghostcms-theme-default"
}),
/** Allows the user to disable the provided 404 page */ /** Allows the user to disable the provided 404 page */
disableDefault404: z.boolean().optional().default(false), disableDefault404: z.coerce.boolean().optional(),
/** Allows the user to disable the provided RSS Feed */ /** Allows the user to disable the provided RSS Feed */
enableRSSFeed: z.boolean().optional().default(true), enableRSSFeed: z.coerce.boolean().optional().default(true),
/** Allows the user to Enable or Disable the default Satori OG Image Generation /** Allows the user to Enable or Disable the default Satori OG Image Generation
* @default true * @default true
*/ */
enableOGImages: z.boolean().optional().default(true), enableOGImages: z.coerce.boolean().optional().default(true),
/** Allows the user to turn on/off Full Console Logs /** Allows the user to turn on/off Full Console Logs
* @default true * @default true
*/ */
verbose: z.boolean().optional().default(false), verbose: z.coerce.boolean().optional(),
/** OPTIONAL - Integrations Configuration /** OPTIONAL - Integrations Configuration
* This option allows the user to configure the included integrations * This option allows the user to configure the included integrations
* Options shown are the availble options * Options shown are the availble options
@ -60,7 +64,7 @@ export const GhostUserConfigSchema = z.object({
*/ */
sitemap: z.custom<SitemapOptions>().optional(), sitemap: z.custom<SitemapOptions>().optional(),
}) })
.optional(), .optional().default({}),
}); });
/** USER CONFIGURATION SCHEMA */ /** USER CONFIGURATION SCHEMA */

View File

@ -14,7 +14,7 @@ export default defineConfig({
ThemeProvider: { ThemeProvider: {
theme: "@matthiesenxyz/astro-ghostcms-brutalbyelian", theme: "@matthiesenxyz/astro-ghostcms-brutalbyelian",
}, },
verbose: false, verbose: true,
}), }),
], ],
}); });