Skip to content

Commit c2c54d4

Browse files
authored
fix(icons): add rewrite icons export ,rename subscript to sub-script (#3857)
1 parent a61abc3 commit c2c54d4

File tree

9 files changed

+36
-43
lines changed

9 files changed

+36
-43
lines changed

internals/automate/src/build-svg-to-js/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
export const svgsPath = '../../packages/theme/src/svgs'
33
export const iconsPath = '../../packages/vue-icon'
44

5-
export const rewriteConfig = {}
5+
export const rewriteConfig = {
6+
'subscript': 'sub-script'
7+
}

internals/automate/src/build-svg-to-js/index.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import * as configSaas from './config-saas'
3838
interface FileInfo {
3939
svgName: string
4040
hasFill: boolean
41-
rewriteName: string // hasFill:true时, 不应该有rewriteName
4241
}
4342
const camelize = (str) => str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : ''))
4443
const isSaas = process.argv.includes('--icon-saas')
@@ -64,10 +63,10 @@ svgsFiles.forEach((filename) => {
6463

6564
if (filename.endsWith('-filled.svg')) {
6665
svgName = filename.replace('-filled.svg', '')
67-
item = { svgName, hasFill: true, rewriteName: rewriteConfig[svgName] }
66+
item = { svgName, hasFill: true }
6867
} else if (filename.endsWith('.svg')) {
6968
svgName = filename.replace('.svg', '')
70-
item = { svgName, hasFill: false, rewriteName: rewriteConfig[svgName] }
69+
item = { svgName, hasFill: false }
7170
} else {
7271
return
7372
}
@@ -80,23 +79,23 @@ svgsFiles.forEach((filename) => {
8079
})
8180

8281
// 2、生成组件的js
83-
const rewriteList: { capName: string; svgName: string; rewriteName: string }[] = []
8482
const fillList: { capName: string; svgName: string }[] = []
8583
const uncheckedList: { capName: string; svgName: string }[] = []
84+
const rewriteList = Object.keys(rewriteConfig).map((wrongName) => {
85+
return {
86+
capName: camelize('-' + wrongName),
87+
svgName: wrongName,
88+
rewriteName: camelize('-' + rewriteConfig[wrongName])
89+
}
90+
})
8691

8792
Object.values(svgsMap).forEach((item) => {
8893
const capName = camelize('-' + item.svgName)
8994

90-
// 重命名的图标
91-
if (item.rewriteName) {
92-
rewriteList.push({ capName, svgName: item.svgName, rewriteName: camelize('-' + item.rewriteName) })
93-
return
94-
}
9595
// 支持线&面的图标
9696
if (item.hasFill) {
9797
fillList.push({ capName, svgName: item.svgName })
98-
const tmplStr = `
99-
import { svg } from '@opentiny/vue-common'
98+
const tmplStr = `import { svg } from '@opentiny/vue-common'
10099
import ${capName} from '${themePackage}/svgs/${item.svgName}.svg'
101100
import ${capName}Filled from '${themePackage}/svgs/${item.svgName + '-filled'}.svg'
102101
@@ -108,8 +107,7 @@ export default () => svg({ name: 'Icon${capName}', component: ${capName}, filled
108107
}
109108
// 未梳理到的图标
110109
uncheckedList.push({ capName, svgName: item.svgName })
111-
const tmplStr = `
112-
import { svg } from '@opentiny/vue-common'
110+
const tmplStr = `import { svg } from '@opentiny/vue-common'
113111
import ${capName} from '${themePackage}/svgs/${item.svgName}.svg'
114112
115113
export default () => svg({ name: 'Icon${capName}', component: ${capName}, filledComponent: ${capName} })()
@@ -160,20 +158,6 @@ fs.writeFileSync(`${iconsPath}/index.ts`, tmplStr, 'utf-8')
160158

161159
// 4、打印日志
162160

163-
// 即是 hasFill, 但配置了 rewriteName, 请从config.ts中移除相应的rewrite。
164-
// 因为要求设计师那边已经去重过了,
165-
const err1 = Object.values(svgsMap)
166-
.filter((item) => item.hasFill && item.rewriteName)
167-
.map((item) => item.svgName)
168-
169-
if (err1.length) {
170-
console.error(`
171-
********即是 hasFill, 但配置了 rewriteName, 请从config.ts中移除相应的rewrite**********
172-
${err1.join(',')}
173-
************************************************************************************
174-
`)
175-
}
176-
177161
// 非 hasFill, 且未配置 rewriteName, 大概是未梳理到的历史图标,tiny图标
178162
const err2 = uncheckedList.map((item) => item.svgName)
179163
if (err2.length) {

packages/vue-icon-saas/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,14 @@ export { IconWord, IconWord as iconWord }
11641164
export { IconZip, IconZip as iconZip }
11651165

11661166
// 重命名导出
1167+
export const IconTotalNolume = () => ({
1168+
...IconTotalVolume(),
1169+
name: 'IconTotalNolume',
1170+
deprecatedBy: 'IconTotalVolume'
1171+
})
1172+
export const iconTotalNolume = IconTotalNolume
1173+
export const IconSubscript = () => ({ ...IconSubScript(), name: 'IconSubscript', deprecatedBy: 'IconSubScript' })
1174+
export const iconSubscript = IconSubscript
11671175

11681176
export default {
11691177
IconAcceptance,
@@ -1745,5 +1753,7 @@ export default {
17451753
IconWarning,
17461754
IconWeaknet,
17471755
IconWord,
1748-
IconZip
1756+
IconZip,
1757+
IconTotalNolume,
1758+
IconSubscript
17491759
}

packages/vue-icon-saas/src/sub-script.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ import { svg } from '@opentiny/vue-common'
22
import SubScript from '@opentiny/vue-theme-saas/svgs/sub-script.svg'
33
import SubScriptFilled from '@opentiny/vue-theme-saas/svgs/sub-script-filled.svg'
44

5-
// TODO: 文件名和组件名已统一改为 subscript,此文件应该删除
65
export default () => svg({ name: 'IconSubScript', component: SubScript, filledComponent: SubScriptFilled })()

packages/vue-icon-saas/src/subscript.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/vue-icon/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ import IconStreamSolid from './src/stream-solid'
460460
import IconStretchCrosswise from './src/stretch-crosswise'
461461
import IconStretchUpright from './src/stretch-upright'
462462
import IconStretch from './src/stretch'
463-
import IconSubscript from './src/subscript'
463+
import IconSubScript from './src/sub-script'
464464
import IconSubstituteMaterial from './src/substitute-material'
465465
import IconSuccess from './src/success'
466466
import IconSuccessful from './src/successful'
@@ -999,7 +999,7 @@ export { IconStreamSolid, IconStreamSolid as iconStreamSolid }
999999
export { IconStretchCrosswise, IconStretchCrosswise as iconStretchCrosswise }
10001000
export { IconStretchUpright, IconStretchUpright as iconStretchUpright }
10011001
export { IconStretch, IconStretch as iconStretch }
1002-
export { IconSubscript, IconSubscript as iconSubscript }
1002+
export { IconSubScript, IconSubScript as iconSubScript }
10031003
export { IconSubstituteMaterial, IconSubstituteMaterial as iconSubstituteMaterial }
10041004
export { IconSuccess, IconSuccess as iconSuccess }
10051005
export { IconSuccessful, IconSuccessful as iconSuccessful }
@@ -1074,6 +1074,8 @@ export { IconZoomIn, IconZoomIn as iconZoomIn }
10741074
export { IconZoomOut, IconZoomOut as iconZoomOut }
10751075

10761076
// 重命名导出
1077+
export const IconSubscript = () => ({ ...IconSubScript(), name: 'IconSubscript', deprecatedBy: 'IconSubScript' })
1078+
export const iconSubscript = IconSubscript
10771079

10781080
export default {
10791081
IconEditorEraser,
@@ -1538,7 +1540,7 @@ export default {
15381540
IconStretchCrosswise,
15391541
IconStretchUpright,
15401542
IconStretch,
1541-
IconSubscript,
1543+
IconSubScript,
15421544
IconSubstituteMaterial,
15431545
IconSuccess,
15441546
IconSuccessful,
@@ -1610,5 +1612,6 @@ export default {
16101612
IconYes,
16111613
IconZipType,
16121614
IconZoomIn,
1613-
IconZoomOut
1615+
IconZoomOut,
1616+
IconSubscript
16141617
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { svg } from '@opentiny/vue-common'
2+
import SubScript from '@opentiny/vue-theme/svgs/sub-script.svg'
3+
4+
export default () => svg({ name: 'IconSubScript', component: SubScript, filledComponent: SubScript })()

packages/vue-icon/src/subscript.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)