From 39d23eec7a5023ccae4f3b88f450d0716442db10 Mon Sep 17 00:00:00 2001 From: "zude.hzd" Date: Wed, 12 Aug 2020 14:48:23 +0800 Subject: [PATCH 1/4] icon setter update --- packages/demo/public/assets.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/demo/public/assets.json b/packages/demo/public/assets.json index 70ac9ab9a..1ac9cc3e1 100644 --- a/packages/demo/public/assets.json +++ b/packages/demo/public/assets.json @@ -5876,7 +5876,7 @@ { "name": "hint", "title": "Icon 水印", - "propType": "string", + "propType": "icon", "description": "水印 (Icon的type类型,和hasClear占用一个地方)" }, { @@ -7235,7 +7235,7 @@ }, { "name": "iconType", - "propType": "string", + "propType": "icon", "description": "显示的图标类型,会覆盖内部设置的IconType" }, { From db144a9c6ba2fcccc6243fbc5aed244510374f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E5=B8=8C?= Date: Wed, 12 Aug 2020 23:55:08 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20group=20chunks=20by?= =?UTF-8?q?=20filetype=20family?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/code-generator/src/const/file.ts | 3 + .../src/generator/ChunkBuilder.ts | 88 ++++++++++++++----- .../src/generator/ModuleBuilder.ts | 33 +++---- 3 files changed, 79 insertions(+), 45 deletions(-) create mode 100644 packages/code-generator/src/const/file.ts diff --git a/packages/code-generator/src/const/file.ts b/packages/code-generator/src/const/file.ts new file mode 100644 index 000000000..d29ea43a3 --- /dev/null +++ b/packages/code-generator/src/const/file.ts @@ -0,0 +1,3 @@ +import { FileType } from '../types/core'; + +export const FILE_TYPE_FAMILY = [[FileType.TSX, FileType.TS, FileType.JSX, FileType.JS]]; diff --git a/packages/code-generator/src/generator/ChunkBuilder.ts b/packages/code-generator/src/generator/ChunkBuilder.ts index 18ff63991..67ecd504e 100644 --- a/packages/code-generator/src/generator/ChunkBuilder.ts +++ b/packages/code-generator/src/generator/ChunkBuilder.ts @@ -1,28 +1,72 @@ -import { - BuilderComponentPlugin, - IChunkBuilder, - ICodeChunk, - ICodeStruct, -} from '../types'; +import { BuilderComponentPlugin, IChunkBuilder, ICodeChunk, ICodeStruct, FileType } from '../types'; import { COMMON_SUB_MODULE_NAME } from '../const/generator'; +import { FILE_TYPE_FAMILY } from '../const/file'; + +type ChunkGroupInfo = { + chunk: ICodeChunk; + familyIdx?: number; +}; + +function whichFamily(type: FileType): [number, FileType[]] | undefined { + const idx = FILE_TYPE_FAMILY.findIndex((family) => family.indexOf(type) >= 0); + if (idx < 0) { + return undefined; + } + return [idx, FILE_TYPE_FAMILY[idx]]; +} export const groupChunks = (chunks: ICodeChunk[]): ICodeChunk[][] => { - const col = chunks.reduce( - (chunksSet: Record, chunk) => { - const fileKey = `${chunk.subModule || COMMON_SUB_MODULE_NAME}.${ - chunk.fileType - }`; - if (!chunksSet[fileKey]) { - chunksSet[fileKey] = []; + const tmp: Record> = {}; + const col = chunks.reduce((chunksSet: Record, chunk) => { + const fileKey = chunk.subModule || COMMON_SUB_MODULE_NAME; + if (!chunksSet[fileKey]) { + chunksSet[fileKey] = []; + } + const res = whichFamily(chunk.fileType as FileType); + const info: ChunkGroupInfo = { + chunk, + }; + if (res) { + const [familyIdx, family] = res; + const rank = family.indexOf(chunk.fileType as FileType); + if (tmp[fileKey]) { + if (tmp[fileKey][familyIdx] !== undefined) { + if (tmp[fileKey][familyIdx] > rank) { + tmp[fileKey][familyIdx] = rank; + } + } else { + tmp[fileKey][familyIdx] = rank; + } + } else { + tmp[fileKey] = {}; + tmp[fileKey][familyIdx] = rank; } - chunksSet[fileKey].push(chunk); - return chunksSet; - }, - {}, - ); + info.familyIdx = familyIdx; + } - return Object.keys(col).map(key => col[key]); + chunksSet[fileKey].push(info); + return chunksSet; + }, {}); + + const result: ICodeChunk[][] = []; + Object.keys(col).forEach((key) => { + const byType: Record = {}; + col[key].forEach((info) => { + let t: string = info.chunk.fileType; + if (info.familyIdx !== undefined) { + t = FILE_TYPE_FAMILY[info.familyIdx][tmp[key][info.familyIdx]]; + info.chunk.fileType = t; + } + if (!byType[t]) { + byType[t] = []; + } + byType[t].push(info.chunk); + }); + result.push(...Object.keys(byType).map((t) => byType[t])); + }); + + return result; }; /** @@ -39,7 +83,7 @@ export default class ChunkBuilder implements IChunkBuilder { this.plugins = plugins; } - public async run( + async run( ir: unknown, initialStructure: ICodeStruct = { ir, @@ -64,11 +108,11 @@ export default class ChunkBuilder implements IChunkBuilder { }; } - public getPlugins() { + getPlugins() { return this.plugins; } - public addPlugin(plugin: BuilderComponentPlugin) { + addPlugin(plugin: BuilderComponentPlugin) { this.plugins.push(plugin); } } diff --git a/packages/code-generator/src/generator/ModuleBuilder.ts b/packages/code-generator/src/generator/ModuleBuilder.ts index 991ffedec..063434cb4 100644 --- a/packages/code-generator/src/generator/ModuleBuilder.ts +++ b/packages/code-generator/src/generator/ModuleBuilder.ts @@ -37,29 +37,23 @@ export function createModuleBuilder( const generateModule = async (input: unknown): Promise => { const moduleMainName = options.mainFileName || COMMON_SUB_MODULE_NAME; if (chunkGenerator.getPlugins().length <= 0) { - throw new CodeGeneratorError( - 'No plugins found. Component generation cannot work without any plugins!', - ); + throw new CodeGeneratorError('No plugins found. Component generation cannot work without any plugins!'); } let files: IResultFile[] = []; const { chunks } = await chunkGenerator.run(input); - chunks.forEach(fileChunkList => { + chunks.forEach((fileChunkList) => { const content = linker.link(fileChunkList); - const file = new ResultFile( - fileChunkList[0].subModule || moduleMainName, - fileChunkList[0].fileType, - content, - ); + const file = new ResultFile(fileChunkList[0].subModule || moduleMainName, fileChunkList[0].fileType, content); files.push(file); }); if (options.postProcessors.length > 0) { - files = files.map(file => { + files = files.map((file) => { let content = file.content; const type = file.ext; - options.postProcessors.forEach(processer => { + options.postProcessors.forEach((processer) => { content = processer(content, type); }); @@ -81,25 +75,18 @@ export function createModuleBuilder( const { files } = await generateModule(containerInfo); const dir = new ResultDir(containerInfo.moduleName); - files.forEach(file => dir.addFile(file)); + files.forEach((file) => dir.addFile(file)); return dir; - } + }; - const linkCodeChunks = ( - chunks: Record, - fileName: string, - ) => { + const linkCodeChunks = (chunks: Record, fileName: string) => { const files: IResultFile[] = []; - Object.keys(chunks).forEach(fileKey => { + Object.keys(chunks).forEach((fileKey) => { const fileChunkList = chunks[fileKey]; const content = linker.link(fileChunkList); - const file = new ResultFile( - fileChunkList[0].subModule || fileName, - fileChunkList[0].fileType, - content, - ); + const file = new ResultFile(fileChunkList[0].subModule || fileName, fileChunkList[0].fileType, content); files.push(file); }); From 8f5391063dc4dd688d617521e0963304bab7a21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E5=B8=8C?= Date: Thu, 13 Aug 2020 00:28:51 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20loop=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/code-generator/src/utils/nodeToJSX.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/code-generator/src/utils/nodeToJSX.ts b/packages/code-generator/src/utils/nodeToJSX.ts index 018eac1d4..39791d7cd 100644 --- a/packages/code-generator/src/utils/nodeToJSX.ts +++ b/packages/code-generator/src/utils/nodeToJSX.ts @@ -166,15 +166,13 @@ export function generateBasicNode( export function generateReactCtrlLine(ctx: INodeGeneratorContext, nodeItem: IComponentNodeItem): CodePiece[] { const pieces: CodePiece[] = []; - if (nodeItem.loop && nodeItem.loopArgs) { - let loopDataExp; - if (isJsExpression(nodeItem.loop)) { - loopDataExp = `(${generateExpression(nodeItem.loop)})`; - } else { - loopDataExp = JSON.stringify(nodeItem.loop); - } + if (nodeItem.loop) { + const args: [string, string] = nodeItem.loopArgs || ['item', 'index']; + const loopData = generateCompositeType(nodeItem.loop, { + nodeGenerator: ctx.generator, + }); pieces.unshift({ - value: `${loopDataExp}.map((${nodeItem.loopArgs[0]}, ${nodeItem.loopArgs[1]}) => (`, + value: `(${loopData}).map((${args[0]}, ${args[1]}) => (`, type: PIECE_TYPE.BEFORE, }); pieces.push({ @@ -198,7 +196,7 @@ export function generateReactCtrlLine(ctx: INodeGeneratorContext, nodeItem: ICom }); } - if (nodeItem.condition || (nodeItem.loop && nodeItem.loopArgs)) { + if (nodeItem.condition || nodeItem.loop) { pieces.unshift({ value: '{', type: PIECE_TYPE.BEFORE, From b3fc47c18577256d5707462c4a006bca78bd8608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E5=B8=8C?= Date: Thu, 13 Aug 2020 11:00:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=F0=9F=A4=96=20version=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/code-generator/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/code-generator/package.json b/packages/code-generator/package.json index bfe83ccf4..e85b50574 100644 --- a/packages/code-generator/package.json +++ b/packages/code-generator/package.json @@ -1,6 +1,6 @@ { "name": "@ali/lowcode-code-generator", - "version": "0.8.9", + "version": "0.8.12", "description": "出码引擎 for LowCode Engine", "main": "lib/index.js", "files": [