@sj-distributor/react-iconfont-cli 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 原罪
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,165 @@
1
+ ## react-iconfont-cli
2
+ 用纯JS把iconfont.cn的图标转换成React组件,不依赖字体,支持多色彩
3
+
4
+ ![](https://github.com/fwh1990/react-iconfont-cli/blob/master/images/icons.png?raw=true)
5
+
6
+ ## 特性
7
+
8
+ 1、纯组件,不依赖字体,体积小
9
+ <br />
10
+ 2、支持渲染多色彩图标,支持自定义颜色
11
+ <br />
12
+ 3、自动化生成图标组件,支持es6和typescript两种文件格式
13
+
14
+ ## Step 1
15
+ 安装插件
16
+ ```bash
17
+ # Yarn
18
+ yarn add react-iconfont-cli --dev
19
+
20
+ # Npm
21
+ npm install react-iconfont-cli --save-dev
22
+ ```
23
+
24
+ # Step 2
25
+ 生成配置文件
26
+ ```bash
27
+ npx iconfont-init
28
+ ```
29
+ 此时项目根目录会生成一个`iconfont.json`的文件,内容如下:
30
+ ```json
31
+ {
32
+ "symbol_url": "请参考README.md,复制官网提供的JS链接",
33
+ "use_typescript": false,
34
+ "save_dir": "./src/components/iconfont",
35
+ "trim_icon_prefix": "icon",
36
+ "unit": "px",
37
+ "default_icon_size": 18
38
+ }
39
+ ```
40
+ ### 配置参数说明:
41
+ ### symbol_url
42
+ 请直接复制[iconfont](http://iconfont.cn)官网提供的项目链接。请务必看清是`.js`后缀而不是.css后缀。如果你现在还没有创建iconfont的仓库,那么可以填入这个链接去测试:`http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js`
43
+
44
+ <br />
45
+
46
+ ![](https://github.com/fwh1990/react-iconfont-cli/blob/master/images/symbol-url.png?raw=true)
47
+
48
+ ### use_typescript
49
+ 如果您的项目使用Typescript编写,请设置为true。这个选项将决定生成的图标组件是`.tsx`还是`.js`后缀。
50
+
51
+ 当该值为false时,我们会为您的图标生成`.js`和`.d.ts`两个文件,以便您能享受到最好的开发体验。
52
+
53
+ ### save_dir
54
+ 根据iconfont图标生成的组件存放的位置。每次生成组件之前,该文件夹都会被清空。
55
+
56
+ ### trim_icon_prefix
57
+ 如果你的图标有通用的前缀,而你在使用的时候又不想重复去写,那么可以通过这种配置这个选项把前缀统一去掉。
58
+
59
+ 注意,这个选项只针对 `<Icon />` 组件有效
60
+
61
+ ### unit
62
+ 图标的单位,默认是网页常用单位`px`即像素,也推荐您在手机网页中使用自适应的`rem`单位。
63
+
64
+ ### default_icon_size
65
+ 我们将为每个生成的图标组件加入默认的字体大小,当然,你也可以通过传入props的方式改变这个size值。
66
+
67
+ # Step 3
68
+ 开始生成React标准组件
69
+ ```bash
70
+ npx iconfont-h5
71
+ ```
72
+
73
+ 生成后查看您设置的保存目录中是否含有所有的图标,你可以参考[snapshots目录](https://github.com/iconfont-cli/react-iconfont-cli/tree/master/snapshots)的快照文件,以区分不同模式下的图标结构。
74
+
75
+ # 使用
76
+
77
+ 现在我们提供了两种引入方式供您选择:
78
+
79
+ 1、使用汇总`Icon`组件:
80
+ ```typescript jsx
81
+ import React from 'react';
82
+ import IconFont from '../src/iconfont';
83
+
84
+ export const App = () => {
85
+ return (
86
+ <div>
87
+ <IconFont name="alipay" size={20} />
88
+ <IconFont name="wechat" />
89
+ </div>
90
+ );
91
+ };
92
+ ```
93
+
94
+ 2、使用单个图标。这样可以避免没用到的图标也打包进App:
95
+
96
+ ```typescript jsx
97
+ import React from 'react';
98
+ import IconAlipay from '../src/iconfont/IconAlipay';
99
+ import IconWechat from '../src/iconfont/IconWechat';
100
+
101
+ export const App = () => {
102
+ return (
103
+ <div>
104
+ <IconAlipay size={20} />
105
+ <IconWechat />
106
+ </div>
107
+ );
108
+ };
109
+ ```
110
+
111
+ ### 图标尺寸
112
+ 根据配置`default_icon_size`,每个图标都会有一个默认的尺寸,你可以随时覆盖。
113
+ ```typescript jsx
114
+ <IconFont name="alipay" size={20} />
115
+ ```
116
+ ![](https://github.com/fwh1990/react-iconfont-cli/blob/master/images/default-color-icon.png?raw=true)
117
+ ### 图标单色
118
+ 单色图标,如果不指定颜色值,图标将渲染原本的颜色。如果你想设置为其他的颜色,那么设置一个你想要的颜色即可。
119
+
120
+ **注意:如果你在props传入的color是字符串而不是数组,那么即使原本是多色彩的图标,也会变成单色图标。**
121
+
122
+ ```typescript jsx
123
+ <IconFont name="alipay" color="green" />
124
+ ```
125
+ ![](https://github.com/fwh1990/react-iconfont-cli/blob/master/images/one-color-icon.png?raw=true)
126
+
127
+ ### 图标多色彩
128
+ 多色彩的图标,如果不指定颜色值,图标将渲染原本的多色彩。如果你想设置为其他的颜色,那么设置一组你想要的颜色即可
129
+ ```typescript jsx
130
+ <IconFont name="alipay" color={['green', 'orange']} />
131
+ ```
132
+ 颜色组的数量以及排序,需要根据当前图标的信息来确定。您需要进入图标组件中查看并得出结论。
133
+
134
+
135
+ ![](https://github.com/fwh1990/react-iconfont-cli/blob/master/images/multi-color-icon.png?raw=true)
136
+
137
+ ### 与文字并排
138
+ 图标是块状的容器,如果您想与文字并排混合,请使用`flex`布局以保证文字和图标能对齐
139
+ ```jsx harmony
140
+ <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
141
+ <span>Hello</span>
142
+ <IconFont name="alipay" />
143
+ </div>
144
+ ```
145
+
146
+ # 更新图标
147
+ 当您在iconfont.cn中的图标有变更时,只需更改配置`symbol_url`,然后再次执行`Step 3`即可生成最新的图标组件
148
+ ```bash
149
+ # 修改 symbol_url 配置后执行:
150
+ npx iconfont-h5
151
+ ```
152
+
153
+ # 扩展
154
+ |平台|库|
155
+ |----|---|
156
+ |小程序|[mini-program-iconfont-cli](https://github.com/iconfont-cli/mini-program-iconfont-cli)|
157
+ |Taro|[taro-iconfont-cli](https://github.com/iconfont-cli/taro-iconfont-cli)|
158
+ |React Native|[react-native-iconfont-cli](https://github.com/iconfont-cli/react-native-iconfont-cli)|
159
+ |Flutter|[flutter-iconfont-cli](https://github.com/iconfont-cli/flutter-iconfont-cli)
160
+ |Remax|[remax-iconfont-cli](https://github.com/iconfont-cli/remax-iconfont-cli)
161
+
162
+
163
+ --------
164
+
165
+ 欢迎使用,并给我一些反馈和建议,让这个库做的更好
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ var tslib_1 = require("tslib");
5
+ var colors_1 = tslib_1.__importDefault(require("colors"));
6
+ var getConfig_1 = require("../libs/getConfig");
7
+ var iconfont_parser_1 = require("iconfont-parser");
8
+ var generateComponent_1 = require("../libs/generateComponent");
9
+ var config = getConfig_1.getConfig();
10
+ iconfont_parser_1.fetchXml(config.symbol_url).then(function (result) {
11
+ generateComponent_1.generateComponent(result, config);
12
+ }).catch(function (e) {
13
+ console.error(colors_1.default.red(e.message || 'Unknown Error'));
14
+ process.exit(1);
15
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ var tslib_1 = require("tslib");
5
+ var path_1 = tslib_1.__importDefault(require("path"));
6
+ var fs_1 = tslib_1.__importDefault(require("fs"));
7
+ var fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
8
+ var colors_1 = tslib_1.__importDefault(require("colors"));
9
+ var targetFile = path_1.default.resolve('iconfont.json');
10
+ if (fs_1.default.existsSync(targetFile)) {
11
+ console.error(colors_1.default.red('File "iconfont.json" was created before.'));
12
+ }
13
+ else {
14
+ // fs.copyFileSync only can be used above node v8.5.0+
15
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '../libs/iconfont.json'), targetFile);
16
+ console.log(colors_1.default.green('File "iconfont.json" is created now. We recommend you add it to version control.'));
17
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ var tslib_1 = require("tslib");
5
+ var colors_1 = tslib_1.__importDefault(require("colors"));
6
+ console.log([
7
+ '',
8
+ 'Usage:',
9
+ '',
10
+ ' ' + colors_1.default.yellow('npx iconfont-init') + ' : generate config file',
11
+ ' ' + colors_1.default.yellow('npx iconfont-h5') + ' : generate icon components',
12
+ '',
13
+ ].join('\n'));
@@ -0,0 +1 @@
1
+ export declare const copyTemplate: (fromFile: string, toFile: string) => void;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var fs_1 = tslib_1.__importDefault(require("fs"));
5
+ var path_1 = tslib_1.__importDefault(require("path"));
6
+ exports.copyTemplate = function (fromFile, toFile) {
7
+ return fs_1.default.copyFileSync(path_1.default.join(__dirname, "../templates/" + fromFile + ".template"), toFile);
8
+ };
@@ -0,0 +1,3 @@
1
+ import { XmlData } from "iconfont-parser";
2
+ import { Config } from "./getConfig";
3
+ export declare const generateComponent: (data: XmlData, config: Config) => void;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var fs_1 = tslib_1.__importDefault(require("fs"));
5
+ var path_1 = tslib_1.__importDefault(require("path"));
6
+ var mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
7
+ var glob_1 = tslib_1.__importDefault(require("glob"));
8
+ var colors_1 = tslib_1.__importDefault(require("colors"));
9
+ var lodash_1 = require("lodash");
10
+ var getTemplate_1 = require("./getTemplate");
11
+ var replace_1 = require("./replace");
12
+ var whitespace_1 = require("./whitespace");
13
+ var copyTemplate_1 = require("./copyTemplate");
14
+ var ATTRIBUTE_FILL_MAP = ["path"];
15
+ exports.generateComponent = function (data, config) {
16
+ var names = [];
17
+ var imports = [];
18
+ var saveDir = path_1.default.resolve(config.save_dir);
19
+ var jsxExtension = config.use_typescript ? ".tsx" : ".js";
20
+ var jsExtension = config.use_typescript ? ".ts" : ".js";
21
+ var cases = "";
22
+ mkdirp_1.default.sync(saveDir);
23
+ glob_1.default.sync(path_1.default.join(saveDir, "*")).forEach(function (file) { return fs_1.default.unlinkSync(file); });
24
+ copyTemplate_1.copyTemplate("helper" + jsExtension, path_1.default.join(saveDir, "helper" + jsExtension));
25
+ if (!config.use_typescript) {
26
+ copyTemplate_1.copyTemplate("helper.d.ts", path_1.default.join(saveDir, "helper.d.ts"));
27
+ }
28
+ data.svg.symbol.forEach(function (item) {
29
+ var singleFile;
30
+ var iconId = item.$.id;
31
+ var iconIdAfterTrim = config.trim_icon_prefix
32
+ ? iconId.replace(new RegExp("^" + config.trim_icon_prefix + "(.+?)$"), function (_, value) { return value.replace(/^[-_.=+#@!~*]+(.+?)$/, "$1"); })
33
+ : iconId;
34
+ var componentName = lodash_1.upperFirst(lodash_1.camelCase(iconId));
35
+ names.push(iconIdAfterTrim);
36
+ cases += whitespace_1.whitespace(4) + "case '" + iconIdAfterTrim + "':\n";
37
+ imports.push(componentName);
38
+ cases += whitespace_1.whitespace(6) + "return <" + componentName + " {...rest} />;\n";
39
+ singleFile = getTemplate_1.getTemplate("SingleIcon" + jsxExtension);
40
+ singleFile = replace_1.replaceSize(singleFile, config.default_icon_size);
41
+ if (jsxExtension === ".tsx") {
42
+ singleFile = replace_1.replaceReactName(singleFile, config.can_import_react);
43
+ }
44
+ singleFile = replace_1.replaceComponentName(singleFile, componentName);
45
+ singleFile = replace_1.replaceSingleIconContent(singleFile, generateCase(item, 4));
46
+ singleFile = replace_1.replaceSizeUnit(singleFile, config.unit);
47
+ fs_1.default.writeFileSync(path_1.default.join(saveDir, componentName + jsxExtension), singleFile);
48
+ if (!config.use_typescript) {
49
+ var typeDefinitionFile = getTemplate_1.getTemplate("SingleIcon.d.ts");
50
+ typeDefinitionFile = replace_1.replaceComponentName(typeDefinitionFile, componentName);
51
+ fs_1.default.writeFileSync(path_1.default.join(saveDir, componentName + ".d.ts"), typeDefinitionFile);
52
+ }
53
+ console.log(colors_1.default.green("√") + " Generated icon \"" + colors_1.default.yellow(iconId) + "\"");
54
+ });
55
+ var iconFile = getTemplate_1.getTemplate("Icon" + jsxExtension);
56
+ iconFile = replace_1.replaceCases(iconFile, cases);
57
+ iconFile = replace_1.replaceImports(iconFile, imports);
58
+ iconFile = replace_1.replaceExports(iconFile, imports);
59
+ if (config.use_typescript) {
60
+ iconFile = replace_1.replaceNames(iconFile, names);
61
+ }
62
+ else {
63
+ iconFile = replace_1.replaceNamesArray(iconFile, names);
64
+ var typeDefinitionFile = getTemplate_1.getTemplate("Icon.d.ts");
65
+ typeDefinitionFile = replace_1.replaceExports(typeDefinitionFile, imports);
66
+ typeDefinitionFile = replace_1.replaceNames(typeDefinitionFile, names);
67
+ fs_1.default.writeFileSync(path_1.default.join(saveDir, "index.d.ts"), typeDefinitionFile);
68
+ }
69
+ fs_1.default.writeFileSync(path_1.default.join(saveDir, "index" + jsxExtension), iconFile);
70
+ console.log("\n" + colors_1.default.green("√") + " All icons have putted into dir: " + colors_1.default.green(config.save_dir) + "\n");
71
+ };
72
+ var generateCase = function (data, baseIdent) {
73
+ var e_1, _a;
74
+ var template = "\n" + whitespace_1.whitespace(baseIdent) + "<svg viewBox=\"" + data.$.viewBox + "\" width={size} height={size} style={style} {...rest}>\n";
75
+ var _loop_1 = function (domName) {
76
+ if (domName === "$") {
77
+ return "continue";
78
+ }
79
+ if (!domName) {
80
+ console.error(colors_1.default.red("Unable to transform dom \"" + domName + "\""));
81
+ process.exit(1);
82
+ }
83
+ var counter = {
84
+ colorIndex: 0,
85
+ baseIdent: baseIdent,
86
+ };
87
+ if (data[domName].$) {
88
+ template += whitespace_1.whitespace(baseIdent + 2) + "<" + domName + addAttribute(domName, data[domName], counter) + "\n" + whitespace_1.whitespace(baseIdent + 2) + "/>\n";
89
+ }
90
+ else if (Array.isArray(data[domName])) {
91
+ data[domName].forEach(function (sub) {
92
+ template += whitespace_1.whitespace(baseIdent + 2) + "<" + domName + addAttribute(domName, sub, counter) + "\n" + whitespace_1.whitespace(baseIdent + 2) + "/>\n";
93
+ });
94
+ }
95
+ };
96
+ try {
97
+ for (var _b = tslib_1.__values(Object.keys(data)), _c = _b.next(); !_c.done; _c = _b.next()) {
98
+ var domName = _c.value;
99
+ _loop_1(domName);
100
+ }
101
+ }
102
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
103
+ finally {
104
+ try {
105
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
106
+ }
107
+ finally { if (e_1) throw e_1.error; }
108
+ }
109
+ template += whitespace_1.whitespace(baseIdent) + "</svg>\n";
110
+ return template;
111
+ };
112
+ var addAttribute = function (domName, sub, counter) {
113
+ var e_2, _a;
114
+ var template = "";
115
+ if (sub && sub.$) {
116
+ if (ATTRIBUTE_FILL_MAP.includes(domName)) {
117
+ // Set default color same as in iconfont.cn
118
+ // And create placeholder to inject color by user's behavior
119
+ sub.$.fill = sub.$.fill || "#333333";
120
+ }
121
+ try {
122
+ for (var _b = tslib_1.__values(Object.keys(sub.$)), _c = _b.next(); !_c.done; _c = _b.next()) {
123
+ var attributeName = _c.value;
124
+ if (attributeName === "fill") {
125
+ template += "\n" + whitespace_1.whitespace(counter.baseIdent + 4) + lodash_1.camelCase(attributeName) + "={getIconColor(color, " + counter.colorIndex + ", '" + sub.$[attributeName] + "')}";
126
+ counter.colorIndex += 1;
127
+ }
128
+ else {
129
+ template += "\n" + whitespace_1.whitespace(counter.baseIdent + 4) + lodash_1.camelCase(attributeName) + "=\"" + sub.$[attributeName] + "\"";
130
+ }
131
+ }
132
+ }
133
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
134
+ finally {
135
+ try {
136
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
137
+ }
138
+ finally { if (e_2) throw e_2.error; }
139
+ }
140
+ }
141
+ return template;
142
+ };
@@ -0,0 +1,10 @@
1
+ export interface Config {
2
+ symbol_url: string;
3
+ use_typescript: boolean;
4
+ save_dir: string;
5
+ trim_icon_prefix: string;
6
+ unit: string;
7
+ default_icon_size: number;
8
+ can_import_react: boolean;
9
+ }
10
+ export declare const getConfig: () => Config;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var path_1 = tslib_1.__importDefault(require("path"));
5
+ var fs_1 = tslib_1.__importDefault(require("fs"));
6
+ var colors_1 = tslib_1.__importDefault(require("colors"));
7
+ var iconfont_json_1 = tslib_1.__importDefault(require("./iconfont.json"));
8
+ var cacheConfig;
9
+ exports.getConfig = function () {
10
+ if (cacheConfig) {
11
+ return cacheConfig;
12
+ }
13
+ var targetFile = path_1.default.resolve("iconfont.json");
14
+ if (!fs_1.default.existsSync(targetFile)) {
15
+ console.warn(colors_1.default.red('File "iconfont.json" doesn\'t exist, did you forget to generate it?'));
16
+ process.exit(1);
17
+ }
18
+ var config = require(targetFile);
19
+ if (!config.symbol_url || !/^(https?:)?\/\//.test(config.symbol_url)) {
20
+ console.warn(colors_1.default.red("You are required to provide symbol_url"));
21
+ process.exit(1);
22
+ }
23
+ if (config.symbol_url.indexOf("//") === 0) {
24
+ config.symbol_url = "http:" + config.symbol_url;
25
+ }
26
+ config.save_dir = config.save_dir || iconfont_json_1.default.save_dir;
27
+ config.default_icon_size =
28
+ config.default_icon_size || iconfont_json_1.default.default_icon_size;
29
+ config.unit = config.unit || iconfont_json_1.default.unit;
30
+ config.can_import_react =
31
+ config.can_import_react || iconfont_json_1.default.can_import_react;
32
+ cacheConfig = config;
33
+ return config;
34
+ };
@@ -0,0 +1 @@
1
+ export declare const getTemplate: (fileName: string) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var fs_1 = tslib_1.__importDefault(require("fs"));
5
+ var path_1 = tslib_1.__importDefault(require("path"));
6
+ exports.getTemplate = function (fileName) {
7
+ return fs_1.default.readFileSync(path_1.default.join(__dirname, "../templates/" + fileName + ".template")).toString();
8
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "symbol_url": "请参考README.md,复制官网提供的JS链接",
3
+ "use_typescript": false,
4
+ "save_dir": "./src/components/iconfont",
5
+ "trim_icon_prefix": "icon",
6
+ "unit": "px",
7
+ "default_icon_size": 18,
8
+ "can_import_react": false
9
+ }
@@ -0,0 +1,10 @@
1
+ export declare const replaceSize: (content: string, size: number) => string;
2
+ export declare const replaceCases: (content: string, cases: string) => string;
3
+ export declare const replaceNames: (content: string, names: string[]) => string;
4
+ export declare const replaceNamesArray: (content: string, names: string[]) => string;
5
+ export declare const replaceComponentName: (content: string, name: string) => string;
6
+ export declare const replaceReactName: (content: string, canImport: boolean) => string;
7
+ export declare const replaceSingleIconContent: (content: string, render: string) => string;
8
+ export declare const replaceImports: (content: string, imports: string[]) => string;
9
+ export declare const replaceSizeUnit: (content: string, unit: string) => string;
10
+ export declare const replaceExports: (content: string, exports: string[]) => string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceSize = function (content, size) {
4
+ return content.replace(/#size#/g, String(size));
5
+ };
6
+ exports.replaceCases = function (content, cases) {
7
+ return content.replace(/#cases#/g, cases);
8
+ };
9
+ exports.replaceNames = function (content, names) {
10
+ return content.replace(/#names#/g, names.join("' | '"));
11
+ };
12
+ exports.replaceNamesArray = function (content, names) {
13
+ return content.replace(/#namesArray#/g, JSON.stringify(names).replace(/"/g, "'").replace(/','/g, "', '"));
14
+ };
15
+ exports.replaceComponentName = function (content, name) {
16
+ return content.replace(/#componentName#/g, name);
17
+ };
18
+ exports.replaceReactName = function (content, canImport) {
19
+ return content.replace(/#reactName#/g, canImport ? "React, " : "");
20
+ };
21
+ exports.replaceSingleIconContent = function (content, render) {
22
+ return content.replace(/#iconContent#/g, render);
23
+ };
24
+ exports.replaceImports = function (content, imports) {
25
+ return content.replace(/#imports#/g, imports.map(function (item) { return "import " + item + " from './" + item + "';"; }).join("\n"));
26
+ };
27
+ exports.replaceSizeUnit = function (content, unit) {
28
+ return content.replace(/\{size\}/g, "{size + '" + unit + "'}");
29
+ };
30
+ exports.replaceExports = function (content, exports) {
31
+ return content.replace(/#exports#/g, exports
32
+ .map(function (item) { return "export { default as " + item + " } from './" + item + "';"; })
33
+ .join("\n"));
34
+ };
@@ -0,0 +1 @@
1
+ export declare const whitespace: (repeat: number) => string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.whitespace = function (repeat) {
4
+ return ' '.repeat(repeat);
5
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@sj-distributor/react-iconfont-cli",
3
+ "version": "2.0.3",
4
+ "main": "index.js",
5
+ "keywords": [
6
+ "iconfont",
7
+ "react",
8
+ "react-iconfont",
9
+ "icon",
10
+ "icons",
11
+ "iconfont.cn"
12
+ ],
13
+ "repository": "https://github.com/Simoon-F/react-iconfont-cli",
14
+ "author": "Simon <simoonf@vip.qq.com>",
15
+ "license": "MIT",
16
+ "bin": {
17
+ "sj-iconfont": "./commands/help.js",
18
+ "sj-iconfont-init": "./commands/createJson.js",
19
+ "sj-iconfont-h5": "./commands/createIcon.js"
20
+ },
21
+ "peerDependencies": {
22
+ "react": "*"
23
+ },
24
+ "dependencies": {
25
+ "colors": "^1.3.3",
26
+ "glob": "^7.1.4",
27
+ "iconfont-parser": "^1.0.0",
28
+ "lodash": "^4.17.15",
29
+ "minimist": "^1.2.5",
30
+ "mkdirp": "^0.5.1",
31
+ "tslib": "^1.10.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/fs-extra": "^8.0.0",
35
+ "@types/glob": "^7.1.1",
36
+ "@types/lodash": "^4.14.137",
37
+ "@types/minimist": "^1.2.0",
38
+ "@types/mkdirp": "^0.5.2",
39
+ "@types/node": "^12.7.2",
40
+ "@types/react": "^16.9.2",
41
+ "react": "^16.9.0",
42
+ "ts-node": "^8.3.0",
43
+ "typescript": "^3.5.3"
44
+ }
45
+ }
@@ -0,0 +1,14 @@
1
+ /* eslint-disable */
2
+
3
+ import { SVGAttributes, FunctionComponent } from 'react';
4
+ #exports#
5
+
6
+ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
7
+ name: '#names#';
8
+ size?: number;
9
+ color?: string | string[];
10
+ }
11
+
12
+ declare const IconFont: FunctionComponent<Props>;
13
+
14
+ export default IconFont;
@@ -0,0 +1,15 @@
1
+ /* eslint-disable */
2
+
3
+ import React from 'react';
4
+ #imports#
5
+ #exports#
6
+
7
+ const IconFont = ({ name, ...rest }) => {
8
+ switch (name) {
9
+ #cases#
10
+ }
11
+
12
+ return null;
13
+ };
14
+
15
+ export default IconFont;
@@ -0,0 +1,24 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ import React, { SVGAttributes, FunctionComponent } from 'react';
5
+ #imports#
6
+ #exports#
7
+
8
+ export type IconNames = '#names#';
9
+
10
+ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
11
+ name: IconNames;
12
+ size?: number;
13
+ color?: string | string[];
14
+ }
15
+
16
+ const IconFont: FunctionComponent<Props> = ({ name, ...rest }) => {
17
+ switch (name) {
18
+ #cases#
19
+ }
20
+
21
+ return null;
22
+ };
23
+
24
+ export default IconFont;
@@ -0,0 +1,12 @@
1
+ /* eslint-disable */
2
+
3
+ import { SVGAttributes, FunctionComponent } from 'react';
4
+
5
+ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
6
+ size?: number;
7
+ color?: string | string[];
8
+ }
9
+
10
+ declare const #componentName#: FunctionComponent<Props>;
11
+
12
+ export default #componentName#;
@@ -0,0 +1,20 @@
1
+ /* eslint-disable */
2
+
3
+ import React from 'react';
4
+ import { getIconColor } from './helper';
5
+
6
+ const DEFAULT_STYLE = {
7
+ display: 'block',
8
+ };
9
+
10
+ const #componentName# = ({ size, color, style: _style, ...rest }) => {
11
+ const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;
12
+
13
+ return (#iconContent# );
14
+ };
15
+
16
+ #componentName#.defaultProps = {
17
+ size: #size#,
18
+ };
19
+
20
+ export default #componentName#;
@@ -0,0 +1,26 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ import #reactName#{ CSSProperties, SVGAttributes, FunctionComponent } from 'react';
5
+ import { getIconColor } from './helper';
6
+
7
+ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
8
+ size?: number;
9
+ color?: string | string[];
10
+ }
11
+
12
+ const DEFAULT_STYLE: CSSProperties = {
13
+ display: 'block',
14
+ };
15
+
16
+ const #componentName#: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
17
+ const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;
18
+
19
+ return (#iconContent# );
20
+ };
21
+
22
+ #componentName#.defaultProps = {
23
+ size: #size#,
24
+ };
25
+
26
+ export default #componentName#;
@@ -0,0 +1,3 @@
1
+ /* eslint-disable */
2
+
3
+ export declare const getIconColor: (color: string | string[] | undefined, index: number, defaultColor: string) => string;
@@ -0,0 +1,17 @@
1
+ /* eslint-disable */
2
+
3
+ /**
4
+ * @param {string | string[] | undefined} color
5
+ * @param {number} index
6
+ * @param {string} defaultColor
7
+ * @return {string}
8
+ */
9
+ export const getIconColor = (color, index, defaultColor) => {
10
+ return color
11
+ ? (
12
+ typeof color === 'string'
13
+ ? color
14
+ : color[index] || defaultColor
15
+ )
16
+ : defaultColor;
17
+ };
@@ -0,0 +1,12 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export const getIconColor = (color: string | string[] | undefined, index: number, defaultColor: string) => {
5
+ return color
6
+ ? (
7
+ typeof color === 'string'
8
+ ? color
9
+ : color[index] || defaultColor
10
+ )
11
+ : defaultColor;
12
+ };