Commit 975798529e4fa446a7dc476c44f7b43d8d2545f3

Authored by fengwotao
1 parent dee9cae0

fix(src/packages/): 修复之前未移动组件路径的项目导入问题

  1 +/**
  2 + * 兼容配置文件
  3 + * 如果匹配到之前移动路径的组件则替换为现在正确的路径
  4 + * 比如之前摄像头是放在组合Compose包下,现在移动到Informations信息包下了,那么找到这个组件,替换为正确的包名即可
  5 + */
  6 +export const compatibleConfig = [
  7 + {
  8 + key: 'SingleCamera', //单个摄像头
  9 + oldPackage: 'Composes', //之前的包名
  10 + newPackage: 'Informations', //新的包名
  11 + oldCategory: 'Mores', //之前的目录
  12 + newCategory: 'Mores', //新的目录
  13 + oldCategoryName: '更多', //之前的目录名
  14 + newCategoryName: '更多' //新的目录名
  15 + },
  16 + {
  17 + key: 'Camera', //多个摄像头
  18 + oldPackage: 'Composes', //之前的包名
  19 + newPackage: 'Informations', //新的包名
  20 + oldCategory: 'Mores', //之前的目录
  21 + newCategory: 'Mores', //新的目录
  22 + oldCategoryName: '更多', //之前的目录名
  23 + newCategoryName: '更多' //新的目录名
  24 + },
  25 + {
  26 + key: 'ThreeDimensional', //三维
  27 + oldPackage: 'Composes', //之前的包名
  28 + newPackage: 'Decorates', //新的包名
  29 + oldCategory: 'Mores', //之前的目录
  30 + newCategory: 'Three', //新的目录
  31 + oldCategoryName: '更多', //之前的目录名
  32 + newCategoryName: '三维' //新的目录名
  33 + },
  34 + {
  35 + key: 'Button', //自定义按钮
  36 + oldPackage: 'Informations', //之前的包名
  37 + newPackage: 'Informations', //现在的包名
  38 + oldCategory: 'Mores', //之前的目录
  39 + newCategory: 'Inputs', //新的目录
  40 + oldCategoryName: '更多', //之前的目录名
  41 + newCategoryName: '控件' //新的目录名
  42 + },
  43 + {
  44 + key: 'OverrideInputsDate', //自定义时间选择器
  45 + oldPackage: 'Informations', //之前的包名
  46 + newPackage: 'Informations', //现在的包名
  47 + oldCategory: 'Mores', //之前的目录
  48 + newCategory: 'Inputs', //新的目录
  49 + oldCategoryName: '更多', //之前的目录名
  50 + newCategoryName: '控件' //新的目录名
  51 + },
  52 + {
  53 + key: 'OverrideInputsTab', //自定义标签选择器
  54 + oldPackage: 'Informations', //之前的包名
  55 + newPackage: 'Informations', //现在的包名
  56 + oldCategory: 'Mores', //之前的目录
  57 + newCategory: 'Inputs', //新的目录
  58 + oldCategoryName: '更多', //之前的目录名
  59 + newCategoryName: '控件' //新的目录名
  60 + },
  61 + {
  62 + key: 'OverrideSelect', //自定义下拉选择器
  63 + oldPackage: 'Informations', //之前的包名
  64 + newPackage: 'Informations', //现在的包名
  65 + oldCategory: 'Mores', //之前的目录
  66 + newCategory: 'Inputs', //新的目录
  67 + oldCategoryName: '更多', //之前的目录名
  68 + newCategoryName: '控件' //新的目录名
  69 + },
  70 + {
  71 + key: 'OverrideILoadConfigurationframe', //加载组态
  72 + oldPackage: 'Informations', //之前的包名
  73 + newPackage: 'Informations', //现在的包名
  74 + oldCategory: 'Mores', //之前的目录
  75 + newCategory: 'Mores', //新的目录
  76 + oldCategoryName: '更多', //之前的目录名
  77 + newCategoryName: '更多' //新的目录名
  78 + },
  79 + {
  80 + key: 'OverrideTextCommon', //自定义文字
  81 + oldPackage: 'Informations', //之前的包名
  82 + newPackage: 'Informations', //现在的包名
  83 + oldCategory: 'Mores', //之前的目录
  84 + newCategory: 'Texts', //新的目录
  85 + oldCategoryName: '更多', //之前的目录名
  86 + newCategoryName: '文本' //新的目录名
  87 + },
  88 + {
  89 + key: 'OverrideTextGradient', //自定义渐变文字
  90 + oldPackage: 'Informations', //之前的包名
  91 + newPackage: 'Informations', //现在的包名
  92 + oldCategory: 'Mores', //之前的目录
  93 + newCategory: 'Texts', //新的目录
  94 + oldCategoryName: '更多', //之前的目录名
  95 + newCategoryName: '文本' //新的目录名
  96 + },
  97 + {
  98 + key: 'OverrideTextBarrage', //自定义弹幕文字
  99 + oldPackage: 'Informations', //之前的包名
  100 + newPackage: 'Informations', //现在的包名
  101 + oldCategory: 'Mores', //之前的目录
  102 + newCategory: 'Texts', //新的目录
  103 + oldCategoryName: '更多', //之前的目录名
  104 + newCategoryName: '文本' //新的目录名
  105 + },
  106 + {
  107 + key: 'LeftCenterRightHead', //大标题1
  108 + newKey: 'Headline1', //新的key
  109 + oldPackage: 'Composes', //之前的包名
  110 + newPackage: 'Decorates', //现在的包名
  111 + oldCategory: 'HeadCombinations', //之前的目录
  112 + newCategory: 'Headline', //新的目录
  113 + oldCategoryName: '更多', //之前的目录名
  114 + newCategoryName: '大标题' //新的目录名
  115 + },
  116 + {
  117 + key: 'LeftCenterRightHeadAnimat', //大标题2
  118 + newKey: 'Headline2', //新的key
  119 + oldPackage: 'Composes', //之前的包名
  120 + newPackage: 'Decorates', //现在的包名
  121 + oldCategory: 'HeadCombinations', //之前的目录
  122 + newCategory: 'Headline', //新的目录
  123 + oldCategoryName: '更多', //之前的目录名
  124 + newCategoryName: '大标题' //新的目录名
  125 + },
  126 + {
  127 + key: 'Title1', //小标题1
  128 + newKey: 'Subtitle1', //新的key
  129 + oldPackage: 'Composes', //之前的包名
  130 + newPackage: 'Decorates', //现在的包名
  131 + oldCategory: 'Mores', //之前的目录
  132 + newCategory: 'Subtitle', //新的目录
  133 + oldCategoryName: '更多', //之前的目录名
  134 + newCategoryName: '小标题' //新的目录名
  135 + },
  136 + {
  137 + key: 'Title2', //小标题2
  138 + newKey: 'Subtitle2', //新的key
  139 + oldPackage: 'Composes', //之前的包名
  140 + newPackage: 'Decorates', //现在的包名
  141 + oldCategory: 'Mores', //之前的目录
  142 + newCategory: 'Subtitle', //新的目录
  143 + oldCategoryName: '更多', //之前的目录名
  144 + newCategoryName: '小标题' //新的目录名
  145 + },
  146 + {
  147 + key: 'Title3', //小标题3
  148 + newKey: 'Subtitle3', //新的key
  149 + oldPackage: 'Composes', //之前的包名
  150 + newPackage: 'Decorates', //现在的包名
  151 + oldCategory: 'Mores', //之前的目录
  152 + newCategory: 'Subtitle', //新的目录
  153 + oldCategoryName: '更多', //之前的目录名
  154 + newCategoryName: '小标题' //新的目录名
  155 + }
  156 +]
  157 +//
