From 355fdb95b97726f0b6e663915b16656a60568c69 Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Fri, 10 Jun 2022 15:47:58 -0700 Subject: [PATCH] enhancement(cli): add option to --- packages/remix-dev/__tests__/cli-test.ts | 1 + packages/remix-dev/cli/commands.ts | 12 ++++++++++-- packages/remix-dev/cli/run.ts | 9 +++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/remix-dev/__tests__/cli-test.ts b/packages/remix-dev/__tests__/cli-test.ts index 9c58df72e3a..87c933e73f7 100644 --- a/packages/remix-dev/__tests__/cli-test.ts +++ b/packages/remix-dev/__tests__/cli-test.ts @@ -110,6 +110,7 @@ describe("remix CLI", () => { --sourcemap Generate source maps for production \`dev\` Options: --debug Attach Node.js inspector + --port, -p Choose the port from which to run your app \`routes\` Options: --json Print the routes as JSON \`migrate\` Options: diff --git a/packages/remix-dev/cli/commands.ts b/packages/remix-dev/cli/commands.ts index 320ac28166d..27d637f6377 100644 --- a/packages/remix-dev/cli/commands.ts +++ b/packages/remix-dev/cli/commands.ts @@ -234,7 +234,11 @@ export async function watch( }); } -export async function dev(remixRoot: string, modeArg?: string) { +export async function dev( + remixRoot: string, + modeArg?: string, + portArg?: number +) { let createApp: typeof createAppType; let express: typeof Express; try { @@ -255,7 +259,11 @@ export async function dev(remixRoot: string, modeArg?: string) { await loadEnv(config.rootDirectory); let port = await getPort({ - port: process.env.PORT ? Number(process.env.PORT) : makeRange(3000, 3100), + port: portArg + ? Number(portArg) + : process.env.PORT + ? Number(process.env.PORT) + : makeRange(3000, 3100), }); if (config.serverEntryPoint) { diff --git a/packages/remix-dev/cli/run.ts b/packages/remix-dev/cli/run.ts index 6f551c84d79..55431afc244 100644 --- a/packages/remix-dev/cli/run.ts +++ b/packages/remix-dev/cli/run.ts @@ -42,6 +42,7 @@ ${colors.heading("Options")}: --sourcemap Generate source maps for production \`dev\` Options: --debug Attach Node.js inspector + --port, -p Choose the port from which to run your app \`routes\` Options: --json Print the routes as JSON \`migrate\` Options: @@ -126,10 +127,13 @@ const npxInterop = { pnpm: "pnpm exec", }; -async function dev(projectDir: string, flags: { debug?: boolean }) { +async function dev( + projectDir: string, + flags: { debug?: boolean; port?: number } +) { if (!process.env.NODE_ENV) process.env.NODE_ENV = "development"; if (flags.debug) inspector.open(); - await commands.dev(projectDir, process.env.NODE_ENV); + await commands.dev(projectDir, process.env.NODE_ENV, flags.port); } /** @@ -157,6 +161,7 @@ export async function run(argv: string[] = process.argv.slice(2)) { install: { type: "boolean" }, json: { type: "boolean" }, migration: { type: "string", alias: "m" }, + port: { type: "number", alias: "p" }, remixVersion: { type: "string" }, sourcemap: { type: "boolean" }, template: { type: "string" },