override.ts
734 Bytes
import { ConfigType } from "../index.d"
import { matchExternalPrefixReg } from "./useWidgetKey"
const getAllConfigFile = async () => {
return import.meta.glob('../components/**/config.ts')
}
const getChartConfigFile = async (path: string) => {
const fileList = await getAllConfigFile()
return fileList[path]() as any
}
export const createComponent = async (configType: ConfigType) => {
const { key, chartKey, category, package: packageName } = configType
const hasExternalPrefix = matchExternalPrefixReg.test(chartKey)
const filePath = `../components${hasExternalPrefix ? '/external' : ''}/${packageName}/${category}/${key}/config.ts`
const chart = await getChartConfigFile(filePath)
return new chart.default()
}