Skip to content

Commit db94785

Browse files
committed
微信开发者工具打开
1 parent b51ab26 commit db94785

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

src/harmony/tools/hdc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ export async function getHdc() {
4949
if (await exists(hdcPath)) return hdcPath
5050
}
5151

52-
throw Error('未找到 hdc 可执行文件,请确定已安装 Harmony SDK')
52+
throw Error('未找到 hdc 可执行文件,请确认已安装 Harmony SDK')
5353
}

src/harmony/tools/hvigorw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function getHvigorw() {
3131
if (await exists(hvigorwPath)) return hvigorwPath
3232
}
3333

34-
throw Error('未找到 hvigorw 可执行文件,请确定已安装 Harmony 命令行工具或者DevEco')
34+
throw Error('未找到 hvigorw 可执行文件,请确认已安装 Harmony 命令行工具或者DevEco')
3535
}
3636

3737
export async function hvigorwClean() {

src/harmony/tools/ohpm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function getOhpm() {
3030
if (await exists(ohpmPath)) return ohpmPath
3131
}
3232

33-
throw Error('未找到 ohpm 可执行文件,请确定已安装 Harmony 命令行工具或者DevEco')
33+
throw Error('未找到 ohpm 可执行文件,请确认已安装 Harmony 命令行工具或者DevEco')
3434
}
3535

3636
export async function ohpmInstall() {

src/platforms/mp-weixin.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
import { existsSync } from 'node:fs'
21
import { resolve } from 'node:path'
32
import { execa } from 'execa'
43
import type { GeneratorTransform } from 'execa/types/transform/normalize.js'
5-
import ora from 'ora'
64
import { resolveCommand } from 'package-manager-detector/commands'
75
import type { BuildOptions } from '../build.js'
86
import type { RunOptions } from '../run.js'
97
import { App } from '../utils/app.js'
10-
import { errorDebugLog } from '../utils/error.js'
118
import { stripAnsiColors } from '../utils/exec.js'
9+
import { exists } from '../utils/file.js'
1210
import Log from '../utils/log.js'
13-
import { isWindows, uniRunSuccess } from '../utils/util.js'
11+
import { isDarwin, isWindows, uniRunSuccess } from '../utils/util.js'
1412
import { PlatformModule } from './index.js'
1513

16-
function getWeixinDevToolCliPath() {
14+
async function getWeixinDevToolCliPath() {
1715
if (process.env.WEIXIN_DEV_TOOL) {
18-
if (existsSync(process.env.WEIXIN_DEV_TOOL)) return process.env.WEIXIN_DEV_TOOL
16+
if (await exists(process.env.WEIXIN_DEV_TOOL)) return process.env.WEIXIN_DEV_TOOL
1917
}
2018
const defaultPath = isWindows()
2119
? 'C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat'
2220
: '/Applications/wechatwebdevtools.app/Contents/MacOS/cli'
23-
if (existsSync(defaultPath)) return defaultPath
21+
if (await exists(defaultPath)) return defaultPath
2422
}
2523

26-
function openWeixinDevTool(projectPath: string) {
27-
const cliPath = getWeixinDevToolCliPath()
24+
async function openWeixinDevTool(projectPath: string) {
25+
if (!isWindows() && !isDarwin()) {
26+
Log.error(`微信开发者工具不支持系统: ${process.platform}`)
27+
return
28+
}
29+
const cliPath = await getWeixinDevToolCliPath()
2830
if (!cliPath) {
29-
Log.error('微信开发工具没有找到,请运行 `uniapp requirement mp-weixin` 查看详细信息')
31+
Log.error('未找到微信开发工具,请确认已安装')
3032
return
3133
}
32-
const spinner = ora('正在打开微信开发者工具').start()
33-
execa`${cliPath} ${['open', '--project', resolve(App.projectRoot, projectPath)]}`
34-
.then(({ stderr }) => {
35-
if (stderr) {
36-
spinner.fail('微信开发者工具打开出错了')
37-
} else {
38-
spinner.succeed('微信开发者工具已打开')
39-
}
40-
})
41-
.catch((err) => {
42-
spinner.fail('微信开发者工具打开出错了')
43-
errorDebugLog(err)
44-
})
34+
await execa({
35+
stdio: 'inherit',
36+
env: { FORCE_COLOR: 'true' },
37+
reject: false,
38+
})`${cliPath} ${['open', '--project', resolve(App.projectRoot, projectPath)]}`
4539
}
4640

4741
export default class PlatformMPWeixin extends PlatformModule {
@@ -50,12 +44,12 @@ export default class PlatformMPWeixin extends PlatformModule {
5044
modules = ['@dcloudio/uni-mp-weixin']
5145

5246
async requirement() {
53-
if (process.platform !== 'win32' && process.platform !== 'darwin') {
47+
if (!isWindows() && !isDarwin()) {
5448
Log.error(`微信开发者工具不支持系统: ${process.platform}`)
5549
return
5650
}
5751

58-
const cliPath = getWeixinDevToolCliPath()
52+
const cliPath = await getWeixinDevToolCliPath()
5953

6054
if (cliPath) {
6155
Log.success(`微信开发者工具已安装 (${cliPath})`)
@@ -89,7 +83,7 @@ export default class PlatformMPWeixin extends PlatformModule {
8983
if (!uniRunSuccess(text)) return
9084

9185
over = true
92-
openWeixinDevTool('dist/dev/mp-weixin')
86+
void openWeixinDevTool('dist/dev/mp-weixin')
9387
} as GeneratorTransform<false>
9488

9589
await execa({
@@ -121,7 +115,7 @@ export default class PlatformMPWeixin extends PlatformModule {
121115

122116
const text = stripAnsiColors(stdout as unknown as string)
123117
if (/DONE {2}Build complete\./.test(text)) {
124-
openWeixinDevTool('dist/build/mp-weixin')
118+
await openWeixinDevTool('dist/build/mp-weixin')
125119
}
126120
}
127121
}

0 commit comments

Comments
 (0)