Skip to content

Commit

Permalink
feat: Remove property component_name
Browse files Browse the repository at this point in the history
  • Loading branch information
fwh1990 committed Apr 14, 2020
1 parent 6b22e4d commit ecaca3f
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 55 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ npx iconfont-init
"platforms": "*",
"use_rpx": true,
"trim_icon_prefix": "icon",
"default_icon_size": 18,
"componnent_name": "IconFont"
"default_icon_size": 18
}
```
### 配置参数说明:
Expand Down Expand Up @@ -88,10 +87,6 @@ npx iconfont-init
### default_icon_size
我们将为每个生成的图标组件加入默认的字体大小,当然,你也可以通过传入props的方式改变这个size值。

### component_name
就是组件的名称,默认名称为`IconFont`,您也可以改成`Icons`或者您喜欢的名字。记住,它是一个变量名,您必须遵守Javascript中关于变量的语法规则。以及作为组件名,请尽量以大写字母开头。


# Step 3
开始生成RemaxJs标准组件
```bash
Expand Down
3 changes: 1 addition & 2 deletions scripts/config/iconfont-js.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"use_rpx": true,
"save_dir": "./snapshots/iconfont-js",
"trim_icon_prefix": "icon",
"default_icon_size": 14,
"component_name": "JsIcon"
"default_icon_size": 14
}
3 changes: 1 addition & 2 deletions scripts/config/iconfont-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"use_rpx": false,
"save_dir": "./snapshots/iconfont-ts",
"trim_icon_prefix": "icon",
"default_icon_size": 20,
"component_name": "TsxIcon"
"default_icon_size": 20
}
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.alipay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import React from 'react';
import Iconfont_alipay from './alipay/alipay';

export const JsIcon = (props) => {
export const IconFont = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
return <Iconfont_alipay name={name} size={size} color={color} />;
};

