|
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') |
9 |
| - |
10 |
| -try { |
11 |
| - const content = fs.readFileSync(privateKeyPath, 'utf8'); |
12 |
| - console.log('文件内容:', content); |
13 |
| -} catch (err) { |
14 |
| - console.error('读取文件出错:', err); |
15 |
| -} |
16 |
| - |
17 |
| -// 检查私钥文件是否已存在 |
18 |
| -if (!fs.existsSync(privateKeyPath)) { |
19 |
| - const privateKeyContent = process.env.WX_PRIVATE_KEY |
20 |
| - if (!privateKeyContent) { |
21 |
| - throw new Error('未找到私钥内容,请确保已正确配置 GitHub Secrets') |
22 |
| - } |
23 |
| - console.log('>>>>写入私钥文件:', privateKeyPath); |
24 |
| - fs.writeFileSync(privateKeyPath, privateKeyContent) |
25 |
| -} |
26 |
| - |
27 |
| -const project = new ci.Project({ |
28 |
| - appid: 'wx622bee4f78fa4f5a', |
29 |
| - type: 'miniProgram', |
30 |
| - projectPath: path.resolve(__dirname, '../'), |
31 |
| - privateKeyPath: path.resolve(__dirname, './key'), |
32 |
| - ignores: [path.resolve(__dirname, '../miniprogram/node_modules/**/*')] |
33 |
| -}) |
34 |
| -const robotNumber = 2 |
35 |
| -const params = { |
36 |
| - onProgressUpdate: console.log, |
37 |
| - robot: robotNumber, |
38 |
| - version: packageJson.version, |
39 |
| - desc: packageJson.bundleDescription, |
40 |
| - setting: { |
41 |
| - es7: true, |
42 |
| - minifyJS: true, |
43 |
| - minifyWXML: true, |
44 |
| - minifyWXSS: true, |
45 |
| - codeProtect: false, |
46 |
| - autoPrefixWXSS: true, |
47 |
| - ignoreUploadUnusedFiles: true |
48 |
| - }, |
49 |
| -} |
50 |
| -await ci.packNpm(project, {}) |
51 |
| -ci.upload({ |
52 |
| - project, |
53 |
| - ...params |
54 |
| -}).then(res => { |
55 |
| - console.debug('>>>>upload res', res) |
56 |
| -}).catch(err => { |
57 |
| - console.error('>>>>upload error', err) |
58 |
| - throw err |
59 |
| -}).finally(() => { |
60 |
| - // 删除临时私钥文件 |
61 |
| - fs.unlinkSync(privateKeyPath) |
62 |
| -}) |
63 |
| - |
64 |
| - |
0 commit comments