Skip to content
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

Adding in cli args, refactoring file structure, and changing prompts for inquirer #58

Merged
merged 24 commits into from
Jun 27, 2022

Conversation

MWhite-22
Copy link
Member

I went a little nuts, so, apologies, but i'll outline all the rationale below:

Accepting args (#37 #50):

  • Added commander as a parsing agent for the command line
  • the first non-flagged argument will used as the app name and directory name
  • Flags include:
    • -y or --default: Skips over the prompts and goes straight to initializing a new repo with opinionated defaults. Can still accept a directory argument so npx create-t3-app myApp -y will create a "default" app named "myApp" inside the "./myApp" directory
    • --noGit: Skip the git initialization step
    • -v or --version: Print the current create-t3-app version
    • -h or --help: All of this and more in a nicely formatted help menu

Inquirer vs. Prompts:

  • Inquirer has a much smaller package size and allows for assigning some generic types into the prompt instantiation.
  • Inquirer is slowly moving over to a full TS package where type safety will be massively improved
  • Prompts was weirdly not exiting the CLI if the user pressed ctrl-c mid questions. Instead, it jumped straight into trying to run the scaffold scripts, which can't be cancelled once started. With inquirer, the user can press ctrl-c any time before the scaffolding starts, and the cli will correctly exit
  • Inquirer comes with a check that the terminal is interactive. If not, it will throw a specific error. The current implementation catches that error, and will scaffold a default app for the user. This should help is someone not using an interactive terminal tries to use the cli and doesn't understand why no prompts are coming up.

Add packages as a list, not individual questions (#42):

  • Changed this question type to select from a list, rather than answer one by one
  • Refactoring some of the installer types into an as const object means this list can be quickly and easily expanded in a type safe way

A few bug fixes for ora (#47):

  • Ora was blocking the scaffold function from asking the user if they wanted to overwrite a directory that already existed. Fixed those issues, and a few stylistic changes that bring the entire cli experience to a cohesive feel.

That should be everything. If you have any questions, please ask away.

@MWhite-22
Copy link
Member Author

MWhite-22 commented Jun 27, 2022

On top of the above, I tried finding a way to easily add in a --noInstall flag to skip the actual install part of the scaffolding, but with the current architecture thats going to be really tough.

One thing we should think about doing in the future is moving over to a true templated file structure that gets hydrated before being copied over. That way we aren't maintaining copies of files just for different setup methods, and can easily update to new structures (ala the new next pages rfc) once they come out

@juliusmarminge
Copy link
Member

On top of the above, I tried finding a way to easily add in a --noInstall flag to skip the actual install part of the scaffolding, but with the current architecture thats going to be really tough.

I guess a hack would be to just run a rm -rf node_modules afterwards. Can't believe there isn't an native argument like npm install --add-only for adding the latest version of a package to the package.json...

@MWhite-22
Copy link
Member Author

I thought about doing that temporarily, but feels SUPER hacky.

@nexxeln
Copy link
Member

nexxeln commented Jun 27, 2022

I think --noInstall can be implemented later when the layouts RFC thing comes out. We will have to kind of rewrite then anyway. For now I think not having this is fine.

@nexxeln
Copy link
Member

nexxeln commented Jun 27, 2022

@MWhite-22 Can you also please unselect all of the prompts by default

@MWhite-22
Copy link
Member Author

MWhite-22 commented Jun 27, 2022

@MWhite-22 Can you also please unselect all of the prompts by default

Just confirming, if someone does npx create-t3-app -y or tries to call it from a non-interactive terminal, they get nothing more than the base next app.

Thats the way you want it @nexxeln?

@nexxeln
Copy link
Member

nexxeln commented Jun 27, 2022

No, what I meant was that in the prompts to select the packages, initially nothing should be selected.

@MWhite-22
Copy link
Member Author

Right right, but I am building those choices programmatically from the "default" option.

So the new build will have all packages by -y default, but if they user is going through the prompts, the prompts will start off will all packages deselected. Correct?

@nexxeln
Copy link
Member

nexxeln commented Jun 27, 2022

Yes you got it.

Incorporating results into prompt steps
Utility functions with no sideeffects moved to utils

Project creators and sccafolders stay in helpers
Inquirer has:
- a significantly smaller bundle size
- more frequently updated
- more then 2x stars in GH
- is moving (slowly) to a full TS package
Should prevent mixing absolute imports with relative imports
Rename the two installPackage functions to be more descriptive

Move package installer types and creation of installer map into ./installers directory
…Project

Changed spinner stop to spinner succeed and fail when appropriate
Blue/cyan seems to be the more fitting color scheme then bright red
See comments. Will create an issue to discuss further
@MWhite-22
Copy link
Member Author

Rebased to the new readme doc

@MWhite-22
Copy link
Member Author

Done and tested. Working as intended.

@nexxeln
Copy link
Member

nexxeln commented Jun 27, 2022

Looks good! Very good PR. Thank you so much

@nexxeln nexxeln merged commit 08d9a6a into t3-oss:main Jun 27, 2022
@MWhite-22 MWhite-22 deleted the feat/cli_args branch June 27, 2022 19:53
@juliusmarminge
Copy link
Member

Looked this over and had a thought about this:

// src/cli/index:133
  } catch (err) {
    // If the user is not calling create-t3-app from an interactive terminal, inquirer will throw an error with isTTYError = true
    // If this happens, we catch the error, tell the user what has happened, and then contiue to run the program with a default t3 app
    // eslint-disable-next-line -- Otherwise we have to do some fancy namespace extension logic on the Error type which feels overkill for one line
    if (err instanceof Error && (err as any).isTTYError) {
      logger.warn(
        `${CREATE_T3_APP} needs an interactive terminal to provide options`,
      );
      logger.info(`Bootsrapping a default t3 app in ./${DEFAULT_APP_NAME}`);
    } else {
      throw err;
    }
  }

and more specifically

logger.info(`Bootsrapping a default t3 app in ./${DEFAULT_APP_NAME}`);

If I have an un-interactive shell and run npx create-t3-app appxyz, are we not able to catch the name argument and use that?

@MWhite-22
Copy link
Member Author

It does! Any name arg is passed in still, but the interactive part (aka: the fun language selector, and the packages selector) will not be viewable.

@MWhite-22
Copy link
Member Author

Never mind, I now see what you mean. Updating the string template to ${cliResults.appName}

@nexxeln nexxeln mentioned this pull request Jun 28, 2022
devvianto605 pushed a commit to devvianto605/create-devviantex-nextjs-app-deprecated that referenced this pull request Jun 9, 2024
Adding in cli args, refactoring file structure, and changing prompts for inquirer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants