From af5ac46e7afe693be6e2153e5807e63585cae634 Mon Sep 17 00:00:00 2001 From: codecalm Date: Sun, 14 Dec 2025 20:10:28 +0100 Subject: [PATCH] Enhance build-outline.mjs with progress tracking and parallel file copying for improved performance during SVG icon processing. Update tsconfig.json to include source files for better type checking. --- packages/icons-preact/tsconfig.json | 6 ++- .../icons-webfont/.build/build-outline.mjs | 45 +++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/packages/icons-preact/tsconfig.json b/packages/icons-preact/tsconfig.json index b59f7ee3a..7303b1a38 100644 --- a/packages/icons-preact/tsconfig.json +++ b/packages/icons-preact/tsconfig.json @@ -14,12 +14,14 @@ "skipLibCheck": true, "resolveJsonModule": true, "allowSyntheticDefaultImports": true, + "allowImportingTsExtensions": true, "downlevelIteration": true, "sourceMap": true, "outDir": "./dist", "jsx": "react-jsx", "jsxImportSource": "preact", - "types": ["@testing-library/jest-dom"], + "types": ["@testing-library/jest-dom"] }, - "exclude": ["**/node_modules"] + "exclude": ["**/node_modules"], + "include": ["src"] } diff --git a/packages/icons-webfont/.build/build-outline.mjs b/packages/icons-webfont/.build/build-outline.mjs index dee957712..21f42e1cd 100644 --- a/packages/icons-webfont/.build/build-outline.mjs +++ b/packages/icons-webfont/.build/build-outline.mjs @@ -57,6 +57,19 @@ const buildOutline = async () => { let processed = 0 let cached = 0 const total = iconsToProcess.length + const startTime = Date.now() + + // Progress update interval (every 50 icons to avoid console spam) + let lastProgress = 0 + const showProgress = () => { + const done = processed + cached + if (done - lastProgress >= 50 || done === total) { + const percent = Math.round((done / total) * 100) + const elapsed = ((Date.now() - startTime) / 1000).toFixed(1) + process.stdout.write(`\r[${strokeName}/${type}] ${done}/${total} (${percent}%) - ${elapsed}s`.padEnd(60)) + lastProgress = done + } + } await parallelLimit(iconsToProcess, async ({ name, content, unicode }) => { const filename = `u${unicode.toUpperCase()}-${name}.svg` @@ -73,6 +86,7 @@ const buildOutline = async () => { if (cachedHash && crypto.createHash('sha1').update(contentWithoutHash).digest("hex") === cachedHash) { cached++ + showProgress() return } } catch (e) { @@ -109,12 +123,14 @@ const buildOutline = async () => { fs.writeFileSync(filePath, finalContent + hashString, 'utf-8') processed++ + showProgress() } catch (error) { console.error(`\nError processing ${strokeName}/${type}/${name}:`, error.message) } }, 64) // 64 concurrent tasks - console.log(`Stroke ${strokeName}/${type}: ${processed} processed, ${cached} cached`) + const totalTime = ((Date.now() - startTime) / 1000).toFixed(1) + console.log(`\n[${strokeName}/${type}] Done: ${processed} processed, ${cached} cached in ${totalTime}s`) } // Remove old files @@ -128,26 +144,29 @@ const buildOutline = async () => { }) } - // Copy icons to all directory + // Copy icons to all directory (parallel) fs.mkdirSync(resolve(DIR, `icons-outlined/${strokeName}/all`), { recursive: true }) + const copyTasks = [] for (const [type, typeIcons] of Object.entries(icons)) { for (const { name, unicode } of typeIcons) { if (!unicode) continue - const iconName = `u${unicode.toUpperCase()}-${name}` - const srcPath = resolve(DIR, `icons-outlined/${strokeName}/${type}/${iconName}.svg`) - - try { - fs.copyFileSync( - srcPath, - resolve(DIR, `icons-outlined/${strokeName}/all/${iconName}${type !== 'outline' ? `-${type}` : ''}.svg`) - ) - } catch (e) { - // Source file doesn't exist, skip - } + copyTasks.push({ type, name, unicode }) } } + await parallelLimit(copyTasks, async ({ type, name, unicode }) => { + const iconName = `u${unicode.toUpperCase()}-${name}` + const srcPath = resolve(DIR, `icons-outlined/${strokeName}/${type}/${iconName}.svg`) + const destPath = resolve(DIR, `icons-outlined/${strokeName}/all/${iconName}${type !== 'outline' ? `-${type}` : ''}.svg`) + + try { + fs.copyFileSync(srcPath, destPath) + } catch (e) { + // Source file doesn't exist, skip + } + }, 128) // High concurrency for simple I/O + console.log(`Stroke ${strokeName}: completed`) }))