|
|
@@ -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 {
|