Merge branch 'main' into jzh

This commit is contained in:
JzoNg 2026-04-20 16:42:16 +08:00
commit a3242f0634
6 changed files with 550 additions and 477 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -23,9 +23,10 @@
"./custom-vender/chars.json": "./custom-vender/chars.json"
},
"scripts": {
"generate": "node ./scripts/generate-collections.mjs"
"generate": "tsx ./scripts/generate-collections.ts"
},
"devDependencies": {
"iconify-import-svg": "catalog:"
"iconify-import-svg": "catalog:",
"tsx": "catalog:"
}
}

View File

@ -3,45 +3,62 @@ import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { importSvgCollections } from 'iconify-import-svg'
type IconData = {
body: string
left?: number
top?: number
width?: number
height?: number
rotate?: 0 | 1 | 2 | 3
hFlip?: boolean
vFlip?: boolean
}
type AliasData = Omit<IconData, 'body'> & {
parent: string
}
type ImportedCollection = {
icons?: Record<string, IconData>
aliases?: Record<string, AliasData>
lastModified?: number
}
type ImportedCollections = Record<string, ImportedCollection>
type CollectionInfo = {
prefix: string
name: string
total: number
version: string
author: {
name: string
url: string
}
license: {
title: string
spdx: string
url: string
}
samples: string[]
palette: false
}
type PackageJson = {
version: string
}
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const packageDir = path.resolve(__dirname, '..')
const parseColorOptions = {
fallback: () => 'currentColor',
}
const svgOptimizeConfig = {
cleanupSVG: true,
deOptimisePaths: true,
runSVGO: true,
parseColors: parseColorOptions,
}
const customPublicCollections = importSvgCollections({
source: path.resolve(packageDir, 'assets/public'),
prefix: 'custom-public',
ignoreImportErrors: true,
...svgOptimizeConfig,
})
const customVenderCollections = importSvgCollections({
source: path.resolve(packageDir, 'assets/vender'),
prefix: 'custom-vender',
ignoreImportErrors: true,
...svgOptimizeConfig,
})
const packageJson = JSON.parse(await readFile(path.resolve(packageDir, 'package.json'), 'utf8'))
const flattenCollections = (collections, prefix) => {
const icons = {}
const aliases = {}
const flattenCollections = (collections: ImportedCollections, prefix: string) => {
const icons: Record<string, IconData> = {}
const aliases: Record<string, AliasData> = {}
let lastModified = 0
for (const [collectionKey, collection] of Object.entries(collections)) {
const segment = collectionKey.slice(prefix.length + 1)
const namePrefix = segment
? `${segment}-`
: ''
const namePrefix = segment ? `${segment}-` : ''
for (const [iconName, iconData] of Object.entries(collection.icons ?? {}))
icons[`${namePrefix}${iconName}`] = iconData
@ -61,11 +78,38 @@ const flattenCollections = (collections, prefix) => {
}
}
const createCollectionInfo = (prefix, name, icons) => ({
const customPublicCollections = importSvgCollections({
source: path.resolve(packageDir, 'assets/public'),
prefix: 'custom-public',
ignoreImportErrors: true,
cleanupSVG: true,
deOptimisePaths: true,
runSVGO: true,
parseColors: false,
}) as ImportedCollections
const customVenderCollections = importSvgCollections({
source: path.resolve(packageDir, 'assets/vender'),
prefix: 'custom-vender',
ignoreImportErrors: true,
cleanupSVG: true,
deOptimisePaths: true,
runSVGO: false,
parseColors: {
callback: () => 'currentColor',
},
}) as ImportedCollections
const createCollectionInfo = (
prefix: string,
name: string,
icons: Record<string, IconData>,
version: string,
): CollectionInfo => ({
prefix,
name,
total: Object.keys(icons).length,
version: packageJson.version,
version,
author: {
name: 'LangGenius, Inc.',
url: 'https://github.com/langgenius/dify',
@ -79,7 +123,7 @@ const createCollectionInfo = (prefix, name, icons) => ({
palette: false,
})
const createIndexMjs = () => `import icons from './icons.json' with { type: 'json' }
const createIndexMjs = (): string => `import icons from './icons.json' with { type: 'json' }
import info from './info.json' with { type: 'json' }
import metadata from './metadata.json' with { type: 'json' }
import chars from './chars.json' with { type: 'json' }
@ -87,7 +131,7 @@ import chars from './chars.json' with { type: 'json' }
export { icons, info, metadata, chars }
`
const createIndexJs = () => `'use strict'
const createIndexJs = (): string => `'use strict'
const icons = require('./icons.json')
const info = require('./info.json')
@ -97,7 +141,7 @@ const chars = require('./chars.json')
module.exports = { icons, info, metadata, chars }
`
const createIndexTypes = () => `export interface IconifyJSON {
const createIndexTypes = (): string => `export interface IconifyJSON {
prefix: string
icons: Record<string, IconifyIcon>
aliases?: Record<string, IconifyAlias>
@ -153,9 +197,14 @@ export declare const metadata: IconifyMetaData
export declare const chars: IconifyChars
`
const writeCollectionPackage = async (directoryName, collection, name) => {
const writeCollectionPackage = async (
directoryName: string,
collection: ReturnType<typeof flattenCollections>,
name: string,
version: string,
): Promise<void> => {
const targetDir = path.resolve(packageDir, directoryName)
const info = createCollectionInfo(collection.prefix, name, collection.icons)
const info = createCollectionInfo(collection.prefix, name, collection.icons, version)
await mkdir(targetDir, { recursive: true })
await writeFile(path.resolve(targetDir, 'icons.json'), `${JSON.stringify(collection, null, 2)}\n`)
@ -167,12 +216,32 @@ const writeCollectionPackage = async (directoryName, collection, name) => {
await writeFile(path.resolve(targetDir, 'index.d.ts'), `${createIndexTypes()}\n`)
}
const mergedCustomPublicCollection = flattenCollections(customPublicCollections, 'custom-public')
const mergedCustomVenderCollection = flattenCollections(customVenderCollections, 'custom-vender')
async function main(): Promise<void> {
const packageJson = JSON.parse(
await readFile(path.resolve(packageDir, 'package.json'), 'utf8'),
) as PackageJson
const customPublicCollection = flattenCollections(customPublicCollections, 'custom-public')
const customVenderCollection = flattenCollections(customVenderCollections, 'custom-vender')
await rm(path.resolve(packageDir, 'src'), { recursive: true, force: true })
await rm(path.resolve(packageDir, 'custom-public'), { recursive: true, force: true })
await rm(path.resolve(packageDir, 'custom-vender'), { recursive: true, force: true })
await rm(path.resolve(packageDir, 'src'), { recursive: true, force: true })
await rm(path.resolve(packageDir, 'custom-public'), { recursive: true, force: true })
await rm(path.resolve(packageDir, 'custom-vender'), { recursive: true, force: true })
await writeCollectionPackage('custom-public', mergedCustomPublicCollection, 'Dify Custom Public')
await writeCollectionPackage('custom-vender', mergedCustomVenderCollection, 'Dify Custom Vender')
await writeCollectionPackage(
'custom-public',
customPublicCollection,
'Dify Custom Public',
packageJson.version,
)
await writeCollectionPackage(
'custom-vender',
customVenderCollection,
'Dify Custom Vender',
packageJson.version,
)
}
main().catch((error: unknown) => {
console.error(error)
process.exitCode = 1
})

15
pnpm-lock.yaml generated
View File

@ -352,8 +352,8 @@ catalogs:
specifier: 1.2.1
version: 1.2.1
iconify-import-svg:
specifier: 0.1.2
version: 0.1.2
specifier: 0.2.0
version: 0.2.0
immer:
specifier: 11.1.4
version: 11.1.4
@ -718,7 +718,10 @@ importers:
devDependencies:
iconify-import-svg:
specifier: 'catalog:'
version: 0.1.2
version: 0.2.0
tsx:
specifier: 'catalog:'
version: 4.21.0
packages/migrate-no-unchecked-indexed-access:
dependencies:
@ -5932,8 +5935,8 @@ packages:
typescript:
optional: true
iconify-import-svg@0.1.2:
resolution: {integrity: sha512-8dwxdGK1a7oPDQhLQOPTbx51tpkxYB6HZvf4fxWz2QVYqEtgop0FWE7OXQ+4zqnrTVUpMIGnOsvqIHtPBK9Isw==}
iconify-import-svg@0.2.0:
resolution: {integrity: sha512-NFuDyiYRKLSNvbiUnR4627DF4QjQR+bC+n+Nh0lcMnKXv9MCwzikOcdzqITU1yFfRacc6S6PeElc2H5l+35T1Q==}
iconv-lite@0.6.3:
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
@ -13329,7 +13332,7 @@ snapshots:
optionalDependencies:
typescript: 6.0.2
iconify-import-svg@0.1.2:
iconify-import-svg@0.2.0:
dependencies:
'@iconify/tools': 4.2.0
'@iconify/types': 2.0.0

View File

@ -163,7 +163,7 @@ catalog:
html-to-image: 1.11.13
i18next: 26.0.4
i18next-resources-to-backend: 1.2.1
iconify-import-svg: 0.1.2
iconify-import-svg: 0.2.0
immer: 11.1.4
jotai: 2.19.1
js-audio-recorder: 1.0.7