Merge sources from config files
This commit is contained in:
parent
73ab0a61d7
commit
cc353d310b
4 changed files with 53 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import { createThemeFn } from '../../theme-fn'
|
|||
import { deepMerge, isPlainObject } from './deep-merge'
|
||||
import {
|
||||
type ResolvedConfig,
|
||||
type ResolvedContentConfig,
|
||||
type ResolvedThemeValue,
|
||||
type ThemeValue,
|
||||
type UserConfig,
|
||||
|
|
@ -18,6 +19,7 @@ interface ResolutionContext {
|
|||
design: DesignSystem
|
||||
configs: UserConfig[]
|
||||
plugins: PluginWithConfig[]
|
||||
content: ResolvedContentConfig
|
||||
theme: Record<string, ThemeValue>
|
||||
extend: Record<string, ThemeValue[]>
|
||||
result: ResolvedConfig
|
||||
|
|
@ -26,6 +28,9 @@ interface ResolutionContext {
|
|||
let minimal: ResolvedConfig = {
|
||||
theme: {},
|
||||
plugins: [],
|
||||
content: {
|
||||
files: [],
|
||||
},
|
||||
}
|
||||
|
||||
export function resolveConfig(design: DesignSystem, files: ConfigFile[]): ResolvedConfig {
|
||||
|
|
@ -33,6 +38,9 @@ export function resolveConfig(design: DesignSystem, files: ConfigFile[]): Resolv
|
|||
design,
|
||||
configs: [],
|
||||
plugins: [],
|
||||
content: {
|
||||
files: [],
|
||||
},
|
||||
theme: {},
|
||||
extend: {},
|
||||
|
||||
|
|
@ -48,6 +56,7 @@ export function resolveConfig(design: DesignSystem, files: ConfigFile[]): Resolv
|
|||
mergeTheme(ctx)
|
||||
|
||||
return {
|
||||
content: ctx.content,
|
||||
theme: ctx.theme as ResolvedConfig['theme'],
|
||||
plugins: ctx.plugins,
|
||||
}
|
||||
|
|
@ -125,6 +134,18 @@ function resolveInternal(ctx: ResolutionContext, { config, path }: ConfigFile):
|
|||
}
|
||||
}
|
||||
|
||||
// Merge in content paths from multiple configs
|
||||
let content = config.content ?? []
|
||||
let files = Array.isArray(content) ? content : content.files
|
||||
|
||||
for (let file of files) {
|
||||
ctx.content.files.push(
|
||||
typeof file === 'object'
|
||||
? file
|
||||
: { base: path!, pattern: file }
|
||||
)
|
||||
}
|
||||
|
||||
// Then apply the "user" config
|
||||
ctx.configs.push(config)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,3 +20,22 @@ export interface ResolvedConfig {
|
|||
theme: Record<string, Record<string, unknown>>
|
||||
plugins: PluginWithConfig[]
|
||||
}
|
||||
|
||||
// Content support
|
||||
type ContentFile = string | { raw: string; extension?: string }
|
||||
|
||||
export interface UserConfig {
|
||||
content?: ContentFile[] | { files: ContentFile[] }
|
||||
}
|
||||
|
||||
type ResolvedContent =
|
||||
| { base: string, pattern: string }
|
||||
| { raw: string; extension?: string }
|
||||
|
||||
export interface ResolvedContentConfig {
|
||||
files: ResolvedContent[],
|
||||
}
|
||||
|
||||
export interface ResolvedConfig {
|
||||
content: ResolvedContentConfig
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ async function parseCss(
|
|||
|
||||
let plugins = await Promise.all(pluginPaths.map(loadPlugin))
|
||||
|
||||
let pluginApi = registerPlugins(plugins, designSystem, ast, configs)
|
||||
let { pluginApi, resolvedConfig } = registerPlugins(plugins, designSystem, ast, configs)
|
||||
|
||||
// Replace `@apply` rules with the actual utility classes.
|
||||
if (css.includes('@apply')) {
|
||||
|
|
@ -338,6 +338,14 @@ async function parseCss(
|
|||
return WalkAction.Skip
|
||||
})
|
||||
|
||||
for (let file of resolvedConfig.content.files) {
|
||||
if ('raw' in file) {
|
||||
throw new Error('raw content is not currently supported')
|
||||
}
|
||||
|
||||
globs.push(file.pattern)
|
||||
}
|
||||
|
||||
return {
|
||||
designSystem,
|
||||
pluginApi,
|
||||
|
|
|
|||
|
|
@ -362,5 +362,8 @@ export function registerPlugins(
|
|||
handler(pluginApi)
|
||||
}
|
||||
|
||||
return pluginApi
|
||||
return {
|
||||
pluginApi,
|
||||
resolvedConfig,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue