feat: add miniapp reference assets and primitives
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { createHash } from 'node:crypto'
|
||||
|
||||
const root = resolve(import.meta.dirname, '..')
|
||||
const assets = [
|
||||
@@ -16,10 +17,55 @@ const assets = [
|
||||
'miniapp/assets/covers/station-default.jpg',
|
||||
]
|
||||
|
||||
const miniappHeroAssets = [
|
||||
'miniapp/assets/brand/home-hero-v2.jpg',
|
||||
'miniapp/assets/service/matchmaker-hero.jpg',
|
||||
'miniapp/assets/service/counseling-hero.jpg',
|
||||
'miniapp/assets/service/premarital-hero.jpg',
|
||||
'miniapp/assets/service/anti-fraud-hero.jpg',
|
||||
'miniapp/assets/service/station-hero.jpg',
|
||||
]
|
||||
|
||||
const homeIconAssets = [
|
||||
'find-object.png',
|
||||
'matchmaker.png',
|
||||
'activity.png',
|
||||
'counseling.png',
|
||||
'classroom.png',
|
||||
'premarital.png',
|
||||
'anti-fraud.png',
|
||||
'service-station.png',
|
||||
].map((name) => `miniapp/assets/icons/home/${name}`)
|
||||
|
||||
const uiIconAssets = [
|
||||
'back.png',
|
||||
'chevron-right.png',
|
||||
'warning.png',
|
||||
'empty.png',
|
||||
'loading.png',
|
||||
'search.png',
|
||||
].map((name) => `miniapp/assets/icons/ui/${name}`)
|
||||
|
||||
for (const file of assets) {
|
||||
const path = resolve(root, file)
|
||||
assert.ok(existsSync(path), `缺少品牌资产 ${file}`)
|
||||
assert.ok(readFileSync(path).length > 4096, `品牌资产为空或过小 ${file}`)
|
||||
}
|
||||
|
||||
for (const file of miniappHeroAssets) {
|
||||
const path = resolve(root, file)
|
||||
assert.ok(existsSync(path), `缺少小程序 Hero 素材 ${file}`)
|
||||
assert.ok(readFileSync(path).length > 16 * 1024, `小程序 Hero 素材为空或过小 ${file}`)
|
||||
}
|
||||
|
||||
const homeIconHashes = new Set()
|
||||
for (const file of [...homeIconAssets, ...uiIconAssets]) {
|
||||
const path = resolve(root, file)
|
||||
assert.ok(existsSync(path), `缺少小程序图标 ${file}`)
|
||||
const bytes = readFileSync(path)
|
||||
assert.ok(bytes.length > 256, `小程序图标为空或过小 ${file}`)
|
||||
if (homeIconAssets.includes(file)) homeIconHashes.add(createHash('sha256').update(bytes).digest('hex'))
|
||||
}
|
||||
assert.equal(homeIconHashes.size, homeIconAssets.length, '首页 8 个入口不得复用同一图标')
|
||||
|
||||
console.log('Brand asset contracts passed')
|
||||
|
||||
Reference in New Issue
Block a user