MCPcopy Create free account
hub / github.com/auth0/auth0-cli / runConnectedMode

Function runConnectedMode

internal/cli/acul_dev.go:268–407  ·  view source on GitHub ↗
(ctx context.Context, cli *cli, projectDir, port string, screensToWatch []string)

Source from the content-addressed store, hash-verified

266}
267
268func runConnectedMode(ctx context.Context, cli *cli, projectDir, port string, screensToWatch []string) error {
269 fmt.Println("\n🚀 " + ansi.Green("ACUL connected dev mode started for: "+ansi.Cyan(projectDir)))
270
271 // Step 1: Do initial build.
272 fmt.Println("")
273 fmt.Println("🔨 " + ansi.Bold(ansi.Blue("Step 1: Running initial build with 'npm run build'")))
274 if err := buildProject(cli, projectDir); err != nil {
275 return fmt.Errorf("initial build failed: %w", err)
276 }
277
278 // Always validate screens after build to ensure they have actual built assets.
279 screensToWatch, err := validateScreensAfterBuild(projectDir, screensToWatch)
280 if err != nil {
281 return fmt.Errorf("screen validation failed after build: %w", err)
282 }
283
284 // Step 2: Ask user to host assets and get port confirmation.
285 fmt.Println("")
286 fmt.Println("📡 " + ansi.Bold(ansi.Blue("Step 2: Host your assets locally")))
287
288 if port == "" {
289 var portInput string
290
291 portQuestion := prompt.TextInput("port", "Enter port to serve assets:", "Example: 55444", "55444", true)
292 if err := prompt.AskOne(portQuestion, &portInput); err != nil {
293 return fmt.Errorf("failed to get port: %w", err)
294 }
295
296 if _, err = strconv.Atoi(portInput); err != nil {
297 return fmt.Errorf("invalid port number: %s", portInput)
298 }
299
300 port = portInput
301 }
302
303 if !isPortFree(port) {
304 return fmt.Errorf("port %s is already in use; please free it or choose another port", port)
305 }
306
307 fmt.Println("💡 " + ansi.Yellow("Your assets must be served locally with CORS enabled."))
308
309 runServe := prompt.Confirm(fmt.Sprintf("Would you like to host the assets by running 'npx serve dist -p %s --cors' in the background?", port))
310
311 var serveStarted bool
312
313 if runServe {
314 fmt.Println("🚀 " + ansi.Cyan("Starting local server in the background..."))
315
316 serveCmd := exec.Command("npx", "serve", "dist", "-p", port, "--cors")
317 serveCmd.Dir = projectDir
318
319 if cli.debug {
320 serveCmd.Stdout = os.Stdout
321 serveCmd.Stderr = os.Stderr
322 }
323
324 if err := serveCmd.Start(); err != nil {
325 fmt.Println("⚠️ " + ansi.Yellow("Failed to start local server: ") + ansi.Bold(err.Error()))

Callers 1

aculDevCmdFunction · 0.85

Calls 15

GreenFunction · 0.92
CyanFunction · 0.92
BoldFunction · 0.92
BlueFunction · 0.92
TextInputFunction · 0.92
AskOneFunction · 0.92
YellowFunction · 0.92
ConfirmFunction · 0.92
MagentaFunction · 0.92
buildProjectFunction · 0.85
isPortFreeFunction · 0.85

Tested by

no test coverage detected