mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 23:21:12 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
95 lines
2.3 KiB
TypeScript
95 lines
2.3 KiB
TypeScript
import { readFile } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
type IconData = {
|
|
width?: number
|
|
height?: number
|
|
}
|
|
|
|
type IconCollection = {
|
|
icons: Record<string, IconData>
|
|
width?: number
|
|
height?: number
|
|
}
|
|
|
|
type DimensionRule = {
|
|
collection: 'custom-vender'
|
|
icons: string[]
|
|
width: number
|
|
height: number
|
|
}
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const packageDir = path.resolve(__dirname, '..')
|
|
|
|
const dimensionRules: DimensionRule[] = [
|
|
{
|
|
collection: 'custom-vender',
|
|
icons: [
|
|
'main-nav-home',
|
|
'main-nav-home-active',
|
|
'main-nav-integrations',
|
|
'main-nav-integrations-active',
|
|
'main-nav-knowledge',
|
|
'main-nav-knowledge-active',
|
|
'main-nav-marketplace',
|
|
'main-nav-marketplace-active',
|
|
'main-nav-studio',
|
|
'main-nav-studio-active',
|
|
],
|
|
width: 20,
|
|
height: 20,
|
|
},
|
|
]
|
|
|
|
const readCollection = async (collection: DimensionRule['collection']): Promise<IconCollection> => {
|
|
return JSON.parse(
|
|
await readFile(path.resolve(packageDir, collection, 'icons.json'), 'utf8'),
|
|
) as IconCollection
|
|
}
|
|
|
|
const main = async () => {
|
|
const collections = new Map<string, IconCollection>()
|
|
const failures: string[] = []
|
|
|
|
for (const rule of dimensionRules) {
|
|
if (!collections.has(rule.collection))
|
|
collections.set(rule.collection, await readCollection(rule.collection))
|
|
|
|
const collection = collections.get(rule.collection)!
|
|
|
|
for (const iconName of rule.icons) {
|
|
const icon = collection.icons[iconName]
|
|
const width = icon?.width ?? collection.width ?? 16
|
|
const height = icon?.height ?? collection.height ?? 16
|
|
|
|
if (!icon) {
|
|
failures.push(`${rule.collection}:${iconName} is missing`)
|
|
continue
|
|
}
|
|
|
|
if (width !== rule.width || height !== rule.height) {
|
|
failures.push(
|
|
`${rule.collection}:${iconName} expected ${rule.width}x${rule.height}, got ${width}x${height}`,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (failures.length) {
|
|
console.error('Icon dimension check failed:')
|
|
for (const failure of failures)
|
|
console.error(`- ${failure}`)
|
|
process.exitCode = 1
|
|
return
|
|
}
|
|
|
|
console.log('Icon dimension check passed.')
|
|
}
|
|
|
|
main().catch((error: unknown) => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|