|
| 1 | +import changeCase from 'change-case'; |
| 2 | +import { |
| 3 | + FileType, |
| 4 | + BuilderComponentPluginFactory, |
| 5 | + BuilderComponentPlugin, |
| 6 | + ICodeStruct, |
| 7 | + IWithDependency, |
| 8 | + ChunkType, |
| 9 | +} from '../../types'; |
| 10 | + |
| 11 | +import { COMMON_CHUNK_NAME } from '../../const/generator'; |
| 12 | + |
| 13 | +const pluginFactory: BuilderComponentPluginFactory<unknown> = () => { |
| 14 | + const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { |
| 15 | + const next: ICodeStruct = { |
| 16 | + ...pre, |
| 17 | + }; |
| 18 | + |
| 19 | + const ir = next.ir as IWithDependency; |
| 20 | + const { chunks } = next; |
| 21 | + |
| 22 | + if (ir && ir.deps && ir.deps.length > 0) { |
| 23 | + let lowcodeMaterialsStyleAdded = false; |
| 24 | + let nextStyleAddedMap: Record<string, boolean> = {}; |
| 25 | + ir.deps.forEach((dep: any) => { |
| 26 | + if (dep.package === '@alifd/next' && !nextStyleAddedMap[dep.exportName]) { |
| 27 | + chunks.push({ |
| 28 | + type: ChunkType.STRING, |
| 29 | + fileType: FileType.JSX, |
| 30 | + name: COMMON_CHUNK_NAME.InternalDepsImport, |
| 31 | + content: `import '@alifd/next/lib/${changeCase.paramCase(dep.exportName)}/style';`, |
| 32 | + linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport], |
| 33 | + }); |
| 34 | + nextStyleAddedMap[dep.exportName] = true; |
| 35 | + } else if (dep.package === '@alilc/lowcode-materials' && !lowcodeMaterialsStyleAdded) { |
| 36 | + chunks.push({ |
| 37 | + type: ChunkType.STRING, |
| 38 | + fileType: FileType.JSX, |
| 39 | + name: COMMON_CHUNK_NAME.InternalDepsImport, |
| 40 | + content: 'import \'@alilc/lowcode-materials/lib/style\';', |
| 41 | + linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport], |
| 42 | + }); |
| 43 | + lowcodeMaterialsStyleAdded = true; |
| 44 | + } |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + return next; |
| 49 | + }; |
| 50 | + |
| 51 | + return plugin; |
| 52 | +}; |
| 53 | + |
| 54 | +export default pluginFactory; |
0 commit comments