Skip to content

Commit a5479f2

Browse files
committed
update generate icons for vue
1 parent 65a15be commit a5479f2

File tree

1,181 files changed

+11083
-9924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,181 files changed

+11083
-9924
lines changed

Diff for: packages/icons-vue/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
**/*.spec.*
33
**/style/
44
*.html
5+
src/icons

Diff for: packages/icons-vue/.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ build/
2929
.vscode
3030

3131
# publish
32-
*.tgz
32+
*.tgz
33+
34+
/icons
35+
/*.js
36+
/*.d.ts
37+
!.jest.js
38+
!Icon.d.ts

Diff for: packages/icons-vue/.jest.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
const libDir = process.env.LIB_DIR;
22

33
const transformIgnorePatterns = [
4-
'/dist/', 'node_modules\/[^/]+?\/(?!(es|node_modules)\/)', // Ignore modules without es dir
4+
'/dist/',
5+
'node_modules/[^/]+?/(?!(es|node_modules)/)', // Ignore modules without es dir
56
];
67

78
module.exports = {
89
testURL: 'http://localhost/',
9-
moduleFileExtensions: [
10-
"js",
11-
"jsx",
12-
"json",
13-
"vue",
14-
],
10+
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
1511
modulePathIgnorePatterns: ['/_site/'],
16-
testPathIgnorePatterns: [
17-
'/node_modules/', 'node'
18-
],
12+
testPathIgnorePatterns: ['/node_modules/', 'node'],
1913
transform: {
20-
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
21-
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest"
14+
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
15+
'^.+\\.(js|jsx)$': '<rootDir>/node_modules/babel-jest',
2216
},
23-
testRegex: libDir === 'dist'
24-
? 'demo\\.test\\.js$'
25-
: '.*\\.test\\.js$',
17+
testRegex: libDir === 'dist' ? 'demo\\.test\\.js$' : '.*\\.test\\.js$',
2618
moduleNameMapper: {
27-
"^@/(.*)$": "<rootDir>/$1",
19+
'^@/(.*)$': '<rootDir>/$1',
2820
},
29-
snapshotSerializers: ["<rootDir>/node_modules/jest-serializer-vue"],
21+
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
3022
collectCoverage: process.env.COVERAGE === 'true',
31-
collectCoverageFrom: [
32-
"src/**/*.{js,jsx,vue}",
33-
],
34-
transformIgnorePatterns
23+
collectCoverageFrom: ['src/**/*.{js,jsx,vue}'],
24+
transformIgnorePatterns,
25+
verbose: true,
3526
};

Diff for: packages/icons-vue/examples/basic.jsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import Vue from 'vue';
2-
import { Home, SettingFilled } from '../src';
3-
import Icon, { Smile, Sync, Loading, Filter } from '../src';
2+
import { SmileOutlined, SyncOutlined, LoadingOutlined, HomeOutlined, SettingFilled } from '../src';
3+
import Icon, { FilterOutlined } from '../src';
4+
import { AntDesignOutlined } from '@ant-design/icons-svg';
5+
import IconBase from '../src/components/IconBase';
46

