|
|
@ -1,15 +1,14 @@ |
|
|
|
import { globSync } from 'glob'; |
|
|
|
import path from 'path'; |
|
|
|
import type { FC } from 'react'; |
|
|
|
import React from 'react'; |
|
|
|
|
|
|
|
type StyleFn = (prefix?: string) => void; |
|
|
|
|
|
|
|
type GenCssinjs = (options: { |
|
|
|
interface GenCssinjsOptions { |
|
|
|
key: string; |
|
|
|
render: (component: FC) => void; |
|
|
|
render: (component: React.FC) => void; |
|
|
|
beforeRender?: (componentName: string) => void; |
|
|
|
}) => Promise<void>; |
|
|
|
} |
|
|
|
|
|
|
|
export const styleFiles = globSync( |
|
|
|
path.join( |
|
|
@ -18,29 +17,27 @@ export const styleFiles = globSync( |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
export const generateCssinjs: GenCssinjs = async ({ key, beforeRender, render }) => { |
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
for (const file of styleFiles) { |
|
|
|
const pathArr = file.split('/'); |
|
|
|
const styleIndex = pathArr.lastIndexOf('style'); |
|
|
|
const componentName = pathArr[styleIndex - 1]; |
|
|
|
let useStyle: StyleFn = () => {}; |
|
|
|
if (file.includes('grid')) { |
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
const { useColStyle, useRowStyle } = await import(file); |
|
|
|
useStyle = (prefixCls: string) => { |
|
|
|
useRowStyle(prefixCls); |
|
|
|
useColStyle(prefixCls); |
|
|
|
export const generateCssinjs = ({ key, beforeRender, render }: GenCssinjsOptions) => |
|
|
|
Promise.all( |
|
|
|
styleFiles.map(async (file) => { |
|
|
|
const pathArr = file.split('/'); |
|
|
|
const styleIndex = pathArr.lastIndexOf('style'); |
|
|
|
const componentName = pathArr[styleIndex - 1]; |
|
|
|
let useStyle: StyleFn = () => {}; |
|
|
|
if (file.includes('grid')) { |
|
|
|
const { useColStyle, useRowStyle } = await import(file); |
|
|
|
useStyle = (prefixCls: string) => { |
|
|
|
useRowStyle(prefixCls); |
|
|
|
useColStyle(prefixCls); |
|
|
|
}; |
|
|
|
} else { |
|
|
|
useStyle = (await import(file)).default; |
|
|
|
} |
|
|
|
const Demo: React.FC = () => { |
|
|
|
useStyle(`${key}-${componentName}`); |
|
|
|
return React.createElement('div'); |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
useStyle = (await import(file)).default; |
|
|
|
} |
|
|
|
const Demo: FC = () => { |
|
|
|
useStyle(`${key}-${componentName}`); |
|
|
|
return React.createElement('div'); |
|
|
|
}; |
|
|
|
beforeRender?.(componentName); |
|
|
|
render?.(Demo); |
|
|
|
} |
|
|
|
}; |
|
|
|
beforeRender?.(componentName); |
|
|
|
render?.(Demo); |
|
|
|
}), |
|
|
|
); |
|
|
|