ignite icon indicating copy to clipboard operation
ignite copied to clipboard

fix(generate): add support for Expo Router app directory prompts

Open cdanwards opened this issue 10 months ago • 2 comments

Description

  • Issues: fixes #2903

This PR addresses a user who creates screens within an ignited app using expo-router. It checks for the existence of src/app (the expo router configuration) and then determines where to put the screen in 4 ways:

  • An override provided in the CLI command
  • destinationDir set from the screen generator template
  • If neither of those exists, it prompts the user to provide a dir path, if none is provided or they decide to not create that directory, it defaults to src/app/

Screenshots

Scenario Result
Using CLI Override for directory override
Using directory set in template front matter frontmatter
Setting via prompts - chooses to create dir created_dir
Setting via prompts - detects src/app and user just taps enter CleanShot 2025-04-30 at 07 26 44@2x
Setting via prompts - goes to default src/app Screenshot 2025-02-27 at 10 57 11 AM

Checklist

  • [X] README.md and other relevant documentation has been updated with my changes
  • [X] I have manually tested this, including by generating a new app locally (see docs).

cdanwards avatar Feb 24 '25 20:02 cdanwards

Sorry about not chiming in on the original issue!

I have some thoughts.

  1. I think the screen should be separated from the route.
npx ignite-cli g screen DetailScreen

The screen should always (IMO) be in src/app/screens/detail-screen.tsx (if it's an Expo Router app)

  1. We need a route generator
npx ignite-cli g route listings/detail DetailScreen

This creates a route file at app/listings/detail.tsx which imports the specified screen.

This would allow us to have multiple routes that can import the same screen.

It also eliminates this specialized generator logic which I think is going away from the spirit of the simple generators we want for Ignite. Ignite's generators got too complicated in earlier versions, which is why I rewrote them to be super simple in Ignite 6. The whole CLI was just over 900 lines of code at that point (vs 3k+ for previous versions), and I really don't want to continue to bloat it with additional logic if we can avoid that.

jamonholmgren avatar Apr 30 '25 18:04 jamonholmgren

I made some updates to this to help progress it along.

Now, for expo-router projects, we restored the screen generator to keep it being placed in src/screens, matching react navigation ignite projects (aside from the root dir)

In addition to that, upon a new project it will generate a route generator template which you can use like so:

npx ignite-cli g route welcome --dir=src/app/some/route

resulting in

src/app/some/route/welcome.tsx and generates

import { WelcomeScreen } from "@/screens/WelcomeScreen"

export default function Welcome() {
  return <WelcomeScreen />
}

frankcalise avatar May 26 '25 15:05 frankcalise