5-
Vue.component(Filter.name, Filter);
7+
Vue.component(FilterOutlined.name, FilterOutlined);
68
const SimpleDemo = {
79
render() {
810
return (
911
<div class="icons-list">
10-
<Home />
12+
<HomeOutlined />
1113
<SettingFilled />
12-
<Smile />
13-
<Sync spin />
14-
<Smile rotate={180} />
15-
<Loading />
16-
<icon-filter />
14+
<SmileOutlined />
15+
<SyncOutlined spin />
16+
<SmileOutlined rotate={180} />
17+
<LoadingOutlined />
18+
<icon-filter-outlined />
1719
<Icon viewBox="0 0 24 24">
1820
<title>Cool Home</title>
1921
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
2022
</Icon>
2123
<Icon viewBox="0 0 24 24"></Icon>
24+
<IconBase icon={AntDesignOutlined} />
2225
</div>
2326
);
2427
},

Diff for: packages/icons-vue/examples/simple.jsx

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import Vue from "vue";
2-
import { AntDesign, Dashboard, Twitter } from "../src";
3-
import "./index.less";
1+
import Vue from 'vue';
2+
import { AntDesignOutlined, DashboardOutlined, TwitterOutlined } from '../src';
3+
import './index.less';
44

5-
const displaySize = ["64px", "48px", "32px", "24px", "16px", "12px", "8px"];
5+
const displaySize = ['64px', '48px', '32px', '24px', '16px', '12px', '8px'];
66
const relatedHref =
7-
"https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4";
7+
'https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4';
88
const SimpleDemo = {
99
methods: {
1010
renderStatement(fontSize) {
1111
const style = {
1212
fontSize,
13-
color: (fontSize === "48px" && "lightblue") || "inherit"
13+
color: (fontSize === '48px' && 'lightblue') || 'inherit',
1414
};
1515
return (
1616
<div class="simple-wrap" key={fontSize} style={style}>
1717
{fontSize}
1818
Ant Design
19-
<AntDesign />
19+
<AntDesignOutlined />
2020
0123
21-
<Dashboard />
21+
<DashboardOutlined />
2222
你好
23-
<Twitter />
23+
<TwitterOutlined />
2424
</div>
2525
);
2626
},
2727
renderStatements() {
2828
return displaySize.map(fontSize => {
2929
return this.renderStatement(fontSize);
3030
});
31-
}
31+
},
3232
},
3333

3434
render() {
3535
return (
3636
<div>
3737
<h1>Simple Demo - Icons Alignments</h1>
3838
{this.renderStatements()}
39-
See{" "}
40-
<a href={relatedHref} target={"_blank"}>
39+
See{' '}
40+
<a href={relatedHref} target={'_blank'}>
4141
related blog
42-
</a>{" "}
42+
</a>{' '}
4343
for detail.
4444
</div>
4545
);
46-
}
46+
},
4747
};
4848

4949
new Vue({
50-
el: "#__vue-content>div",
50+
el: '#__vue-content>div',
5151
render() {
5252
return <SimpleDemo />;
53-
}
53+
},
5454
});

Diff for: packages/icons-vue/examples/use-iconfontcn.jsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Vue from "vue";
2-
import { createFromIconfontCN } from "../src";
1+
import Vue from 'vue';
2+
import { createFromIconfontCN } from '../src';
33

44
const IconFont = createFromIconfontCN({
5-
scriptUrl: "//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js"
5+
scriptUrl: '//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js',
66
});
77

88
const SimpleDemo = {
@@ -20,12 +20,12 @@ const SimpleDemo = {
2020
<IconFont type="icon-twitter" />
2121
</div>
2222
);
23-
}
23+
},
2424
};
2525

2626
new Vue({
27-
el: "#__vue-content>div",
27+
el: '#__vue-content>div',
2828
render() {
2929
return <SimpleDemo />;
30-
}
30+
},
3131
});

