需求:小程序端代码要同时同步到服务器与 git 远程仓库,此前前端仅存在于本地目录(无 remote,从未推送), 服务器与 gitcode 上只有后端。现并入本仓库,复用现有「push 即部署」链路,一次推送双端落地。 - 新增 uniapp/:小程序端源码全量快照(150 文件 / 1.2M) pages(13 页面) · components(fc-navbar/fc-tabbar/fc-post-card/fc-empty) · common(api·utils·mock·assets·store·config) · static(74 图标 + 3 轮播插画 + LOGO) · docs(01-04 交付文档) · tests(零依赖全链路用例) · tools(图标/主题/轮播配图生成脚本) - 明确排除:AGENTS.md(含后台密码、服务器 root 密码、小程序 AppSecret,切勿入库)、 unpackage/(构建产物,由 uniapp/.gitignore 忽略)、node_modules、.DS_Store、*.log - .gitignore 新增 /uniapp/AGENTS.md 兜底(与根 /AGENTS.md、/fluniapp/ 同一约定) - README.md 增补「本项目结构 + 部署链路」章节,说明 uniapp/ 为源码快照、 小程序真正上线仍需微信开发者工具 cli upload 说明:本次为源码快照,未携带前端本地仓库历史——其历史提交中含 AGENTS.md 凭据, 若做 subtree 合并会把密码永久写入本仓库历史,故采用快照方式。
80 行
3.2 KiB
JavaScript
80 行
3.2 KiB
JavaScript
/**
|
||
* 轮播配图(白色插画)生成器
|
||
* ------------------------------------------------------------
|
||
* 与 gen-icons.mjs 完全同一套链路:同一份 SVG 渲染「白底」「黑底」两遍 →
|
||
* 两式联立解出真实 alpha → contentBox 定位内容区 → 2× 降采样 → 192×192 真实透明 PNG。
|
||
* 运行: node tools/gen-banner-art.mjs
|
||
*/
|
||
import fs from 'node:fs'
|
||
import path from 'node:path'
|
||
import os from 'node:os'
|
||
import url from 'node:url'
|
||
import { execFileSync } from 'node:child_process'
|
||
import { BANNER_ART, buildBannerArtSvg } from './banner-art.mjs'
|
||
import { decodePng, encodePng, extractAlpha, transparentRatio, contentBox, crop, downscale } from './png-util.mjs'
|
||
|
||
const ROOT = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..')
|
||
const OUT_DIR = path.join(ROOT, 'static', 'banners')
|
||
const SIZE = 384 // 渲染分辨率(96 坐标系 → 4×)
|
||
const TARGET = 192 // 最终输出边长
|
||
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'fc-bannerart-'))
|
||
const SRC = path.join(TMP, 'src')
|
||
const RST = path.join(TMP, 'out')
|
||
fs.mkdirSync(SRC, { recursive: true })
|
||
fs.mkdirSync(RST, { recursive: true })
|
||
fs.mkdirSync(OUT_DIR, { recursive: true })
|
||
|
||
/* 1. 两版 SVG */
|
||
const names = []
|
||
for (const def of BANNER_ART) {
|
||
const base = def.file.replace(/\.png$/, '')
|
||
fs.writeFileSync(path.join(SRC, `${base}__w.svg`), buildBannerArtSvg(def, '#FFFFFF'), 'utf8')
|
||
fs.writeFileSync(path.join(SRC, `${base}__b.svg`), buildBannerArtSvg(def, '#000000'), 'utf8')
|
||
names.push(base)
|
||
}
|
||
|
||
/* 2. 渲染(qlmanage 会把内容贴到正方形画布上,其余补白,用 contentBox 裁掉) */
|
||
try {
|
||
execFileSync(
|
||
'qlmanage',
|
||
['-t', '-s', String(SIZE), '-o', RST, ...names.flatMap((n) => [path.join(SRC, `${n}__w.svg`), path.join(SRC, `${n}__b.svg`)])],
|
||
{ stdio: 'ignore' },
|
||
)
|
||
} catch (e) {
|
||
/* 忽略,后续按产物校验 */
|
||
}
|
||
|
||
/* 3. 反解 alpha -> 透明 PNG */
|
||
let ok = 0
|
||
const missing = []
|
||
const lowAlpha = []
|
||
const sizeSet = new Set()
|
||
for (const n of names) {
|
||
const fw = path.join(RST, `${n}__w.svg.png`)
|
||
const fb = path.join(RST, `${n}__b.svg.png`)
|
||
if (!fs.existsSync(fw) || !fs.existsSync(fb)) {
|
||
missing.push(n)
|
||
continue
|
||
}
|
||
const black = decodePng(fs.readFileSync(fb))
|
||
const box = contentBox(black)
|
||
let img = extractAlpha(crop(decodePng(fs.readFileSync(fw)), box), crop(black, box))
|
||
img = downscale(img, Math.max(1, Math.floor(img.width / TARGET)))
|
||
const ratio = transparentRatio(img)
|
||
if (ratio < 0.1) lowAlpha.push(`${n}(${ratio.toFixed(2)})`)
|
||
fs.writeFileSync(path.join(OUT_DIR, `${n}.png`), encodePng(img))
|
||
sizeSet.add(`${img.width}×${img.height}`)
|
||
ok++
|
||
}
|
||
|
||
fs.rmSync(TMP, { recursive: true, force: true })
|
||
|
||
const bytes = fs
|
||
.readdirSync(OUT_DIR)
|
||
.filter((f) => f.endsWith('.png'))
|
||
.reduce((s, f) => s + fs.statSync(path.join(OUT_DIR, f)).size, 0)
|
||
console.log(`✅ 轮播配图生成完成:${ok}/${names.length} 张 → static/banners/(${[...sizeSet].join(', ')},真实透明,合计 ${(bytes / 1024).toFixed(1)}KB)`)
|
||
if (missing.length) console.log(`⚠️ 未生成:${missing.join(', ')}`)
|
||
if (lowAlpha.length) console.log(`⚠️ 透明区域异常:${lowAlpha.join(', ')}`)
|
||
if (missing.length) process.exitCode = 1
|