-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
38 lines (34 loc) · 1.02 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const automator = require('miniprogram-automator')
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
// 连接开发者工具
// https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/automator.html#automator-connect
automator.connect({
wsEndpoint: 'ws://localhost:9420',
}).then(async miniProgram => {
const data = await miniProgram.callWxMethod('login')
console.log(data);
res.send(data)
miniProgram.disconnect()
})
})
app.get('/launch', (req, res) => {
// 获取 req 中的参数
const { projectPath } = req.query
// 启动并连接开发者工具
// https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/automator.html#automator-launch
automator.launch({
// NOTE: 请根据实际情况修改
projectPath,
}).then(async miniProgram => {
const data = await miniProgram.callWxMethod('login')
console.log(data);
res.send(data)
miniProgram.close()
})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})