Skip to content

Commit

Permalink
Add astroENVConfig Utility, and migrate namespaceplugin to addVitePlu…
Browse files Browse the repository at this point in the history
…gin AIK Utility (#162)

Co-authored-by: Jacob Jenkins <[email protected]>
Co-authored-by: Paul Valladares <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent ebad8d2 commit b8eba07
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
9 changes: 4 additions & 5 deletions packages/studioCMS/src/coreIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkAstroConfig, studioLogger, studioLoggerOptsResolver, makeFrontend, addIntegrationArray, addIntegrationArrayWithCheck } from './utils';
import { studioCMSRobotsTXT, studioCMSImageHandler, studioCMSDashboard } from './integrations';
import { addDts, addVirtualImports, createResolver, defineIntegration } from 'astro-integration-kit';
import { addDts, addVirtualImports, addVitePlugin, createResolver, defineIntegration } from 'astro-integration-kit';
import 'astro-integration-kit/types/db';
import { optionsResolver, vResolver } from './resolvers';
// import inoxsitemap from '@inox-tools/sitemap-ext';
Expand Down Expand Up @@ -33,17 +33,16 @@ export default defineIntegration({
'astro:config:setup': async ( params ) => {

// Destructure Params
const { config: astroConfig, addWatchFile, updateConfig } = params;
const { config: astroConfig, addWatchFile } = params;

// Watch the StudioCMS Config File for changes (including creation/deletion)
addWatchFile(getStudioConfigFileUrl(astroConfig.root));

// Resolve Options
const resolvedOptions = await optionsResolver(params, options);

updateConfig({
vite: { plugins: [namespaceBuiltinsPlugin()] }
})
// Add Namespace Builtins Plugin for vite
addVitePlugin(params, { plugin: namespaceBuiltinsPlugin() })

// Create Runtime Logger
runtimeLogger(params, { name: "StudioCMS" })
Expand Down
26 changes: 10 additions & 16 deletions packages/studioCMS/src/integrations/imageHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { cloudflareImageHandler, netlifyImageHandler, nodeImageHandler, vercelIm
import { optionsSchema } from './schemas';
import { imageHandlerStrings } from './strings';
import { componentResolver } from './componentResolver';
import { addAstroEnvConfig } from '../../utils/astroEnvConfig';

export default defineIntegration({
name: '@astrolicious/studioCMS:imageHandler',
Expand All @@ -16,10 +17,7 @@ export default defineIntegration({
hooks: {
"astro:config:setup": async ( params ) => {

const {
config: { adapter },
updateConfig,
} = params;
const { config: { adapter } } = params;

const { verbose, imageService: { cdnPlugin } } = options;

Expand All @@ -32,19 +30,15 @@ export default defineIntegration({
'@astrojs/netlify'
];

updateConfig({
experimental: {
env: {
schema: {
CMS_CLOUDINARY_CLOUDNAME: envField.string({
context: 'server',
access: 'secret',
optional: true,
})
}
}
addAstroEnvConfig(params,{
schema: {
CMS_CLOUDINARY_CLOUDNAME: envField.string({
context: 'server',
access: 'secret',
optional: true,
})
}
})
});

if (cdnPlugin === 'cloudinary-js') {
if (!env.CMS_CLOUDINARY_CLOUDNAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { usernameAndPasswordAuthConfig } from "./studioauth-config";
import type { IconifyJSON } from '@iconify/types';
import { checkForWebVitals } from "./utils/vitals";
import astrolace from '@matthiesenxyz/astrolace';
import { addAstroEnvConfig } from "../../utils/astroEnvConfig";

export default defineIntegration({
name: '@astrolicious/studioCMS:adminDashboard',
Expand All @@ -31,9 +32,7 @@ export default defineIntegration({
loadKeys(params.logger, options);

// Update Astro Config with Environment Variables (`astro:env`)
params.updateConfig({
experimental: { env: astroENV }
});
addAstroEnvConfig(params, astroENV)

// Virtual Imports and DTS File Creation
virtualResolver(params, { name });
Expand Down
16 changes: 9 additions & 7 deletions packages/studioCMS/src/schemas/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import { z } from 'astro/zod';
export const includedIntegrationsSchema = z
.object({
/**
* Allows the user to enable/disable the use of the Astro Robots Plugin
* Allows the user to enable/disable the use of the StudioCMS Custom `astro-robots-txt` Integration
*
* @default true
*/
useAstroRobots: z.boolean().optional().default(true),
astroRobotsConfig: z.custom<RobotsConfig>().default({}),
// /**
// * Allows the user to enable/disable the use of the Inox-tools Sitemap Plugin
// * For more information on the Inox-tools Sitemap Plugin, visit:
// * @see https://inox-tools.vercel.app/sitemap-ext
// * @default true
// */
/**
* Allows the user to enable/disable the use of the Inox-tools Sitemap Plugin
* For more information on the Inox-tools Sitemap Plugin, visit:
* @see https://inox-tools.vercel.app/sitemap-ext
*
* # TEMPORARILY DISABLED
* If you would like to still use the Inox-tools Sitemap Plugin, you can manually add it to your project's Integrations.
*/
useInoxSitemap: z.boolean().optional().default(true),
})
.optional()
Expand Down
16 changes: 16 additions & 0 deletions packages/studioCMS/src/utils/astroEnvConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { AstroConfig } from "astro";
import { defineUtility } from "astro-integration-kit";


export const addAstroEnvConfig = defineUtility("astro:config:setup")(
(
params,
config: AstroConfig['experimental']['env']
) => {

// Update Astro Config with Environment Variables (`astro:env`)
params.updateConfig({
experimental: { env: config }
});

})

0 comments on commit b8eba07

Please sign in to comment.