mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
refactoring: use Promise.all (#42219)
* chore: use Promise.all * del type * fix
This commit is contained in:
parent
4271ff0976
commit
a4669ace4c
@ -1,15 +1,14 @@
|
|||||||
import { globSync } from 'glob';
|
import { globSync } from 'glob';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type { FC } from 'react';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
type StyleFn = (prefix?: string) => void;
|
type StyleFn = (prefix?: string) => void;
|
||||||
|
|
||||||
type GenCssinjs = (options: {
|
interface GenCssinjsOptions {
|
||||||
key: string;
|
key: string;
|
||||||
render: (component: FC) => void;
|
render: (component: React.FC) => void;
|
||||||
beforeRender?: (componentName: string) => void;
|
beforeRender?: (componentName: string) => void;
|
||||||
}) => Promise<void>;
|
}
|
||||||
|
|
||||||
export const styleFiles = globSync(
|
export const styleFiles = globSync(
|
||||||
path.join(
|
path.join(
|
||||||
@ -18,29 +17,27 @@ export const styleFiles = globSync(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const generateCssinjs: GenCssinjs = async ({ key, beforeRender, render }) => {
|
export const generateCssinjs = ({ key, beforeRender, render }: GenCssinjsOptions) =>
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
Promise.all(
|
||||||
for (const file of styleFiles) {
|
styleFiles.map(async (file) => {
|
||||||
const pathArr = file.split('/');
|
const pathArr = file.split('/');
|
||||||
const styleIndex = pathArr.lastIndexOf('style');
|
const styleIndex = pathArr.lastIndexOf('style');
|
||||||
const componentName = pathArr[styleIndex - 1];
|
const componentName = pathArr[styleIndex - 1];
|
||||||
let useStyle: StyleFn = () => {};
|
let useStyle: StyleFn = () => {};
|
||||||
if (file.includes('grid')) {
|
if (file.includes('grid')) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
const { useColStyle, useRowStyle } = await import(file);
|
||||||
const { useColStyle, useRowStyle } = await import(file);
|
useStyle = (prefixCls: string) => {
|
||||||
useStyle = (prefixCls: string) => {
|
useRowStyle(prefixCls);
|
||||||
useRowStyle(prefixCls);
|
useColStyle(prefixCls);
|
||||||
useColStyle(prefixCls);
|
};
|
||||||
|
} else {
|
||||||
|
useStyle = (await import(file)).default;
|
||||||
|
}
|
||||||
|
const Demo: React.FC = () => {
|
||||||
|
useStyle(`${key}-${componentName}`);
|
||||||
|
return React.createElement('div');
|
||||||
};
|
};
|
||||||
} else {
|
beforeRender?.(componentName);
|
||||||
// eslint-disable-next-line no-await-in-loop
|
render?.(Demo);
|
||||||
useStyle = (await import(file)).default;
|
}),
|
||||||
}
|
);
|
||||||
const Demo: FC = () => {
|
|
||||||
useStyle(`${key}-${componentName}`);
|
|
||||||
return React.createElement('div');
|
|
||||||
};
|
|
||||||
beforeRender?.(componentName);
|
|
||||||
render?.(Demo);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user