JsIcon.defaultProps = {
IconFont.defaultProps = {
size: 14,
};

export default JsIcon;
export default IconFont;
4 changes: 2 additions & 2 deletions snapshots/iconfont-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface Props {
color?: string | string[];
}

export declare const JsIcon: FunctionComponent<Props>;
export declare const IconFont: FunctionComponent<Props>;

export default JsIcon;
export default IconFont;
4 changes: 2 additions & 2 deletions snapshots/iconfont-js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const JsIcon = () => {
export const IconFont = () => {
return null;
};

export default JsIcon;
export default IconFont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.toutiao.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import React from 'react';
import Iconfont_toutiao from './toutiao/toutiao';

export const JsIcon = (props) => {
export const IconFont = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
return <Iconfont_toutiao name={name} size={size} color={color} />;
};

JsIcon.defaultProps = {
IconFont.defaultProps = {
size: 14,
};

export default JsIcon;
export default IconFont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.wechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import React from 'react';
import Iconfont_wechat from './wechat/wechat';

export const JsIcon = (props) => {
export const IconFont = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
return <Iconfont_wechat name={name} size={size} color={color} />;
};

JsIcon.defaultProps = {
IconFont.defaultProps = {
size: 14,
};

export default JsIcon;
export default IconFont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.alipay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ interface Props {
color?: string | string[];
}

export const TsxIcon: FunctionComponent<Props> = (props) => {
export const IconFont: FunctionComponent<Props> = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
// @ts-ignore
return <Iconfont_alipay name={name} size={size} color={color} />;
};

TsxIcon.defaultProps = {
IconFont.defaultProps = {
size: 20,
};

export default TsxIcon;
export default IconFont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.toutiao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ interface Props {
color?: string | string[];
}

export const TsxIcon: FunctionComponent<Props> = (props) => {
export const IconFont: FunctionComponent<Props> = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
// @ts-ignore
return <Iconfont_toutiao name={name} size={size} color={color} />;
};

TsxIcon.defaultProps = {
IconFont.defaultProps = {
size: 20,
};

export default TsxIcon;
export default IconFont;
4 changes: 2 additions & 2 deletions snapshots/iconfont-ts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface Props {
color?: string | string[];
}

export const TsxIcon: FunctionComponent<Props> = () => {
export const IconFont: FunctionComponent<Props> = () => {
return null;
};

export default TsxIcon;
export default IconFont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.wechat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ interface Props {
color?: string | string[];
}

export const TsxIcon: FunctionComponent<Props> = (props) => {
export const IconFont: FunctionComponent<Props> = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
// @ts-ignore
return <Iconfont_wechat name={name} size={size} color={color} />;
};

TsxIcon.defaultProps = {
IconFont.defaultProps = {
size: 20,
};

export default TsxIcon;
export default IconFont;
5 changes: 1 addition & 4 deletions src/libs/generateUsingComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import { Config } from './getConfig';
import { getTemplate } from './getTemplate';
import { replaceIsRpx, replaceNames, replacePlatform, replaceSize, replaceSummaryIcon } from './replace';
import { replaceIsRpx, replaceNames, replacePlatform, replaceSize } from './replace';

export const generateUsingComponent = (config: Config, names: string[], platform?: string) => {
const saveDir = path.resolve(config.save_dir);
Expand All @@ -23,7 +23,6 @@ export const generateUsingComponent = (config: Config, names: string[], platform
iconFile = replaceNames(iconFile, names);
iconFile = replaceSize(iconFile, config.default_icon_size);
iconFile = replaceIsRpx(iconFile, config.use_rpx);
iconFile = replaceSummaryIcon(iconFile, config.component_name);

if (platform) {
iconFile = replacePlatform(iconFile, platform);
Expand All @@ -33,8 +32,6 @@ export const generateUsingComponent = (config: Config, names: string[], platform
let definitionFile = getTemplate('index.d.ts');

definitionFile = replaceNames(definitionFile, names);
definitionFile = replaceSummaryIcon(definitionFile, config.component_name);

fs.writeFileSync(path.join(saveDir, 'index.d.ts'), definitionFile);
}

Expand Down
2 changes: 0 additions & 2 deletions src/libs/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface Config {
use_rpx: boolean;
trim_icon_prefix: string;
default_icon_size: number;
component_name: string;
}

let cacheConfig: Config;
Expand Down Expand Up @@ -60,7 +59,6 @@ export const getConfig = () => {

config.save_dir = config.save_dir || defaultConfig.save_dir;
config.default_icon_size = config.default_icon_size || defaultConfig.default_icon_size;
config.component_name = config.component_name || defaultConfig.component_name;

cacheConfig = config;

Expand Down
3 changes: 1 addition & 2 deletions src/libs/iconfont.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"platforms": "*",
"use_rpx": true,
"trim_icon_prefix": "icon",
"default_icon_size": 18,
"component_name": "IconFont"
"default_icon_size": 18
}
2 changes: 1 addition & 1 deletion src/libs/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export const replaceIsRpx = (content: string, useRpx: boolean) => {
};

export const replaceSummaryIcon = (content: string, iconName: string) => {
return content.replace(/#SummaryIcon#/g, iconName);
return content.replace(/IconFont/g, iconName);
};
4 changes: 2 additions & 2 deletions src/templates/index.d.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface Props {
color?: string | string[];
}

export declare const #SummaryIcon#: FunctionComponent<Props>;
export declare const IconFont: FunctionComponent<Props>;

export default #SummaryIcon#;
export default IconFont;
4 changes: 2 additions & 2 deletions src/templates/index.js.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const #SummaryIcon# = () => {
export const IconFont = () => {
return null;
};

export default #SummaryIcon#;
export default IconFont;
6 changes: 3 additions & 3 deletions src/templates/index.platform.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import React from 'react';
import Iconfont_#platform# from './#platform#/#platform#';

export const #SummaryIcon# = (props) => {
export const IconFont = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
return <Iconfont_#platform# name={name} size={size} color={color} />;
};

#SummaryIcon#.defaultProps = {
IconFont.defaultProps = {
size: #size#,
};

export default #SummaryIcon#;
export default IconFont;
6 changes: 3 additions & 3 deletions src/templates/index.platform.tsx.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ interface Props {
color?: string | string[];
}

export const #SummaryIcon#: FunctionComponent<Props> = (props) => {
export const IconFont: FunctionComponent<Props> = (props) => {
const { name, size, color } = props;

// FIXME: RemaxJs doesn't support pxTransform()
// @ts-ignore
return <Iconfont_#platform# name={name} size={size} color={color} />;
};

#SummaryIcon#.defaultProps = {
IconFont.defaultProps = {
size: #size#,
};

export default #SummaryIcon#;
export default IconFont;
4 changes: 2 additions & 2 deletions src/templates/index.tsx.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface Props {
color?: string | string[];
}

export const #SummaryIcon#: FunctionComponent<Props> = () => {
export const IconFont: FunctionComponent<Props> = () => {
return null;
};

export default #SummaryIcon#;
export default IconFont;

0 comments on commit ecaca3f

Please sign in to comment.