Skip to content

Commit

Permalink
feat: add plugins configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurTriis1 committed Nov 14, 2024
1 parent 97a2bdb commit bb8f5c0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/cli/src/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ import { withBasePath } from './directory'
import path from 'path'
import { logger } from './logger'

type PageConfig = {
export type PageConfig = {
path: string
appLayout: boolean
name: string
}

type Plugin =
export type PluginConfig = {
pages?: { [pageName: string]: Partial<PageConfig> }
}

export type Plugin =
| string
| {
[pluginName: string]: {
pages?: { [pageName: string]: Partial<PageConfig> }
}
[pluginName: string]: PluginConfig
}

const pluginConfigFileName = 'plugin.config.js'
const PLUGIN_CONFIG_FILE = 'plugin.config.js'

const sanitizePluginName = (pluginName: string, pascalCase = false) => {
const sanitized = pluginName.split('/')[1]
Expand Down Expand Up @@ -46,7 +48,7 @@ const getPluginCustomConfig = (plugin: Plugin) => {
return {}
}

return plugin[Object.keys(plugin)[0]]
return plugin[getPluginName(plugin)]
}

const getPluginSrcPath = async (basePath: string, pluginName: string) => {
Expand Down Expand Up @@ -122,7 +124,7 @@ const generatePluginPages = async (basePath: string, plugins: Plugin[]) => {

plugins.forEach(async (plugin) => {
const pluginName = getPluginName(plugin)
const pluginConfigPath = getPackagePath(pluginName, pluginConfigFileName)
const pluginConfigPath = getPackagePath(pluginName, PLUGIN_CONFIG_FILE)

const pluginConfig = await import(pluginConfigPath)

Expand Down

0 comments on commit bb8f5c0

Please sign in to comment.