Skip to content

Commit 114b557

Browse files
author
xiazhigang
committed
更新 增加 prefix icon 组件前缀
1 parent 6c15a7c commit 114b557

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

.codegen/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"iconRoot": "./example/icons/source",
33
"iconTarget": "./example/icons",
44
"templateFile": "./.codegen/templates/icon.handlebars",
5+
"prefix": "Icon",
56
"svgr": {
67
"platform": ["rn", "h5"]
78
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yocdev/tarocodegen",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"author": "[email protected]",
55
"license": "MIT",
66
"bin": {

src/helper/readConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const configSchema = {
99
iconRoot: { type: "string" },
1010
iconTarget: { type: "string" },
1111
templateFile: { type: "string" },
12+
prefix: {type: 'string'},
1213
svgr: {
1314
type: "object",
1415
properties: {

src/icons/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ export default function generateIcons() {
5555
rd.eachSync(routesPath, async (fileDir, stats) => {
5656
const extname = path.extname(fileDir);
5757
const isValidPicture =
58-
stats.isFile() && /svg|png|jpeg/.test(path.extname(fileDir)) && !/@[23]x/.test(fileDir);
58+
stats.isFile() &&
59+
/svg|png|jpeg/.test(path.extname(fileDir)) &&
60+
!/@[23]x/.test(fileDir);
5961
// console.log(fileDir);
6062
if (isValidPicture) {
6163
const name = path.basename(fileDir, path.extname(fileDir));
6264
const iconFileName = path.basename(fileDir);
6365
// 转换为双驼峰写法
6466
const iconName = _.upperFirst(_.camelCase(name));
65-
const iconComponentName = `Icon${iconName}`;
67+
const iconComponentName = config.prefix
68+
? `${config.prefix}${iconName}`
69+
: iconName;
6670
let finalTemplate = template;
6771
if (templates.length > 0) {
6872
templates.some((item) => {

0 commit comments

Comments
 (0)