ソースを参照

feat: 完善微信小程序发布功能

- 添加二维码生成到 web/public/qrcode 目录
- 使用 WEB_HOST 环境变量生成公网访问 URL
- 将 web/public/qrcode/ 添加到 .gitignore
- 清理临时二维码文件

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 3 日 前
コミット
eec4c5dab1
3 ファイル変更42 行追加7 行削除
  1. 2 0
      .gitignore
  2. BIN
      qrcode-enterprise.jpg
  3. 40 7
      scripts/publish-weapp.js

+ 2 - 0
.gitignore

@@ -69,3 +69,5 @@ mini/tests/__snapshots__/*
 web/public/问题封面/
 # 问题反映视频
 web/public/问题反映/
+# 小程序预览二维码
+web/public/qrcode/

BIN
qrcode-enterprise.jpg


+ 40 - 7
scripts/publish-weapp.js

@@ -1,13 +1,18 @@
 const ci = require('miniprogram-ci')
 const path = require('path')
 const { execSync } = require('child_process')
+const fs = require('fs')
+
+// 公网访问域名(从环境变量读取,默认本地)
+const WEB_HOST = process.env.WEB_HOST || 'localhost:8080'
+const PUBLIC_HOST = WEB_HOST.startsWith('http') ? WEB_HOST : `https://${WEB_HOST}`
 
 // 小程序配置
 const MINI_CONFIGS = {
   enterprise: {
     name: '企业小程序',
     appid: 'wx1e791ed2e0229eb8',
-    projectPath: path.resolve(__dirname, '../mini'),
+    projectPath: path.resolve(__dirname, '../mini/dist/weapp/production'),
     privateKeyPath: path.resolve(__dirname, '../mini/certs/private.upload.key'),
     buildCmd: 'cd mini && pnpm build:weapp',
     distPath: 'dist/weapp',
@@ -15,7 +20,7 @@ const MINI_CONFIGS = {
   talent: {
     name: '人才小程序',
     appid: 'wx3c47dbce1ea7d43c',
-    projectPath: path.resolve(__dirname, '../mini-talent'),
+    projectPath: path.resolve(__dirname, '../mini-talent/dist/weapp/production'),
     privateKeyPath: path.resolve(__dirname, '../mini-talent/certs/private.upload.key'),
     buildCmd: 'cd mini-talent && pnpm build:weapp',
     distPath: 'dist/weapp',
@@ -89,7 +94,7 @@ async function uploadExperienceProject(config, options) {
  * 预览小程序(生成二维码)
  */
 async function previewDevProject(config, options) {
-  const { desc, qrcodePath, robot = 1 } = options
+  const { desc, robot = 1 } = options
 
   console.log(`\n👀 正在生成 ${config.name} 预览二维码...`)
 
@@ -101,6 +106,16 @@ async function previewDevProject(config, options) {
     ignores: ['node_modules/**/*'],
   })
 
+  // 二维码保存目录
+  const qrcodeDir = path.resolve(__dirname, '../web/public/qrcode')
+  const qrcodeFileName = `qrcode-${config.appid}.jpg`
+  const qrcodePath = path.join(qrcodeDir, qrcodeFileName)
+
+  // 确保 qrcode 目录存在
+  if (!fs.existsSync(qrcodeDir)) {
+    fs.mkdirSync(qrcodeDir, { recursive: true })
+  }
+
   try {
     await ci.preview({
       project,
@@ -114,7 +129,17 @@ async function previewDevProject(config, options) {
       robot,
     })
 
-    console.log(`\n✅ 开发版预览二维码已生成: ${qrcodePath}`)
+    // 公网访问 URL
+    const publicUrl = `${PUBLIC_HOST}/qrcode/${qrcodeFileName}`
+
+    console.log(`\n✅ 开发版预览二维码已生成!`)
+    console.log(`📱 本地路径: ${qrcodePath}`)
+    console.log(`🌐 公网访问: ${publicUrl}`)
+    console.log(`\n>>>QRCode_IMAGE_START<<<`)
+    console.log(qrcodePath)
+    console.log(`>>>QRCode_URL_START<<<`)
+    console.log(publicUrl)
+    console.log(`>>>QRCode_URL_END<<<`)
   } catch (error) {
     console.error(`\n❌ 开发版预览二维码生成失败`)
     console.error(error.message)
@@ -127,6 +152,11 @@ async function previewDevProject(config, options) {
  */
 async function main() {
   const args = process.argv.slice(2)
+  const noBuildIndex = args.indexOf('--no-build')
+  const noBuild = noBuildIndex !== -1
+  if (noBuild) {
+    args.splice(noBuildIndex, 1)
+  }
   const [miniType, action = 'experience'] = args
 
   // 解析参数
@@ -145,8 +175,12 @@ async function main() {
   const config = MINI_CONFIGS[miniType]
 
   try {
-    // 构建项目
-    buildMiniProject(config)
+    // 构建项目(除非使用 --no-build)
+    if (!noBuild) {
+      buildMiniProject(config)
+    } else {
+      console.log(`\n⏭️ 跳过构建,使用现有构建输出`)
+    }
 
     // 执行操作
     if (action === 'experience') {
@@ -154,7 +188,6 @@ async function main() {
     } else if (action === 'dev') {
       await previewDevProject(config, {
         desc: options.desc,
-        qrcodePath: path.resolve(__dirname, `../qrcode-${miniType}-dev.jpg`),
         robot: options.robot,
       })
     } else {