-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(generate): add support for Expo Router app directory prompts #2905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cdanwards
wants to merge
16
commits into
master
Choose a base branch
from
cdanwards/2903-expo-router-screen-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a650053
fix(generate): add support for Expo Router app directory prompts for …
cdanwards 01d8bdb
Adds check for destinationDir in frontmatter or overwrite
cdanwards a405cc7
Update message to say screen
cdanwards 4111b3f
Removed warning for front-matter and updated check for expo-router
cdanwards 87f20e8
Settled on checking the package.json for the expo-router
cdanwards 65480fb
docs(generate): enhance comment to clarify Expo Router app detection …
fpena 6ed7bd8
Adress PR feedback
fpena 8104282
fix(generate): improve directory prompt for Expo Router apps by dynam…
fpena 488c334
fix(generate): update warning message to reflect dynamic directory as…
fpena b98feb0
Improve code with prettier format
fpena 47661ca
fix(generate): set initial value for directory prompt in Expo Router …
fpena ad512b9
Merge branch 'master' into cdanwards/2903-expo-router-screen-generator
jamonholmgren 27b599b
Merge branch 'master' into cdanwards/2903-expo-router-screen-generator
frankcalise 4fad5d1
fix(boilerplate): update expo-router generator templates
frankcalise df10e5a
fix(cli): new route generator template for expo-router
frankcalise 52c2328
fix(cli): non barrel generator template import paths
frankcalise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { GluegunToolbox } from "gluegun" | ||
import { boolFlag } from "../tools/flag" | ||
import { generateFromTemplate, runGenerator } from "../tools/generators" | ||
import { command, heading, p, warning } from "../tools/pretty" | ||
import { frontMatterDirectoryDir, generateFromTemplate, runGenerator } from "../tools/generators" | ||
import { command, heading, p, prettyPrompt, warning } from "../tools/pretty" | ||
import { Options } from "./new" | ||
|
||
const SUB_DIR_DELIMITER = "/" | ||
|
@@ -16,13 +16,13 @@ module.exports = { | |
} | ||
|
||
async function generate(toolbox: GluegunToolbox) { | ||
const { parameters, strings } = toolbox | ||
const { parameters, strings, filesystem, prompt } = toolbox | ||
|
||
// what generator are we running? | ||
const generator = parameters.first.toLowerCase() | ||
|
||
// check if we should override front matter dir or default dir | ||
const dir = parameters.options.dir ?? parameters.third | ||
let dir = parameters.options.dir ?? parameters.third | ||
|
||
// we need a name for this component | ||
let name = parameters.second | ||
|
@@ -52,6 +52,54 @@ async function generate(toolbox: GluegunToolbox) { | |
pascalName = pascalName.slice(0, -1 * pascalGenerator.length) | ||
command(`npx ignite-cli generate ${generator} ${pascalName}`) | ||
} | ||
// Check if src/app exists, denoting an Expo Router app | ||
if (generator === "screen") { | ||
const packageJson = filesystem.read("package.json", "json") | ||
const isExpoRouterApp = !!packageJson?.dependencies?.["expo-router"] | ||
|
||
if (isExpoRouterApp) { | ||
const directoryDirSetInFrontMatter = frontMatterDirectoryDir("screen") | ||
|
||
if (directoryDirSetInFrontMatter || dir) { | ||
heading( | ||
`It looks like you're working in a project using Expo Router, determined directory for screen from ${dir ? "override" : "template front matter"}`, | ||
) | ||
dir = dir || directoryDirSetInFrontMatter | ||
} else { | ||
const result = await prompt.ask({ | ||
type: "input", | ||
name: "dir", | ||
message: | ||
"It looks like you're working in a project using Expo Router, please enter the desired directory (e.g., src/app):", | ||
}) | ||
|
||
if (result.dir) { | ||
// Validate the directory | ||
const isValidDir = filesystem.exists(result.dir) === "dir" | ||
if (isValidDir) { | ||
dir = result.dir | ||
} else { | ||
const createDirResult = await prompt.ask({ | ||
type: "confirm", | ||
name: "createDir", | ||
message: `⚠️ Directory ${result.dir} does not exist. Would you like to create it?`, | ||
initial: true, | ||
format: prettyPrompt.format.boolean, | ||
}) | ||
|
||
if (createDirResult.createDir) { | ||
filesystem.dir(result.dir) | ||
dir = result.dir | ||
} else { | ||
warning(`⚠️ Placing screen in src/app root.`) | ||
p() | ||
dir = "src/app" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking this still needs to detect if maybe we can set it to be the default of the prompt since it's the example in the message anyway |
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// okay, let's do it! | ||
p() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment could use updating now that we changed the strategy to look at package.json