From 5b4c3e32681f25cc9f3018574bdf427963a70b18 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Mon, 4 Mar 2024 12:02:55 -0800 Subject: [PATCH] cleanup and OCD some code... --- packages/astro-ghostcms/package.json | 3 + packages/astro-ghostcms/src/astro-ghostcms.ts | 73 ++++++++++--------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/packages/astro-ghostcms/package.json b/packages/astro-ghostcms/package.json index 0a2c4e0d..31f6a096 100644 --- a/packages/astro-ghostcms/package.json +++ b/packages/astro-ghostcms/package.json @@ -56,6 +56,9 @@ "test:coverage": "vitest run --coverage", "test:ci": "vitest run --coverage.enabled --coverage.reporter='text-summary'" }, + "enginesStrict": { + "node": ">=18.19.0" + }, "peerDependencies": { "astro": ">=4.4.1" }, diff --git a/packages/astro-ghostcms/src/astro-ghostcms.ts b/packages/astro-ghostcms/src/astro-ghostcms.ts index e2813800..bcc955f1 100644 --- a/packages/astro-ghostcms/src/astro-ghostcms.ts +++ b/packages/astro-ghostcms/src/astro-ghostcms.ts @@ -50,19 +50,25 @@ export default defineIntegration({ }) => { // Set up verbose logging const verbose = options.verbose; + // Configure Loggers const GhostLogger = logger.fork(c.bold(c.blue("👻 Astro-GhostCMS"))); + + // Configure ENV Logger const GhostENVLogger = logger.fork( `${c.bold(c.blue("👻 Astro-GhostCMS"))}${c.gray("/")}${c.blue( "ENV Check", )}`, ); + // Configure Integration Loggers & verbose logging const GhostIntegrationLogger = logger.fork( `${c.bold(c.blue("👻 Astro-GhostCMS"))}${c.gray("/")}${c.blue( "Integrations", )}`, ); + + // Log Info Helper const intLogInfo = (message:string) => { if (verbose) { GhostIntegrationLogger.info(message); @@ -75,12 +81,46 @@ export default defineIntegration({ "Router", )}`, ); + + // Log Route Info Helper const routeLogInfo = (message:string) => { if (verbose) { GhostRouteLogger.info(message); } }; + // Local Integration Helper + const localIntegration = (enabled: boolean, name: string, integration: AstroIntegration) => { + if (enabled) { + addIntegration(integration); + } else { + intLogInfo(c.gray(`${name} integration is disabled`)); + } + } + + // Check External Integration Helper + const checkIntegration = (name: string, integration: AstroIntegration) => { + if (!hasIntegration(name)) { + intLogInfo(c.bold(c.magenta(`Adding ${c.blue(name)} integration`))); + addIntegration(integration); + } else { + intLogInfo(c.gray(`${name} integration already exists, skipping...`)); + } + } + + // Inject Route Helper + const routeHelper = (routename: string, enabled: boolean, pattern: string, entrypoint: string) => { + if (enabled) { + routeLogInfo(c.bold(c.cyan(`Setting up ${routename} route`))); + injectRoute({ + pattern: pattern, + entrypoint: `${name}${entrypoint}`, + prerender: true, + }); + } else { + routeLogInfo(c.gray(`${routename} route is disabled, Skipping...`)); + } + } // Setup Watch Integration for Hot Reload during DEV watchIntegration(resolve()); @@ -143,39 +183,6 @@ export default defineIntegration({ c.bold(c.magenta("Configuring Enabled Integrations")), ); - // Local Integration Helper - const localIntegration = (enabled: boolean, name: string, integration: AstroIntegration) => { - if (enabled) { - addIntegration(integration); - } else { - intLogInfo(c.gray(`${name} integration is disabled`)); - } - } - - // Check External Integration Helper - const checkIntegration = (name: string, integration: AstroIntegration) => { - if (!hasIntegration(name)) { - intLogInfo(c.bold(c.magenta(`Adding ${c.blue(name)} integration`))); - addIntegration(integration); - } else { - intLogInfo(c.gray(`${name} integration already exists, skipping...`)); - } - } - - // Inject Route Helper - const routeHelper = (routename: string, enabled: boolean, pattern: string, entrypoint: string) => { - if (enabled) { - routeLogInfo(c.bold(c.cyan(`Setting up ${routename} route`))); - injectRoute({ - pattern: pattern, - entrypoint: `${name}${entrypoint}`, - prerender: true, - }); - } else { - routeLogInfo(c.gray(`${routename} route is disabled, Skipping...`)); - } - } - localIntegration( !options.ThemeProvider?.disableThemeProvider, "Theme Provider",