1 1
2 import { ConfigType } from "../index.d" 2 import { ConfigType } from "../index.d"
  3 +import { compatibleConfig } from "./compatibleConfig"
3 import { matchExternalPrefixReg } from "./useWidgetKey" 4 import { matchExternalPrefixReg } from "./useWidgetKey"
4 5
5 const getAllConfigFile = async () => { 6 const getAllConfigFile = async () => {
@@ -12,7 +13,8 @@ const getChartConfigFile = async (path: string) => { @@ -12,7 +13,8 @@ const getChartConfigFile = async (path: string) => {
12 } 13 }
13 14
14 export const createComponent = async (configType: ConfigType) => { 15 export const createComponent = async (configType: ConfigType) => {
15 - const { key, chartKey, category, package: packageName, redirectComponent } = configType 16 + // eslint-disable-next-line prefer-const
  17 + let { key, chartKey, category, package: packageName, redirectComponent, categoryName } = configType
16 // redirectComponent 是给图片组件库和图标组件库使用的 18 // redirectComponent 是给图片组件库和图标组件库使用的
17 if (redirectComponent) { 19 if (redirectComponent) {
18 const [packageName, categoryName, keyName] = redirectComponent.split('/') 20 const [packageName, categoryName, keyName] = redirectComponent.split('/')
@@ -20,7 +22,19 @@ export const createComponent = async (configType: ConfigType) => { @@ -20,7 +22,19 @@ export const createComponent = async (configType: ConfigType) => {
20 const redirectChart = await getChartConfigFile(filePath) 22 const redirectChart = await getChartConfigFile(filePath)
21 return new redirectChart.default() 23 return new redirectChart.default()
22 } 24 }
23 - 25 + /**
  26 + * 兼容之前导入错误的补丁
  27 + */
  28 + compatibleConfig?.forEach(item => {
  29 + if (item?.key === key) {
  30 + key = item?.key as string
  31 + packageName = item?.newPackage as string
  32 + category = item?.newCategory as string
  33 + // eslint-disable-next-line @typescript-eslint/no-unused-vars
  34 + categoryName = item?.newCategoryName as string
  35 + }
  36 + })
  37 + //
24 const hasExternalPrefix = matchExternalPrefixReg.test(chartKey) 38 const hasExternalPrefix = matchExternalPrefixReg.test(chartKey)
25 const filePath = `../components${hasExternalPrefix ? '/external' : ''}/${packageName}/${category}/${key}/config.ts` 39 const filePath = `../components${hasExternalPrefix ? '/external' : ''}/${packageName}/${category}/${key}/config.ts`
26 const chart = await getChartConfigFile(filePath) 40 const chart = await getChartConfigFile(filePath)