Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update hap-server #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions __tests__/examples/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ describe('hap-toolkit', () => {
it(
'hap-server',
async () => {
const serverReg = /服务器地址: (http:\/\/.*),/
const dialogs = [
{
pattern: (output) => {
return output.match(/生成HTTP服务器的二维码: (http:\/\/.*)/)
return output.match(serverReg)
},
feeds: (proc, output) => {
const match = output.match(/生成HTTP服务器的二维码: (http:\/\/.*)/)
const match = output.match(serverReg)
const url = match[1]
const p1 = fetch(url)
.then((res) => {
Expand Down
14 changes: 1 addition & 13 deletions packages/hap-packager/src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ async function notify(context, next) {
await next()
}

/**
* 二维码api
*/
async function qrCode(context, next) {
const port = context.app.server.address().port
const data = getServerAddress(port)
const image = qr.image(data, { size: 9 })
await next()
context.type = 'image/png'
context.body = image
}

async function saveDataCoverage(context, next) {
const reqDataCoverage = context.request.body.coverage
if (!reqDataCoverage) {
Expand Down Expand Up @@ -224,7 +212,7 @@ async function saveDataLogs(context, next) {
export default {
index,
bundle,
qrCode,
qrCode: index,
logger,
notify,
saveDataCoverage,
Expand Down
8 changes: 3 additions & 5 deletions packages/hap-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import http from 'http'
import Koa from 'koa'
import opn from 'opn'
import portfinder from 'portfinder'
import qrTerminal from 'qrcode-terminal'
import {
outputQRCodeOnTerminal,
getIPv4IPAddress,
colorconsole,
globalConfig,
Expand Down Expand Up @@ -75,11 +75,9 @@ export async function launch(conf) {
colorconsole.info(`### App Server ### 服务器地址: ${localUrl}, ${lanUrl}`)
colorconsole.info(`### App Server ### 请确保手机与App Server处于相同网段`)
// 输出二维码地址
outputQRCodeOnTerminal(lanUrl)
qrTerminal.generate(lanUrl, { small: true })
// 在浏览器中打开二维码页面
if (openBrowser) {
opn(lanUrl)
}
openBrowser && opn(lanUrl)
resolve({
launchServerError: null,
server,
Expand Down
3 changes: 1 addition & 2 deletions packages/hap-shared-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"event-bus.js"
],
"dependencies": {
"chalk": "^2.4.2",
"qrcode-terminal": "^0.12.0"
"chalk": "^2.4.2"
},
"devDependencies": {
"strip-ansi": "^5.2.0"
Expand Down
9 changes: 0 additions & 9 deletions packages/hap-shared-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import http from 'http'
import { Console } from 'console'
import chalk from 'chalk'
import qrTerminal from 'qrcode-terminal'

Check warning on line 12 in packages/hap-shared-utils/src/index.js

View workflow job for this annotation

GitHub Actions / unit-test

'qrTerminal' is defined but never used

Check warning on line 12 in packages/hap-shared-utils/src/index.js

View workflow job for this annotation

GitHub Actions / test-cov

'qrTerminal' is defined but never used
import globalConfig from './config'
import BuildModeManager from './buildMode/BuildModeManager.js'

Expand Down Expand Up @@ -197,15 +197,6 @@
return ip
}

/**
* 命令行输出二维码
* @param text
*/
export function outputQRCodeOnTerminal(text) {
console.info(`\n生成HTTP服务器的二维码: ${text}`)
qrTerminal.generate(text, { small: true })
}

/**
* 相对工作目录的路径
*
Expand Down
Loading