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' )
5
9
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 )
9
18
}
10
19
11
- const privateKeyPath = path . resolve ( __dirname , './private.key' )
12
- fs . writeFileSync ( privateKeyPath , privateKeyContent )
13
-
14
20
const project = new ci . Project ( {
15
- appid : 'wxe5f52902cf4de896 ' ,
21
+ appid : 'wx622bee4f78fa4f5a ' ,
16
22
type : 'miniProgram' ,
17
23
projectPath : path . resolve ( __dirname , '../' ) ,
18
24
privateKeyPath : path . resolve ( __dirname , './key' ) ,
@@ -30,9 +36,11 @@ const params = {
30
36
minifyWXML : true ,
31
37
minifyWXSS : true ,
32
38
codeProtect : false ,
33
- autoPrefixWXSS : true
39
+ autoPrefixWXSS : true ,
40
+ ignoreUploadUnusedFiles : true
34
41
} ,
35
42
}
43
+ await ci . packNpm ( project , { } )
36
44
ci . upload ( {
37
45
project,
38
46
...params
@@ -45,3 +53,5 @@ ci.upload({
45
53
// 删除临时私钥文件
46
54
fs . unlinkSync ( privateKeyPath )
47
55
} )
56
+
57
+
0 commit comments