Skip to content

Commit d09611f

Browse files
committed
feat: 完善微信提交审核流程
1 parent 1c65fc8 commit d09611f

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dist"
3131
],
3232
"scripts": {
33-
"start": "pnpm dev && node ./index.js",
33+
"start": "pnpm dev && cross-env NODE_ENV=development node ./index.js",
3434
"dev": "unbuild --stub",
3535
"build": "unbuild",
3636
"publish:ci": "npm publish --access public",
@@ -52,6 +52,7 @@
5252
"@types/prompts": "^2.4.9",
5353
"@types/qrcode-terminal": "^0.12.2",
5454
"@types/upng-js": "^2.1.5",
55+
"cross-env": "^7.0.3",
5556
"eslint": "^8.56.0",
5657
"lint-staged": "^15.2.0",
5758
"simple-git-hooks": "^2.9.0",

pnpm-lock.yaml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/weixin/index.ts

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import process from 'node:process'
12
import { yellow } from 'kolorist'
23
import type { Browser, Page } from 'puppeteer'
34
import puppeteer from 'puppeteer'
@@ -56,13 +57,20 @@ export async function jumpToVersions() {
5657
}
5758
spinner.start('正在跳转到版本管理页面...')
5859
await versionManage.click()
60+
5961
const submitReviewBtn = await page.waitForSelector('.mod_default_box.code_version_dev .weui-desktop-btn.weui-desktop-btn_primary')
6062
if (!submitReviewBtn) {
6163
spinner.fail('未找到提交审核按钮')
6264
throw new Error('未找到提交审核按钮')
6365
}
66+
// 判断是否有提交审核中的版本
67+
const testVersion = await page.$('.mod_default_bd.default_box.test_version')
68+
if (testVersion && !await testVersion.evaluate(el => el.textContent?.includes('你暂无提交审核的版本或者版本已发布上线'))) {
69+
spinner.warn('存在提交审核中的版本')
70+
throw new Error('存在提交审核中的版本')
71+
}
6472
await submitReviewBtn.click()
65-
await sleep(1000)
73+
await sleep(1200) // 可能会报错
6674
}
6775

6876
/**
@@ -135,13 +143,23 @@ export async function toRelease() {
135143
}
136144

137145
export default async function weixinRobot(action: ACTION) {
138-
await getLoginScanCode()
139-
await jumpToVersions()
140-
if (action === ACTION.REVIEW) {
141-
await jumpToConfirmPage()
142-
await toSubmitAudit()
146+
try {
147+
await getLoginScanCode()
148+
await jumpToVersions()
149+
if (action === ACTION.REVIEW) {
150+
await jumpToConfirmPage()
151+
await toSubmitAudit()
152+
}
153+
else {
154+
await toRelease()
155+
}
156+
process.exit(0)
143157
}
144-
else {
145-
await toRelease()
158+
catch (err) {
159+
if (process.env.NODE_ENV === 'development') {
160+
console.error(err)
161+
return
162+
}
163+
process.exit(1)
146164
}
147165
}

0 commit comments

Comments
 (0)