1- const path = require ( 'path' )
2- const ci = require ( 'miniprogram-ci' )
3- const fs = require ( 'fs' )
4- const packageJson = require ( '../package.json' )
1+ import path from 'path'
2+ import { fileURLToPath } from 'url'
3+ import fs from 'fs'
4+ import ci from 'miniprogram-ci'
5+ import packageJson from '../package.json' with { type : 'json' }
6+ const __filename = fileURLToPath ( import . meta. url )
7+ const __dirname = path . dirname ( __filename )
8+ const privateKeyPath = path . resolve ( __dirname , './key' )
59
6- const privateKeyContent = process . env . WX_PRIVATE_KEY
7- if ( ! privateKeyContent ) {
8- throw new Error ( '未找到私钥内容,请确保已正确配置 GitHub Secrets' )
10+ // 检查私钥文件是否已存在
11+ if ( ! fs . existsSync ( privateKeyPath ) ) {
12+ const privateKeyContent = process . env . WX_PRIVATE_KEY
13+ if ( ! privateKeyContent ) {
14+ throw new Error ( '未找到私钥内容,请确保已正确配置 GitHub Secrets' )
15+ }
16+ console . log ( '>>>>写入私钥文件:' , privateKeyPath ) ;
17+ fs . writeFileSync ( privateKeyPath , privateKeyContent )
918}
1019
11- const privateKeyPath = path . resolve ( __dirname , './private.key' )
12- fs . writeFileSync ( privateKeyPath , privateKeyContent )
13-
1420const project = new ci . Project ( {
1521 appid : 'wxe5f52902cf4de896' ,
1622 type : 'miniProgram' ,
@@ -30,9 +36,11 @@ const params = {
3036 minifyWXML : true ,
3137 minifyWXSS : true ,
3238 codeProtect : false ,
33- autoPrefixWXSS : true
39+ autoPrefixWXSS : true ,
40+ ignoreUploadUnusedFiles : true
3441 } ,
3542}
43+ await ci . packNpm ( project , { } )
3644ci . upload ( {
3745 project,
3846 ...params
@@ -45,3 +53,5 @@ ci.upload({
4553 // 删除临时私钥文件
4654 fs . unlinkSync ( privateKeyPath )
4755} )
56+
57+
0 commit comments