// 构建前准备两样东西: // 1) 把 docs/ 下的使用说明暂存到 console/extra/,供 electron-builder 的 extraFiles 平铺到部署包根目录; // 2) 生成安装器许可页顶部文案(console/resources/installer-signature.nsh),署名来自构建机本地文件。 // 用 Node 而不是批处理:中文文件名/中文内容在 .bat 里会被 cmd 解析错乱。 import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs' import { dirname, join } from 'node:path' const root = dirname(import.meta.dirname) // ---- 1. usage doc ----------------------------------------------------------- const extraDir = join(root, 'console', 'extra') mkdirSync(extraDir, { recursive: true }) const usageTarget = join(extraDir, '使用说明.txt') const usageSources = [join(root, 'docs', '使用说明.txt'), join(root, 'docs', '使用手册.md')] const usageSource = usageSources.find((file) => existsSync(file)) if (usageSource) { copyFileSync(usageSource, usageTarget) console.log(` usage doc staged from ${usageSource}`) } else { console.log(' [docs] no usage doc, skip') } // ---- 2. installer license page text ---------------------------------------- const signatureFile = join(root, 'deploy', 'signature.local.txt') const nshFile = join(root, 'console', 'resources', 'installer-signature.nsh') mkdirSync(dirname(nshFile), { recursive: true }) let topText = '请阅读并接受许可协议' if (existsSync(signatureFile)) { const signature = readFileSync(signatureFile, 'utf8').trim() if (signature !== '') topText = `内部署名:${signature}` } writeFileSync(nshFile, `!macro customHeader\n !define MUI_LICENSEPAGE_TEXT_TOP "${topText}"\n!macroend\n`, 'utf8') console.log(` installer license text ready (${existsSync(signatureFile) ? 'with' : 'without'} internal signature)`)