From 1a9258463b1efddb757878385405bbab241685fd Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Sat, 24 Feb 2024 08:03:37 -0800 Subject: [PATCH] some progress. and prep to add new component --- package/src/integration.ts | 32 ++++++++++++++++++++++++++++---- package/src/utils.ts | 4 ++++ playground/astro.config.mjs | 1 - 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/package/src/integration.ts b/package/src/integration.ts index 4998389..71c3e4a 100644 --- a/package/src/integration.ts +++ b/package/src/integration.ts @@ -2,26 +2,50 @@ import { defineIntegration, createResolver } from "astro-integration-kit" import { corePlugins } from "astro-integration-kit/plugins" import { astroGistsExpressiveCode } from "./integrations/expressive-code" - +/** Astro-Gist - Astro Integration + * - There is currently no configuration for this integration. Just add it to your astro Integration list. + * @example + * import astroGist from "@matthiesenxyz/astro-gists"; + * export default defineConfig({ + * integrations: [astroGist()] + * }); +*/ export default defineIntegration({ name: "@matthiesenxyz/astro-gists", plugins: [...corePlugins], setup() { const { resolve } = createResolver(import.meta.url); - return { - "astro:config:setup": ({ watchIntegration, config, updateConfig, logger }) => { - watchIntegration(resolve()) + return { + "astro:config:setup": ({ + watchIntegration, + config, + updateConfig, + logger + }) => { + // WATCH INTEGRATION FOR CHANGES + watchIntegration(resolve()) // IMPORT INTEGRATIONS & INTEGRATION ROUTES const integrations = [...config.integrations]; + // ADD ASTRO-EXPRESSIVE-CODE INTEGRATION if (!integrations.find(({ name }) => name === "astro-expressive-code")) { logger.info("Adding astro-expressive-code integration") updateConfig({ integrations: [...integrations, ...astroGistsExpressiveCode()] }) } + + // UPDATE ASTRO-EXPRESSIVE-CODE INTEGRATION + try { + updateConfig({ + integrations: [...astroGistsExpressiveCode()] + }) + } catch (e) { + logger.error(e as string); + throw e; + } } } } diff --git a/package/src/utils.ts b/package/src/utils.ts index 0f6eab4..e2195f3 100644 --- a/package/src/utils.ts +++ b/package/src/utils.ts @@ -1,15 +1,19 @@ import { Octokit } from "octokit"; import { loadEnv } from "vite"; +// Load environment variables const { GITHUB_PERSONAL_TOKEN } = loadEnv("all", process.cwd(), "GITHUB_"); +// Create an Octokit instance export const octokit = new Octokit({ auth: GITHUB_PERSONAL_TOKEN }); +// Get a Gist by ID export const getGist = async (gistId: string) => { const { data } = await octokit.request('GET /gists/{gist_id}', { gist_id: gistId }); return data; }; +// Get a file from a Gist by ID and filename export const getGistFile = async ( gistId: string, filename: string diff --git a/playground/astro.config.mjs b/playground/astro.config.mjs index ac8781b..e334110 100644 --- a/playground/astro.config.mjs +++ b/playground/astro.config.mjs @@ -1,7 +1,6 @@ import { defineConfig } from "astro/config"; import astroGist from "@matthiesenxyz/astro-gists"; - // https://astro.build/config export default defineConfig({ integrations: [astroGist()]