Skip to content

Commit

Permalink
feat(start): Add --open cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
damassi committed Dec 20, 2024
1 parent 9656644 commit 2a45088
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ "${NODE_ENV}" != "production" ]; then
exec node --max_old_space_size=3072 -r @swc-node/register ./src/dev.ts
# Dev
else
yarn concurrently --raw --kill-others 'yarn relay --watch' 'node --max_old_space_size=3072 -r @swc-node/register ./src/dev.ts'
yarn concurrently --raw --kill-others 'yarn relay --watch' "node --max_old_space_size=3072 -r @swc-node/register ./src/dev.ts $@"
fi
# Prod
else
Expand Down
27 changes: 25 additions & 2 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { execSync } from "child_process"
import { createReloadable } from "@artsy/express-reloadable"
import { createRsbuild, loadConfig, logger } from "@rsbuild/core"
import express from "express"
import { isString } from "lodash"
import { hideBin } from "yargs/helpers"
import yargs from "yargs/yargs"

interface CLIArguments {
open?: string
}

const args = yargs(hideBin(process.argv)).argv as CLIArguments

export async function startDevServer() {
// Wait for multienv to load envs
Expand Down Expand Up @@ -34,14 +43,28 @@ export async function startDevServer() {
mountAndReload(outputPath)

const httpServer = await startServer(app, () => {
const url = `http://localhost:${rsbuildServer.port}`
const url = (() => {
const defaultURL = `http://localhost:${rsbuildServer.port}`

if (args.open) {
if (isString(args.open)) {
return args.open
} else {
return defaultURL
}
}

return defaultURL
})()

rsbuildServer.afterListen()

logger.log(`[Force] Server started at ${url}`)

// Open the browser
execSync(`open ${url}`)
if (args.open) {
execSync(`open ${url}`)
}
})

rsbuildServer.connectWebSocket({ server: httpServer })
Expand Down

0 comments on commit 2a45088

Please sign in to comment.