|
@ -1,9 +1,16 @@ |
|
|
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: { |
|
|
|
|
|
key: string; |
|
|
|
|
|
render: (component: FC) => void; |
|
|
|
|
|
beforeRender?: (componentName: string) => void; |
|
|
|
|
|
}) => Promise<void>; |
|
|
|
|
|
|
|
|
export const styleFiles = globSync( |
|
|
export const styleFiles = globSync( |
|
|
path.join( |
|
|
path.join( |
|
|
process.cwd(), |
|
|
process.cwd(), |
|
@ -11,26 +18,29 @@ export const styleFiles = globSync( |
|
|
), |
|
|
), |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
export const generateCssinjs = ({ key, beforeRender, render }: any) => { |
|
|
export const generateCssinjs: GenCssinjs = async ({ key, beforeRender, render }) => { |
|
|
styleFiles.forEach(async (file) => { |
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
|
|
for (const file of styleFiles) { |
|
|
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 { |
|
|
} else { |
|
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
useStyle = (await import(file)).default; |
|
|
useStyle = (await import(file)).default; |
|
|
} |
|
|
} |
|
|
const Component: React.FC = () => { |
|
|
const Demo: FC = () => { |
|
|
useStyle(`${key}-${componentName}`); |
|
|
useStyle(`${key}-${componentName}`); |
|
|
return React.createElement('div'); |
|
|
return React.createElement('div'); |
|
|
}; |
|
|
}; |
|
|
beforeRender?.(componentName); |
|
|
beforeRender?.(componentName); |
|
|
render?.(Component); |
|
|
render?.(Demo); |
|
|
}); |
|
|
} |
|
|
}; |
|
|
}; |
|
|