Skip to content

Commit 2ee3d43

Browse files
authored
Feat css var (#5327)
* style: affix & util * feat(alert): add customIcon slot * feat(anchor): ts type * style: auto-complete * feat: avatar add crossOrigin & maxPopoverTrigger * style(backTop): v-show instead v-if * style: badge * style: breadcrumb * feat: button add global size * feat: update i18n * feat: picker add disabledTime * test: update snap * doc: update img url * style: fix Card tabs of left position * doc: update cascader doc * feat: collapse * style: comment * style: configprovider * feat: date-picker add soem icon slot * style: update descriptions style * feat: add divider orientationMargin * doc: update drawer * feat: dropdown add destroyPopupOnHide & loading * style: update empty * feat: form add labelWrap * style: update grid * test: update grid snap * fix: image ts error * fix: mentions cannot select, close #5233 * doc: update pagination change info, close #5293 * fix: table dynamic expand error, close #5295 * style: remove not use * release 3.0.0-beta.11 * doc: update typo * feat: input add showCount * feat: inputNumber add prefix slot * style: update layout * style: update list * feat: add locale i18 * style: update locale ts * style: update mentions * feat: menu divider add dashed * perf: menu * perf: menu animate * feat: modal method add wrapClassName * style: update pageheader * feat: update pagination ts * feat: confirm add showCancel & promise * doc: update popover * style: update progress * style: radio * style: update rate、result、row * feat: select add fieldNames * feat: add skeleton button & input * feat: spin tip support slot * style: slider & space * stype: update steps ts type * style: update switch * feat: table add tree filter * test: update input sanp * feat: table add filterMode... * fix: tree autoExpandParent bug * test: update input snap * doc: tabs add destroyInactiveTabPane * style: update tag * style: update timeline & time-picker * fix: Tooltip arrowPointAtCenter 1px shift bug * feat: typography add enterEnterIcon triggerType * doc: update tree-select * fix: deps and TypeScript types * style: udpate transfer * style: update style * doc: add colorScheme * chore: add css var builg * doc: sort api * style: lint code * doc: add css var * test: update snap * chore: add pre script * chore: update lint * perf: collapse animate * perf: collapse tree * perf: typography shaking when edit * doc: update auto-complete demo * fix: table tree not have animate * feat: deprecated dropdown center placement * feat: deprecated dropdown center placement * test: update snap
1 parent fdf7857 commit 2ee3d43

File tree

594 files changed

+11057
-4138
lines changed

Some content is hidden

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

594 files changed

+11057
-4138
lines changed

.antd-tools.config.js

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const defaultVars = require('./scripts/default-vars');
4+
const darkVars = require('./scripts/dark-vars');
5+
const compactVars = require('./scripts/compact-vars');
6+
7+
function generateThemeFileContent(theme) {
8+
return `const { ${theme}ThemeSingle } = require('./theme');\nconst defaultTheme = require('./default-theme');\n
9+
module.exports = {
10+
...defaultTheme,
11+
...${theme}ThemeSingle
12+
}`;
13+
}
14+
15+
// We need compile additional content for antd user
16+
function finalizeCompile() {
17+
if (fs.existsSync(path.join(__dirname, './lib'))) {
18+
// Build a entry less file to dist/antd.less
19+
const componentsPath = path.join(process.cwd(), 'components');
20+
let componentsLessContent = '';
21+
// Build components in one file: lib/style/components.less
22+
fs.readdir(componentsPath, (err, files) => {
23+
files.forEach(file => {
24+
if (fs.existsSync(path.join(componentsPath, file, 'style', 'index.less'))) {
25+
componentsLessContent += `@import "../${path.posix.join(
26+
file,
27+
'style',
28+
'index-pure.less',
29+
)}";\n`;
30+
}
31+
});
32+
fs.writeFileSync(
33+
path.join(process.cwd(), 'lib', 'style', 'components.less'),
34+
componentsLessContent,
35+
);
36+
});
37+
}
38+
}
39+
40+
function buildThemeFile(theme, vars) {
41+
// Build less entry file: dist/antd.${theme}.less
42+
if (theme !== 'default') {
43+
fs.writeFileSync(
44+
path.join(process.cwd(), 'dist', `antd.${theme}.less`),
45+
`@import "../lib/style/${theme}.less";\n@import "../lib/style/components.less";`,
46+
);
47+
// eslint-disable-next-line no-console
48+
console.log(`Built a entry less file to dist/antd.${theme}.less`);
49+
} else {
50+
fs.writeFileSync(
51+
path.join(process.cwd(), 'dist', `default-theme.js`),
52+
`module.exports = ${JSON.stringify(vars, null, 2)};\n`,
53+
);
54+
return;
55+
}
56+
57+
// Build ${theme}.js: dist/${theme}-theme.js, for less-loader
58+
59+
fs.writeFileSync(
60+
path.join(process.cwd(), 'dist', `theme.js`),
61+
`const ${theme}ThemeSingle = ${JSON.stringify(vars, null, 2)};\n`,
62+
{
63+
flag: 'a',
64+
},
65+
);
66+
67+
fs.writeFileSync(
68+
path.join(process.cwd(), 'dist', `${theme}-theme.js`),
69+
generateThemeFileContent(theme),
70+
);
71+
72+
// eslint-disable-next-line no-console
73+
console.log(`Built a ${theme} theme js file to dist/${theme}-theme.js`);
74+
}
75+
76+
function finalizeDist() {
77+
if (fs.existsSync(path.join(__dirname, './dist'))) {
78+
// Build less entry file: dist/antd.less
79+
fs.writeFileSync(
80+
path.join(process.cwd(), 'dist', 'antd.less'),
81+
'@import "../lib/style/default.less";\n@import "../lib/style/components.less";',
82+
);
83+
// eslint-disable-next-line no-console
84+
fs.writeFileSync(
85+
path.join(process.cwd(), 'dist', 'theme.js'),
86+
`const defaultTheme = require('./default-theme.js');\n`,
87+
);
88+
// eslint-disable-next-line no-console
89+
console.log('Built a entry less file to dist/antd.less');
90+
buildThemeFile('default', defaultVars);
91+
buildThemeFile('dark', darkVars);
92+
buildThemeFile('compact', compactVars);
93+
buildThemeFile('variable', {});
94+
fs.writeFileSync(
95+
path.join(process.cwd(), 'dist', `theme.js`),
96+
`
97+
function getThemeVariables(options = {}) {
98+
let themeVar = {
99+
'hack': \`true;@import "\${require.resolve('antd/lib/style/color/colorPalette.less')}";\`,
100+
...defaultTheme
101+
};
102+
if(options.dark) {
103+
themeVar = {
104+
...themeVar,
105+
...darkThemeSingle
106+
}
107+
}
108+
if(options.compact){
109+
themeVar = {
110+
...themeVar,
111+
...compactThemeSingle
112+
}
113+
}
114+
return themeVar;
115+
}
116+
117+
module.exports = {
118+
darkThemeSingle,
119+
compactThemeSingle,
120+
getThemeVariables
121+
}`,
122+
{
123+
flag: 'a',
124+
},
125+
);
126+
}
127+
}
128+
129+
function isComponentStyleEntry(file) {
130+
return file.path.match(/style(\/|\\)index\.tsx/);
131+
}
132+
133+
function needTransformStyle(content) {
134+
return content.includes('../../style/index.less') || content.includes('./index.less');
135+
}
136+
137+
module.exports = {
138+
compile: {
139+
includeLessFile: [/(\/|\\)components(\/|\\)style(\/|\\)default.less$/],
140+
transformTSFile(file) {
141+
if (isComponentStyleEntry(file)) {
142+
let content = file.contents.toString();
143+
144+
if (needTransformStyle(content)) {
145+
const cloneFile = file.clone();
146+
147+
// Origin
148+
content = content.replace('../../style/index.less', '../../style/default.less');
149+
cloneFile.contents = Buffer.from(content);
150+
151+
return cloneFile;
152+
}
153+
}
154+
},
155+
transformFile(file) {
156+
if (isComponentStyleEntry(file)) {
157+
const indexLessFilePath = file.path.replace('index.tsx', 'index.less');
158+
159+
if (fs.existsSync(indexLessFilePath)) {
160+
// We put origin `index.less` file to `index-pure.less`
161+
const pureFile = file.clone();
162+
pureFile.contents = Buffer.from(fs.readFileSync(indexLessFilePath, 'utf8'));
163+
pureFile.path = pureFile.path.replace('index.tsx', 'index-pure.less');
164+
165+
// Rewrite `index.less` file with `root-entry-name`
166+
const indexLessFile = file.clone();
167+
indexLessFile.contents = Buffer.from(
168+
[
169+
// Inject variable
170+
'@root-entry-name: default;',
171+
// Point to origin file
172+
"@import './index-pure.less';",
173+
].join('\n\n'),
174+
);
175+
indexLessFile.path = indexLessFile.path.replace('index.tsx', 'index.less');
176+
177+
return [indexLessFile, pureFile];
178+
}
179+
}
180+
181+
return [];
182+
},
183+
lessConfig: {
184+
modifyVars: {
185+
'root-entry-name': 'default',
186+
},
187+
},
188+
finalize: finalizeCompile,
189+
},
190+
dist: {
191+
finalize: finalizeDist,
192+
},
193+
generateThemeFileContent,
194+
bail: true,
195+
};

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ es/
77
lib/
88
_site/
99
dist/
10+
components/version/version.tsx

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ vetur/
7676
report.html
7777

7878
site/src/router/demoRoutes.js
79+
80+
components/version/version.tsx
81+
~component-api.json

antd-tools/apiCollection.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Read all the api from current documents
2+
3+
const glob = require('glob');
4+
const fs = require('fs');
5+
6+
const COMPONENT_NAME = /components\/([^/]*)/;
7+
const PROP_NAME = /^\s*\|\s*([^\s|]*)/;
8+
9+
const components = {};
10+
11+
function mappingPropLine(component, line) {
12+
const propMatch = line.match(PROP_NAME);
13+
if (!propMatch) return;
14+
15+
const propName = propMatch[1];
16+
if (!/^[a-z]/.test(propName)) return;
17+
18+
components[component] = Array.from(new Set([...(components[component] || []), propName]));
19+
}
20+
21+
function apiReport(entities) {
22+
const apis = {};
23+
Object.keys(entities).forEach(component => {
24+
const apiList = entities[component];
25+
apiList.forEach(api => {
26+
if (typeof apis[api] === 'function') {
27+
apis[api] = [];
28+
}
29+
apis[api] = [...(apis[api] || []), component];
30+
});
31+
});
32+
33+
return apis;
34+
}
35+
36+
function printReport(apis) {
37+
const apiList = Object.keys(apis).map(api => ({
38+
name: api,
39+
componentList: apis[api],
40+
}));
41+
apiList.sort((a, b) => b.componentList.length - a.componentList.length);
42+
// eslint-disable-next-line no-console
43+
console.log('| name | components | comments |');
44+
// eslint-disable-next-line no-console
45+
console.log('| ---- | ---------- | -------- |');
46+
apiList.forEach(({ name, componentList }) => {
47+
// eslint-disable-next-line no-console
48+
console.log('|', name, '|', componentList.join(', '), '| |');
49+
});
50+
}
51+
52+
module.exports = () => {
53+
glob('components/*/*.md', (error, files) => {
54+
files.forEach(filePath => {
55+
// Read md file to parse content
56+
const content = fs.readFileSync(filePath, 'utf8');
57+
const component = filePath.match(COMPONENT_NAME)[1];
58+
59+
// Parse lines to get API
60+
const lines = content.split(/[\r\n]+/);
61+
lines.forEach(line => {
62+
mappingPropLine(component, line);
63+
});
64+
});
65+
66+
printReport(apiReport(components));
67+
});
68+
};

antd-tools/cli/run.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'use strict';
55

66
require('colorful').colorful();
7-
require('colorful').isatty = true;
87
const gulp = require('gulp');
98
const program = require('commander');
109

antd-tools/getNpm.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const runCmd = require('./runCmd');
4+
5+
module.exports = function (done) {
6+
if (process.env.NPM_CLI) {
7+
done(process.env.NPM_CLI);
8+
return;
9+
}
10+
runCmd('which', ['tnpm'], code => {
11+
let npm = 'npm';
12+
if (!code) {
13+
npm = 'tnpm';
14+
}
15+
done(npm);
16+
});
17+
};

0 commit comments

Comments
 (0)