From 00cc673583e5857bd28cdc017954c9d30165c990 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 11 Aug 2023 14:00:06 +0800 Subject: [PATCH] cli: set port as paramter --- doric-cli/src/dev.ts | 7 +++---- doric-cli/src/index.ts | 15 +++++++++++++-- doric-cli/src/resourceServer.ts | 3 +-- doric-cli/src/server.ts | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doric-cli/src/dev.ts b/doric-cli/src/dev.ts index a50f91a7..81a85cc6 100644 --- a/doric-cli/src/dev.ts +++ b/doric-cli/src/dev.ts @@ -30,9 +30,8 @@ function getIPAdress() { return ret; } -export default async function dev() { - const server = await createServer() - +export default async function dev(serverPort = 7777, resourcePort = 7778) { + const server = await createServer(serverPort) const cachedContents: Record = {} chokidar @@ -123,7 +122,7 @@ export default async function dev() { console.log(`IP:${e}`); qrcode.generate(e, { small: true }); }); - createResServer(); + await createResServer(resourcePort); } diff --git a/doric-cli/src/index.ts b/doric-cli/src/index.ts index de4120b7..e4569a23 100644 --- a/doric-cli/src/index.ts +++ b/doric-cli/src/index.ts @@ -25,8 +25,14 @@ commander }) commander .command('dev') - .action(async function () { - await dev() + .option('--proxy', 'Link proxy') + .action(async function (cmd, args) { + const [proxy] = args + if (proxy) { + console.log("Running in proxy mode", proxy) + } else { + await dev() + } }) commander .command('build') @@ -58,5 +64,10 @@ commander .action(async function (platform, cmd) { await run(platform); }) +commander + .command('proxy') + .action(async function () { + await dev() + }) commander.parse(process.argv) diff --git a/doric-cli/src/resourceServer.ts b/doric-cli/src/resourceServer.ts index c237b105..4033c648 100644 --- a/doric-cli/src/resourceServer.ts +++ b/doric-cli/src/resourceServer.ts @@ -2,8 +2,7 @@ import fs from "fs" import path from "path" import http from "http"; import { IncomingMessage, ServerResponse } from "http"; -export async function createResServer() { - const port = 7778; +export async function createResServer(port: number) { const server = http.createServer(); server.listen(port); console.log(`resource server is listening on port ${port} !`.green); diff --git a/doric-cli/src/server.ts b/doric-cli/src/server.ts index 624c6016..2a389b09 100644 --- a/doric-cli/src/server.ts +++ b/doric-cli/src/server.ts @@ -12,12 +12,12 @@ export type MSG = { payload: { [index: string]: string } } -export async function createServer() { +export async function createServer(port: number) { let client: WebSocket | undefined = undefined; let debug: WebSocket | undefined = undefined; let deviceId = 0 let debugProcess: ChildProcess | undefined = undefined; - const wss = new WebSocket.Server({ port: 7777 }) + const wss = new WebSocket.Server({ port }) .on("connection", (ws, request) => { let thisDeviceId: string console.log('Connected', request.headers.host)