GeezerVison is showing github.com — feat: add styleImport plugin which handles style import of some funda… · newangle121/lowcode-engine@d0c3c0f
File treeExpand file treeCollapse file tree Open diff view settings tests/fixtures/test-cases demo1/expected/demo-project/src/pages/Test demo2/expected/demo-project/src/pages/Test demo3/expected/demo-project/src/pages/Test demo6-literal-condition/expected/demo-project/src/pages/Test demo9-datasource-engine/expected/demo-project/src/pages/$
demo1/expected/demo-project/src/pages/Test demo2/expected/demo-project/src/pages/Test demo3/expected/demo-project/src/pages/Test demo6-literal-condition/expected/demo-project/src/pages/Test demo9-datasource-engine/expected/demo-project/src/pages/$
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/example-schema.json +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 62 | 62 | "router": "/" | 63 | 63 | }, | 64 | 64 | "props": { | 65 | | - "ref": "outterView", | | 65 | + "ref": "outerView", | 66 | 66 | "autoLoading": true | 67 | 67 | }, | 68 | 68 | "fileName": "test", | 69 | 69 | "state": { | 70 | | - "text": "outter" | | 70 | + "text": "outer" | 71 | 71 | }, | 72 | 72 | "lifeCycles": { | 73 | 73 | "componentDidMount": { | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/example-schema.json5 +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 62 | 62 | router: '/', | 63 | 63 | }, | 64 | 64 | props: { | 65 | | - ref: 'outterView', | | 65 | + ref: 'outerView', | 66 | 66 | autoLoading: true, | 67 | 67 | }, | 68 | 68 | fileName: 'test', | 69 | 69 | state: { | 70 | | - text: 'outter', | | 70 | + text: 'outer', | 71 | 71 | }, | 72 | 72 | lifeCycles: { | 73 | 73 | componentDidMount: { | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/index.ts +16-7Lines changed: 16 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,7 @@ import { createProjectBuilder } from './generator/ProjectBuilder'; | 8 | 8 | import { createModuleBuilder } from './generator/ModuleBuilder'; | 9 | 9 | import { createDiskPublisher } from './publisher/disk'; | 10 | 10 | import { createZipPublisher } from './publisher/zip'; | 11 | | -import createIceJsProjectBuilder, { plugins as reactPlugins } from './solutions/icejs'; | | 11 | +import createIceJsProjectBuilder, { plugins as icejsPlugins } from './solutions/icejs'; | 12 | 12 | import createIce3JsProjectBuilder, { plugins as icejs3Plugins } from './solutions/icejs3'; | 13 | 13 | import createRaxAppProjectBuilder, { plugins as raxPlugins } from './solutions/rax-app'; | 14 | 14 |
| @@ -19,6 +19,7 @@ import { COMMON_CHUNK_NAME, CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from ' | 19 | 19 | // 引入通用插件组 | 20 | 20 | import esmodule from './plugins/common/esmodule'; | 21 | 21 | import requireUtils from './plugins/common/requireUtils'; | | 22 | +import styleImport from './plugins/common/styleImport'; | 22 | 23 |
| 23 | 24 | import css from './plugins/component/style/css'; | 24 | 25 | import constants from './plugins/project/constants'; | @@ -63,12 +64,7 @@ export default { | 63 | 64 | esmodule, | 64 | 65 | esModule: esmodule, | 65 | 66 | requireUtils, | 66 | | - }, | 67 | | - react: { | 68 | | - ...reactPlugins, | 69 | | - }, | 70 | | - rax: { | 71 | | - ...raxPlugins, | | 67 | + styleImport, | 72 | 68 | }, | 73 | 69 | style: { | 74 | 70 | css, | @@ -78,9 +74,22 @@ export default { | 78 | 74 | i18n, | 79 | 75 | utils, | 80 | 76 | }, | | 77 | + icejs: { | | 78 | + ...icejsPlugins, | | 79 | + }, | 81 | 80 | icejs3: { | 82 | 81 | ...icejs3Plugins, | 83 | 82 | }, | | 83 | + rax: { | | 84 | + ...raxPlugins, | | 85 | + }, | | 86 | + | | 87 | + /** | | 88 | + * @deprecated please use icejs | | 89 | + */ | | 90 | + react: { | | 91 | + ...icejsPlugins, | | 92 | + }, | 84 | 93 | }, | 85 | 94 | postprocessor: { | 86 | 95 | prettier, | |
Collapse file Copy file name to clipboard +54Lines changed: 54 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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; |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/solutions/icejs.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { IProjectBuilder, IProjectBuilderOptions } from '../types'; | 3 | 3 | import { createProjectBuilder } from '../generator/ProjectBuilder'; | 4 | 4 |
| 5 | 5 | import esmodule from '../plugins/common/esmodule'; | | 6 | +import styleImport from '../plugins/common/styleImport'; | 6 | 7 | import containerClass from '../plugins/component/react/containerClass'; | 7 | 8 | import containerInitState from '../plugins/component/react/containerInitState'; | 8 | 9 | import containerInjectContext from '../plugins/component/react/containerInjectContext'; | @@ -38,6 +39,7 @@ export default function createIceJsProjectBuilder( | 38 | 39 | esmodule({ | 39 | 40 | fileType: 'jsx', | 40 | 41 | }), | | 42 | + styleImport(), | 41 | 43 | containerClass(), | 42 | 44 | containerInjectContext(), | 43 | 45 | containerInjectUtils(), | @@ -61,6 +63,7 @@ export default function createIceJsProjectBuilder( | 61 | 63 | esmodule({ | 62 | 64 | fileType: 'jsx', | 63 | 65 | }), | | 66 | + styleImport(), | 64 | 67 | containerClass(), | 65 | 68 | containerInjectContext(), | 66 | 69 | containerInjectUtils(), | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/src/solutions/icejs3.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { IProjectBuilder, IProjectBuilderOptions } from '../types'; | 3 | 3 | import { createProjectBuilder } from '../generator/ProjectBuilder'; | 4 | 4 |
| 5 | 5 | import esmodule from '../plugins/common/esmodule'; | | 6 | +import styleImport from '../plugins/common/styleImport'; | 6 | 7 | import containerClass from '../plugins/component/react/containerClass'; | 7 | 8 | import containerInitState from '../plugins/component/react/containerInitState'; | 8 | 9 | import containerInjectContext from '../plugins/component/react/containerInjectContext'; | @@ -38,6 +39,7 @@ export default function createIceJsProjectBuilder( | 38 | 39 | esmodule({ | 39 | 40 | fileType: 'jsx', | 40 | 41 | }), | | 42 | + styleImport(), | 41 | 43 | containerClass(), | 42 | 44 | containerInjectContext(), | 43 | 45 | containerInjectUtils(), | @@ -61,6 +63,7 @@ export default function createIceJsProjectBuilder( | 61 | 63 | esmodule({ | 62 | 64 | fileType: 'jsx', | 63 | 65 | }), | | 66 | + styleImport(), | 64 | 67 | containerClass(), | 65 | 68 | containerInjectContext(), | 66 | 69 | containerInjectUtils(), | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/tests/fixtures/test-cases/icejs3-app/demo1/expected/demo-project/src/pages/Test/index.jsx +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,16 @@ import { createFetchHandler as __$$createFetchRequestHandler } from '@alilc/lowc | 10 | 10 |
| 11 | 11 | import { create as __$$createDataSourceEngine } from '@alilc/lowcode-datasource-engine/runtime'; | 12 | 12 |
| | 13 | +import '@alifd/next/lib/form/style'; | | 14 | + | | 15 | +import '@alifd/next/lib/input/style'; | | 16 | + | | 17 | +import '@alifd/next/lib/number-picker/style'; | | 18 | + | | 19 | +import '@alifd/next/lib/select/style'; | | 20 | + | | 21 | +import '@alifd/next/lib/button/style'; | | 22 | + | 13 | 23 | import utils, { RefsManager } from '../../utils'; | 14 | 24 |
| 15 | 25 | import * as __$$i18n from '../../i18n'; | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/tests/fixtures/test-cases/icejs3-app/demo2/expected/demo-project/src/pages/Test/index.jsx +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,16 @@ import React from 'react'; | 4 | 4 |
| 5 | 5 | import { Form, Input, NumberPicker, Select, Button } from '@alifd/next'; | 6 | 6 |
| | 7 | +import '@alifd/next/lib/form/style'; | | 8 | + | | 9 | +import '@alifd/next/lib/input/style'; | | 10 | + | | 11 | +import '@alifd/next/lib/number-picker/style'; | | 12 | + | | 13 | +import '@alifd/next/lib/select/style'; | | 14 | + | | 15 | +import '@alifd/next/lib/button/style'; | | 16 | + | 7 | 17 | import utils, { RefsManager } from '../../utils'; | 8 | 18 |
| 9 | 19 | import * as __$$i18n from '../../i18n'; | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/tests/fixtures/test-cases/icejs3-app/demo3/expected/demo-project/src/pages/Test/index.jsx +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,20 @@ import Super, { | 13 | 13 |
| 14 | 14 | import SuperOther from '@alifd/next'; | 15 | 15 |
| | 16 | +import '@alifd/next/lib/super/style'; | | 17 | + | | 18 | +import '@alifd/next/lib/button/style'; | | 19 | + | | 20 | +import '@alifd/next/lib/input/style'; | | 21 | + | | 22 | +import '@alifd/next/lib/form/style'; | | 23 | + | | 24 | +import '@alifd/next/lib/number-picker/style'; | | 25 | + | | 26 | +import '@alifd/next/lib/select/style'; | | 27 | + | | 28 | +import '@alifd/next/lib/search-table/style'; | | 29 | + | 16 | 30 | import utils from '../../utils'; | 17 | 31 |
| 18 | 32 | import * as __$$i18n from '../../i18n'; | |
Collapse file Copy file name to clipboardExpand all lines: modules/code-generator/tests/fixtures/test-cases/icejs3-app/demo6-literal-condition/expected/demo-project/src/pages/Test/index.jsx +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,16 @@ import { createFetchHandler as __$$createFetchRequestHandler } from '@alilc/lowc | 10 | 10 |
| 11 | 11 | import { create as __$$createDataSourceEngine } from '@alilc/lowcode-datasource-engine/runtime'; | 12 | 12 |
| | 13 | +import '@alifd/next/lib/form/style'; | | 14 | + | | 15 | +import '@alifd/next/lib/input/style'; | | 16 | + | | 17 | +import '@alifd/next/lib/number-picker/style'; | | 18 | + | | 19 | +import '@alifd/next/lib/select/style'; | | 20 | + | | 21 | +import '@alifd/next/lib/button/style'; | | 22 | + | 13 | 23 | import utils, { RefsManager } from '../../utils'; | 14 | 24 |
| 15 | 25 | import * as __$$i18n from '../../i18n'; | |
|