uniapp-android-cli 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +382 -2
- package/bin/uni-pack.js +7 -0
- package/package.json +66 -4
- package/src/cli.js +242 -0
- package/src/commands/build.js +46 -0
- package/src/commands/debug.js +183 -0
- package/src/commands/device.js +309 -0
- package/src/commands/devices.js +23 -0
- package/src/commands/doctor.js +170 -0
- package/src/commands/init.js +488 -0
- package/src/commands/projects.js +31 -0
- package/src/commands/wgt.js +90 -0
- package/src/core/adb.js +292 -0
- package/src/core/build.js +438 -0
- package/src/core/config.js +208 -0
- package/src/core/debugPreset.js +56 -0
- package/src/core/devicePairing.js +153 -0
- package/src/core/errors.js +36 -0
- package/src/core/fsx.js +183 -0
- package/src/core/gradle.js +221 -0
- package/src/core/gradleLog.js +188 -0
- package/src/core/hash.js +18 -0
- package/src/core/hbuilderx.js +260 -0
- package/src/core/hbuilderxCli.js +168 -0
- package/src/core/initConfig.js +214 -0
- package/src/core/initEnv.js +140 -0
- package/src/core/interactive.js +93 -0
- package/src/core/logger.js +82 -0
- package/src/core/output.js +181 -0
- package/src/core/patch/assets.js +154 -0
- package/src/core/patch/gradle.js +166 -0
- package/src/core/patch/manifest.js +81 -0
- package/src/core/patch/nativePlugins.js +137 -0
- package/src/core/patch/projectManifest.js +66 -0
- package/src/core/patch/template.js +75 -0
- package/src/core/patch/utsPlugins.js +425 -0
- package/src/core/process.js +120 -0
- package/src/core/project.js +263 -0
- package/src/core/qrcode.js +13 -0
- package/src/core/resourceVersion.js +87 -0
- package/src/core/sdk.js +403 -0
- package/src/core/signing.js +102 -0
- package/src/core/templateCache.js +81 -0
- package/src/core/version.js +128 -0
- package/src/core/webBuild.js +77 -0
- package/src/core/wgt.js +98 -0
- package/src/core/workdir.js +44 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import {
|
|
2
|
+
connectDevice,
|
|
3
|
+
deviceWifiIp,
|
|
4
|
+
disconnectDevice,
|
|
5
|
+
enableTcpip,
|
|
6
|
+
listDevices,
|
|
7
|
+
listMdnsServices,
|
|
8
|
+
mdnsSupported,
|
|
9
|
+
pairDevice,
|
|
10
|
+
pickDevice,
|
|
11
|
+
waitForDevice,
|
|
12
|
+
} from '../core/adb.js'
|
|
13
|
+
import { loadConfig } from '../core/config.js'
|
|
14
|
+
import {
|
|
15
|
+
hostOf,
|
|
16
|
+
normalizeAddress,
|
|
17
|
+
normalizePairingAddress,
|
|
18
|
+
pairingPayload,
|
|
19
|
+
selectPairingService,
|
|
20
|
+
validatePairingCode,
|
|
21
|
+
validateServiceName,
|
|
22
|
+
} from '../core/devicePairing.js'
|
|
23
|
+
import { PackError, EXIT } from '../core/errors.js'
|
|
24
|
+
import { Logger } from '../core/logger.js'
|
|
25
|
+
import { renderQr } from '../core/qrcode.js'
|
|
26
|
+
import { resolveAdbPath } from '../core/sdk.js'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {Record<string, any>} options
|
|
30
|
+
*/
|
|
31
|
+
export async function deviceCommand(options) {
|
|
32
|
+
const logger = new Logger(options)
|
|
33
|
+
const config = await loadConfig()
|
|
34
|
+
const adb = await resolveAdbPath(config)
|
|
35
|
+
const [action = 'list', ...rest] = options.positionals ?? []
|
|
36
|
+
|
|
37
|
+
if (action === 'list') {
|
|
38
|
+
await list(adb, logger)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (action === 'pair') {
|
|
42
|
+
if (rest.length >= 2) {
|
|
43
|
+
await pairByCode(adb, rest[0], rest[1], logger)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
await pairByQr(adb, options, logger)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (action === 'connect') {
|
|
50
|
+
await connect(adb, rest[0], logger)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
if (action === 'disconnect') {
|
|
54
|
+
await disconnect(adb, rest[0], logger)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
if (action === 'tcpip') {
|
|
58
|
+
await tcpip(adb, options, logger)
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
if (action === 'mdns') {
|
|
62
|
+
await mdns(adb, logger)
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
throw new PackError(`未知的 device 子命令:${action}`, EXIT.CONFIG, {
|
|
66
|
+
hint: '可用:list / pair / connect / disconnect / tcpip / mdns',
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} adb
|
|
72
|
+
* @param {Logger} logger
|
|
73
|
+
*/
|
|
74
|
+
async function list(adb, logger) {
|
|
75
|
+
const devices = await listDevices(adb)
|
|
76
|
+
if (devices.length === 0) {
|
|
77
|
+
logger.warn('没有发现设备。USB 连接请确认已开启 USB 调试;无线连接用 uni-pack device pair')
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
for (const device of devices) {
|
|
81
|
+
const kind = device.serial.includes(':') ? '无线' : 'USB'
|
|
82
|
+
logger.info(`${device.serial} ${device.state}${device.model ? ` ${device.model}` : ''} [${kind}]`)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} adb
|
|
88
|
+
* @param {Record<string, any>} options
|
|
89
|
+
* @param {Logger} logger
|
|
90
|
+
*/
|
|
91
|
+
async function pairByQr(adb, options, logger) {
|
|
92
|
+
if (!(await mdnsSupported(adb))) {
|
|
93
|
+
throw new PackError('当前 adb 不支持 mDNS 发现,无法使用二维码配对', EXIT.DEVICE, {
|
|
94
|
+
hint: '升级 Android SDK platform-tools(adb mdns check 应返回 mdns daemon 版本)',
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const service = validateServiceName(options.service)
|
|
99
|
+
const code = validatePairingCode(options.code)
|
|
100
|
+
const timeout = clamp(Number(options.timeout) || 120, 15, 600)
|
|
101
|
+
const payload = pairingPayload(service, code)
|
|
102
|
+
|
|
103
|
+
logger.step('手机扫码配对')
|
|
104
|
+
process.stdout.write(`${renderQr(payload)}\n`)
|
|
105
|
+
logger.info('手机:设置 → 开发者选项 → 无线调试 → 使用二维码配对设备')
|
|
106
|
+
logger.info(`服务名:${service} 配对码:${code}`)
|
|
107
|
+
logger.info(`等待手机注册配对服务(最多 ${timeout} 秒)…`)
|
|
108
|
+
|
|
109
|
+
const before = await listMdnsServices(adb)
|
|
110
|
+
const pairing = await waitForPairingService(adb, service, before, timeout)
|
|
111
|
+
if (!pairing) {
|
|
112
|
+
throw new PackError(`等待超时:没有发现配对服务 ${service}`, EXIT.DEVICE, {
|
|
113
|
+
hint: [
|
|
114
|
+
'确认手机与电脑在同一 Wi-Fi,且已选择“使用二维码配对设备”;关闭 VPN/代理后重试。',
|
|
115
|
+
'仍不行改用配对码方式:手机 无线调试 → “使用配对码配对设备”,然后执行',
|
|
116
|
+
' uni-pack device pair <手机显示的 IP:端口> <6 位配对码>',
|
|
117
|
+
'配对完成后在无线调试主页查看 IP:端口,执行 uni-pack device connect <IP:端口>',
|
|
118
|
+
'诊断:另开终端执行 uni-pack device mdns,应能看到 _adb-tls-pairing._tcp 服务',
|
|
119
|
+
].join('\n'),
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
logger.step(`发现配对服务:${pairing.address}`)
|
|
124
|
+
await pairDevice(adb, pairing.address, code)
|
|
125
|
+
logger.success('配对成功')
|
|
126
|
+
|
|
127
|
+
const connectService = await waitForConnectService(adb, pairing.host, before, 20)
|
|
128
|
+
if (!connectService) {
|
|
129
|
+
logger.info('暂未发现连接服务,可稍后在手机上查看 IP 并执行:uni-pack device connect <ip:port>')
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
await connectDevice(adb, connectService.address)
|
|
133
|
+
const device = await waitForDevice(adb, connectService.address, 10000)
|
|
134
|
+
if (device) {
|
|
135
|
+
logger.success(`已连接:${device.serial}${device.model ? `(${device.model})` : ''}`)
|
|
136
|
+
} else {
|
|
137
|
+
logger.warn(`已发起连接,但设备状态未就绪:${connectService.address}`)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {string} adb
|
|
143
|
+
* @param {string} addressValue
|
|
144
|
+
* @param {string} codeValue
|
|
145
|
+
* @param {Logger} logger
|
|
146
|
+
*/
|
|
147
|
+
async function pairByCode(adb, addressValue, codeValue, logger) {
|
|
148
|
+
const address = normalizePairingAddress(addressValue)
|
|
149
|
+
const code = validatePairingCode(codeValue)
|
|
150
|
+
const before = await listMdnsServices(adb)
|
|
151
|
+
logger.step(`配对 ${address}`)
|
|
152
|
+
await pairDevice(adb, address, code)
|
|
153
|
+
logger.success('配对成功')
|
|
154
|
+
|
|
155
|
+
const host = hostOf(address)
|
|
156
|
+
const connectService = await waitForConnectService(adb, host, before, 10)
|
|
157
|
+
if (!connectService) {
|
|
158
|
+
logger.info('已配对。请在手机“无线调试”主页查看 IP:端口,执行:uni-pack device connect <IP:端口>')
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
await connect(adb, connectService.address, logger)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param {string} adb
|
|
166
|
+
* @param {string} service
|
|
167
|
+
* @param {Array<{ address: string }>} before
|
|
168
|
+
* @param {number} timeoutSeconds
|
|
169
|
+
*/
|
|
170
|
+
async function waitForPairingService(adb, service, before, timeoutSeconds) {
|
|
171
|
+
const previous = new Set(before.map((item) => item.address))
|
|
172
|
+
const deadline = Date.now() + timeoutSeconds * 1000
|
|
173
|
+
while (Date.now() < deadline) {
|
|
174
|
+
const services = await listMdnsServices(adb)
|
|
175
|
+
const match = selectPairingService(services, previous, service)
|
|
176
|
+
if (match) {
|
|
177
|
+
return match
|
|
178
|
+
}
|
|
179
|
+
await sleep(1000)
|
|
180
|
+
}
|
|
181
|
+
return null
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {string} adb
|
|
186
|
+
* @param {string} host
|
|
187
|
+
* @param {Array<{ address: string }>} before
|
|
188
|
+
* @param {number} timeoutSeconds
|
|
189
|
+
*/
|
|
190
|
+
async function waitForConnectService(adb, host, before, timeoutSeconds) {
|
|
191
|
+
const previous = new Set(before.map((item) => item.address))
|
|
192
|
+
const deadline = Date.now() + timeoutSeconds * 1000
|
|
193
|
+
while (Date.now() < deadline) {
|
|
194
|
+
const services = await listMdnsServices(adb)
|
|
195
|
+
const candidates = services.filter((item) => item.type === 'connect' && item.host === host)
|
|
196
|
+
const fresh = candidates.find((item) => !previous.has(item.address))
|
|
197
|
+
if (fresh) {
|
|
198
|
+
return fresh
|
|
199
|
+
}
|
|
200
|
+
if (candidates.length === 1) {
|
|
201
|
+
return candidates[0]
|
|
202
|
+
}
|
|
203
|
+
await sleep(1000)
|
|
204
|
+
}
|
|
205
|
+
return null
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @param {string} adb
|
|
210
|
+
* @param {string | undefined} value
|
|
211
|
+
* @param {Logger} logger
|
|
212
|
+
*/
|
|
213
|
+
async function connect(adb, value, logger) {
|
|
214
|
+
if (!value) {
|
|
215
|
+
throw new PackError('缺少设备地址', EXIT.DEVICE, { hint: 'uni-pack device connect <ip[:port]>,默认端口 5555' })
|
|
216
|
+
}
|
|
217
|
+
const address = normalizeAddress(value)
|
|
218
|
+
logger.step(`连接 ${address}`)
|
|
219
|
+
await connectDevice(adb, address)
|
|
220
|
+
const device = await waitForDevice(adb, address, 10000)
|
|
221
|
+
if (device) {
|
|
222
|
+
logger.success(`已连接:${device.serial}${device.model ? `(${device.model})` : ''}`)
|
|
223
|
+
} else {
|
|
224
|
+
logger.warn(`已发起连接,但设备状态未就绪:${address}`)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @param {string} adb
|
|
230
|
+
* @param {string | undefined} value
|
|
231
|
+
* @param {Logger} logger
|
|
232
|
+
*/
|
|
233
|
+
async function disconnect(adb, value, logger) {
|
|
234
|
+
const address = value ? normalizeAddress(value) : ''
|
|
235
|
+
const output = await disconnectDevice(adb, address || undefined)
|
|
236
|
+
logger.success(output || (address ? `已断开 ${address}` : '已断开所有无线设备'))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param {string} adb
|
|
241
|
+
* @param {Record<string, any>} options
|
|
242
|
+
* @param {Logger} logger
|
|
243
|
+
*/
|
|
244
|
+
async function tcpip(adb, options, logger) {
|
|
245
|
+
const devices = await listDevices(adb)
|
|
246
|
+
const device = pickDevice(devices, options.device)
|
|
247
|
+
if (device.serial.includes(':')) {
|
|
248
|
+
throw new PackError(`设备已经是无线连接:${device.serial}`, EXIT.DEVICE, {
|
|
249
|
+
hint: 'USB 转无线请先用数据线连接设备',
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
const port = Number(options.port ?? 5555)
|
|
253
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
254
|
+
throw new PackError(`端口不合法:${options.port}`, EXIT.CONFIG, { hint: '端口范围 1–65535,无线调试常用 5555' })
|
|
255
|
+
}
|
|
256
|
+
const ip = await deviceWifiIp(adb, device.serial)
|
|
257
|
+
if (!ip) {
|
|
258
|
+
throw new PackError('无法读取设备的 Wi-Fi IP', EXIT.DEVICE, {
|
|
259
|
+
hint: '确认手机已连接 Wi-Fi;也可以手动执行 uni-pack device connect <手机IP>:5555',
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
logger.step(`开启无线调试:${device.serial}`)
|
|
264
|
+
await enableTcpip(adb, device.serial, port)
|
|
265
|
+
const address = `${ip}:${port}`
|
|
266
|
+
logger.success(`设备已监听 ${address}`)
|
|
267
|
+
|
|
268
|
+
if (options.connect) {
|
|
269
|
+
await connect(adb, address, logger)
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
logger.info(`连接:uni-pack device connect ${address}`)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @param {string} adb
|
|
277
|
+
* @param {Logger} logger
|
|
278
|
+
*/
|
|
279
|
+
async function mdns(adb, logger) {
|
|
280
|
+
if (!(await mdnsSupported(adb))) {
|
|
281
|
+
throw new PackError('当前 adb 不支持 mDNS 发现', EXIT.DEVICE, {
|
|
282
|
+
hint: '升级 Android SDK platform-tools 后重试',
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
const services = await listMdnsServices(adb)
|
|
286
|
+
if (services.length === 0) {
|
|
287
|
+
logger.warn('没有发现 mDNS 服务(无线调试是否已开启?手机与电脑是否在同一 Wi-Fi?)')
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
for (const service of services) {
|
|
291
|
+
logger.info(`${service.name} ${service.address} [${service.type}]`)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* @param {number} value
|
|
297
|
+
* @param {number} min
|
|
298
|
+
* @param {number} max
|
|
299
|
+
*/
|
|
300
|
+
function clamp(value, min, max) {
|
|
301
|
+
return Math.min(max, Math.max(min, value))
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @param {number} milliseconds
|
|
306
|
+
*/
|
|
307
|
+
function sleep(milliseconds) {
|
|
308
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds))
|
|
309
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { loadConfig } from '../core/config.js'
|
|
2
|
+
import { listDevices } from '../core/adb.js'
|
|
3
|
+
import { Logger } from '../core/logger.js'
|
|
4
|
+
import { resolveAdbPath } from '../core/sdk.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Record<string, any>} options
|
|
8
|
+
*/
|
|
9
|
+
export async function devicesCommand(options) {
|
|
10
|
+
const logger = new Logger(options)
|
|
11
|
+
const config = await loadConfig()
|
|
12
|
+
const adb = await resolveAdbPath(config)
|
|
13
|
+
const devices = await listDevices(adb)
|
|
14
|
+
|
|
15
|
+
if (devices.length === 0) {
|
|
16
|
+
logger.warn('没有检测到设备')
|
|
17
|
+
}
|
|
18
|
+
for (const device of devices) {
|
|
19
|
+
logger.info(`${device.serial}\t${device.state}\t${device.model}`)
|
|
20
|
+
}
|
|
21
|
+
logger.output('devices', { devices })
|
|
22
|
+
return devices
|
|
23
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { loadConfig, resolveProject } from '../core/config.js'
|
|
3
|
+
import { exists, readJson } from '../core/fsx.js'
|
|
4
|
+
import { resolveHbuilderx } from '../core/hbuilderx.js'
|
|
5
|
+
import { Logger } from '../core/logger.js'
|
|
6
|
+
import { detectVueVersion, normalizeManifest, readProjectManifest, readProjectPackage } from '../core/project.js'
|
|
7
|
+
import { listDevices } from '../core/adb.js'
|
|
8
|
+
import { resolveAndroidTools, resolveJavaHome, resolveSdk } from '../core/sdk.js'
|
|
9
|
+
import { resolveSigning } from '../core/signing.js'
|
|
10
|
+
import { assertVersionMatch, readCompilerVersion, readSdkVersion } from '../core/version.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Record<string, any>} options
|
|
14
|
+
*/
|
|
15
|
+
export async function doctorCommand(options) {
|
|
16
|
+
const logger = new Logger(options)
|
|
17
|
+
/** @type {{ name: string, ok: boolean, detail: string }[]} */
|
|
18
|
+
const checks = []
|
|
19
|
+
|
|
20
|
+
const add = (name, ok, detail) => {
|
|
21
|
+
checks.push({ name, ok, detail })
|
|
22
|
+
if (ok) {
|
|
23
|
+
logger.success(`${name}:${detail}`)
|
|
24
|
+
} else {
|
|
25
|
+
logger.warn(`${name}:${detail}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const [major] = process.versions.node.split('.').map(Number)
|
|
30
|
+
add('Node', major >= 20, process.versions.node)
|
|
31
|
+
|
|
32
|
+
const config = await loadConfig()
|
|
33
|
+
|
|
34
|
+
let sdkRoot = ''
|
|
35
|
+
let project
|
|
36
|
+
/** @type {{ version: string | null, source: string }} */
|
|
37
|
+
let compiler = { version: null, source: '' }
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
;({ project } = await resolveProject(config, options.project, options.cwd))
|
|
41
|
+
} catch (error) {
|
|
42
|
+
add('项目', false, error instanceof Error ? error.message : String(error))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (project) {
|
|
46
|
+
try {
|
|
47
|
+
const { manifest, type } = await readProjectManifest(project.projectDir)
|
|
48
|
+
project.type = type
|
|
49
|
+
const resolved = normalizeManifest(
|
|
50
|
+
manifest,
|
|
51
|
+
{
|
|
52
|
+
appid: project.appid,
|
|
53
|
+
package: project.package || (await readProjectPackage(project.projectDir)),
|
|
54
|
+
versionName: project.versionName,
|
|
55
|
+
versionCode: project.versionCode,
|
|
56
|
+
},
|
|
57
|
+
{ validate: false },
|
|
58
|
+
)
|
|
59
|
+
add('项目', true, `${resolved.name} ${resolved.appid} v${resolved.versionName}(${resolved.versionCode})`)
|
|
60
|
+
add(
|
|
61
|
+
'项目类型',
|
|
62
|
+
true,
|
|
63
|
+
`${type === 'hbuilderx' ? 'HBuilderX 项目' : 'CLI 项目'}(Vue ${await detectVueVersion(project.projectDir, manifest, type)})`,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if (type === 'hbuilderx') {
|
|
67
|
+
const hbuilderx = await resolveHbuilderx(config, { project })
|
|
68
|
+
if (hbuilderx) {
|
|
69
|
+
add('HBuilderX', true, `${hbuilderx.root}(${hbuilderx.version})`)
|
|
70
|
+
} else {
|
|
71
|
+
add('HBuilderX', false, '未找到,请配置 hbuilderx.root 或设置 HBUILDERX_HOME')
|
|
72
|
+
}
|
|
73
|
+
compiler = await readCompilerVersion(project, { hbuilderxRoot: hbuilderx?.root })
|
|
74
|
+
} else {
|
|
75
|
+
compiler = await readCompilerVersion(project)
|
|
76
|
+
}
|
|
77
|
+
add('编译器版本', Boolean(compiler.version), `${compiler.version ?? '未知'}(${compiler.source})`)
|
|
78
|
+
} catch (error) {
|
|
79
|
+
add('项目', false, error instanceof Error ? error.message : String(error))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const sdk = await resolveSdk(config, { project, version: compiler.version ?? undefined })
|
|
85
|
+
sdkRoot = sdk.root
|
|
86
|
+
add('离线 SDK', true, sdk.root)
|
|
87
|
+
} catch (error) {
|
|
88
|
+
add('离线 SDK', false, error instanceof Error ? error.message : String(error))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const tools = await resolveAndroidTools(config)
|
|
93
|
+
add('Android SDK', true, `${tools.sdkDir}(build-tools ${tools.buildTools})`)
|
|
94
|
+
const devices = await listDevices(tools.adb)
|
|
95
|
+
const online = devices.filter((device) => device.state === 'device')
|
|
96
|
+
add('ADB 设备', online.length > 0, online.map((device) => `${device.model || 'device'}(${device.serial})`).join(', ') || '未连接')
|
|
97
|
+
} catch (error) {
|
|
98
|
+
add('Android SDK', false, error instanceof Error ? error.message : String(error))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const javaHome = await resolveJavaHome(config)
|
|
103
|
+
add('JDK', true, javaHome)
|
|
104
|
+
} catch (error) {
|
|
105
|
+
add('JDK', false, error instanceof Error ? error.message : String(error))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (project) {
|
|
109
|
+
try {
|
|
110
|
+
const sdkVersion = sdkRoot ? await readSdkVersion(sdkRoot) : null
|
|
111
|
+
const versionCheck = assertVersionMatch({ compiler: compiler.version, sdk: sdkVersion })
|
|
112
|
+
add(
|
|
113
|
+
'版本一致性',
|
|
114
|
+
versionCheck.ok,
|
|
115
|
+
`uni-app ${compiler.version ?? '未知'} / 离线 SDK ${sdkVersion ?? '未知'}${
|
|
116
|
+
versionCheck.ok ? '' : '(必须一致,见 uni-pack build 的提示)'
|
|
117
|
+
}`,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const signing = await resolveSigning(project, options)
|
|
122
|
+
add('签名证书', true, `${signing.keyAlias} @ ${path.basename(signing.keystore)}`)
|
|
123
|
+
|
|
124
|
+
const tools = await resolveAndroidTools(config)
|
|
125
|
+
const { readKeystoreFingerprint } = await import('../core/sdk.js')
|
|
126
|
+
const fingerprint = await readKeystoreFingerprint(
|
|
127
|
+
tools.keytool,
|
|
128
|
+
signing.keystore,
|
|
129
|
+
signing.storePassword,
|
|
130
|
+
signing.keyAlias,
|
|
131
|
+
)
|
|
132
|
+
logger.info(`证书 SHA1:${fingerprint.sha1}`)
|
|
133
|
+
logger.info(`证书 SHA256:${fingerprint.sha256}`)
|
|
134
|
+
logger.info(`AppKey:${project.appKey ?? '(未配置)'}`)
|
|
135
|
+
logger.info('请核对 DCloud 后台的 AppKey 绑定:appid + 包名 + SHA1 三者必须一致')
|
|
136
|
+
} catch (error) {
|
|
137
|
+
add('签名证书', false, error instanceof Error ? error.message : String(error))
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
add('项目', false, error instanceof Error ? error.message : String(error))
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const failed = checks.filter((check) => !check.ok)
|
|
145
|
+
const blocking = failed.filter((check) => check.name !== 'ADB 设备')
|
|
146
|
+
if (project) {
|
|
147
|
+
if (blocking.length === 0) {
|
|
148
|
+
logger.info(
|
|
149
|
+
`下一步:uni-pack build -p "${project.projectDir}"(正式包);调试基座加 --mode debug,资源包用 uni-pack wgt`,
|
|
150
|
+
)
|
|
151
|
+
} else {
|
|
152
|
+
logger.info('先按上面的告警处理,再执行 build / wgt')
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
logger.output('doctor', { ok: failed.length === 0, checks })
|
|
156
|
+
if (failed.length > 0) {
|
|
157
|
+
process.exitCode = 3
|
|
158
|
+
}
|
|
159
|
+
return checks
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {string} file
|
|
164
|
+
*/
|
|
165
|
+
export async function readJsonSafe(file) {
|
|
166
|
+
if (!(await exists(file))) {
|
|
167
|
+
return undefined
|
|
168
|
+
}
|
|
169
|
+
return readJson(file)
|
|
170
|
+
}
|