Diff for: packages/icons-vue/package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,22 @@
1313
],
1414
"license": "MIT",
1515
"scripts": {
16-
"cleanup": "./scripts/cleanup.sh",
16+
"clean": "./scripts/cleanup.sh",
1717
"start": "vc-tools run server",
1818
"lint": "eslint -c ./.eslintrc --fix --ext .jsx,.js,.vue ./src",
1919
"compile": "vc-tools run compile --babel-runtime",
2020
"build": "vc-tools run build",
2121
"dist": "vc-tools run dist",
2222
"test": "cross-env NODE_ENV=test jest --config .jest.js",
23-
"generate": "node scripts/generateIcons.js",
24-
"prepublishOnly": "npm run lint && npm run test && npm run compile && np --no-cleanup --yolo --no-publish"
23+
"generate": "rimraf src/icons && node scripts/generate.js --target=icon",
24+
"postcompile": "npm run clean && node scripts/generate.js --target=entry",
25+
"prepublishOnly": "npm run lint && npm run generate && npm run compile && npm run test && np --no-cleanup --yolo --no-publish"
2526
},
26-
"files": [
27-
"es",
28-
"lib"
29-
],
3027
"peerDependencies": {
3128
"vue": ">=2.5.0",
3229
"vue-template-compiler": ">=2.5.0"
3330
},
3431
"devDependencies": {
35-
"@ant-design/icons": "^2.0.0",
3632
"@types/jest": "^24.0.17",
3733
"@types/node": "^10.5.5",
3834
"@types/vue": "^2.0.0",

Diff for: packages/icons-vue/scripts/cleanup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
ls | grep -v .jest.js | grep -v .eslintrc.js | grep -e '.d.ts' -e '.js$' | xargs rm
33
# keep one d.ts to make vscode auto import working with corrcet path
4-
rm ./es/icons/*.d.ts
4+
rm ./es/icons/*.d.ts || echo

Diff for: packages/icons-vue/scripts/generate.js

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const lodash = require('lodash');
4+
const allIconDefs = require('@ant-design/icons-svg');
5+
6+
const fsPromises = fs.promises;
7+
const template = lodash.template;
8+
9+
function walk(fn) {
10+
return Promise.all(
11+
Object.keys(allIconDefs).map(svgIdentifier => {
12+
const iconDef = allIconDefs[svgIdentifier];
13+
14+
return fn({ svgIdentifier, ...iconDef });
15+
}),
16+
);
17+
}
18+
19+
async function generateIcons() {
20+
const iconsDir = path.join(__dirname, '../src/icons');
21+
try {
22+
await fsPromises.access(iconsDir);
23+
} catch (err) {
24+
await fsPromises.mkdir(iconsDir);
25+
}
26+
27+
const render = template(
28+
`
29+
// GENERATE BY ./scripts/generate.js
30+
// DON NOT EDIT IT MANUALLY
31+
32+
import Icon from '../components/AntdIcon';
33+
import <%= svgIdentifier %>Svg from '@ant-design/icons-svg/lib/asn/<%= svgIdentifier %>';
34+
35+
export default {
36+
name: 'Icon<%= svgIdentifier %>',
37+
displayName: '<%= svgIdentifier %>',
38+
functional: true,
39+
props: [ ...Icon.props ],
40+
render: (h, { data, children, props }) =>
41+
h(
42+
Icon,
43+
{ ...data, props: { ...data.props, ...props, icon: <%= svgIdentifier %>Svg } },
44+
children,
45+
),
46+
};
47+
`.trim(),
48+
);
49+
50+
await walk(async ({ svgIdentifier }) => {
51+
// generate icon file
52+
await fsPromises.writeFile(
53+
path.resolve(__dirname, `../src/icons/${svgIdentifier}.jsx`),
54+
render({ svgIdentifier }),
55+
);
56+
});
57+
58+
// generate icon index
59+
const entryText = Object.keys(allIconDefs)
60+
.map(svgIdentifier => {
61+
return `export { default as ${svgIdentifier} } from './${svgIdentifier}';`;
62+
})
63+
.join('\n');
64+
65+
await fsPromises.appendFile(
66+
path.resolve(__dirname, '../src/icons/index.jsx'),
67+
`
68+
// GENERATE BY ./scripts/generate.js
69+
// DON NOT EDIT IT MANUALLY
70+
`.trim() +
71+
'\n' +
72+
entryText,
73+
);
74+
}
75+
76+
async function generateEntries() {
77+
const render = template(
78+
`
79+
'use strict';
80+
Object.defineProperty(exports, "__esModule", {
81+
value: true
82+
});
83+
exports.default = void 0;
84+
85+
var _<%= svgIdentifier %> = _interopRequireDefault(require('./lib/icons/<%= svgIdentifier %>'));
86+
87+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
88+
89+
var _default = _<%= svgIdentifier %>;
90+
exports.default = _default;
91+
module.exports = _default;
92+
`.trim(),
93+
);
94+
95+
await walk(async ({ svgIdentifier }) => {
96+
// generate `Icon.js` in root folder
97+
await fsPromises.writeFile(
98+
path.resolve(__dirname, `../${svgIdentifier}.js`),
99+
render({
100+
svgIdentifier,
101+
}),
102+
);
103+
104+
// generate `Icon.d.ts` in root folder
105+
await fsPromises.writeFile(
106+
path.resolve(__dirname, `../${svgIdentifier}.d.ts`),
107+
`
108+
import { IconDefinition } from '@ant-design/icons-svg/lib/types';
109+
declare class ${svgIdentifier} extends Vue {
110+
static install(vue: typeof Vue): void;
111+
icon: IconDefinition;
112+
twoToneColor?: string | [string, string];
113+
tabIndex?: number;
114+
spin?: boolean;
115+
rotate?: number;
116+
};
117+
export default ${svgIdentifier};
118+
`.trim(),
119+
);
120+
});
121+
}
122+
123+
if (process.argv[2] === '--target=icon') {
124+
generateIcons();
125+
}
126+
127+
if (process.argv[2] === '--target=entry') {
128+
generateEntries();
129+
}

0 commit comments

Comments
 (0)