Skip to content

Commit

Permalink
Merge pull request #15039 from artsy/damassi/chore/open-with-flag
Browse files Browse the repository at this point in the history
feat(start): Add --open cli argument
  • Loading branch information
damassi authored Dec 20, 2024
2 parents 9656644 + da95f9a commit 3894593
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 198 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"use-deep-compare-effect": "^1.2.0",
"uuid": "3.3.2",
"web-vitals": "^4.2.4",
"yargs": "13",
"yargs": "^17.7.2",
"yup": "0.32.6"
},
"devDependencies": {
Expand Down
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
Loading

0 comments on commit 3894593

Please sign in to comment.