Skip to content

Commit

Permalink
fix: updated --dbProvider CI flag to parse configured databases #1865 (
Browse files Browse the repository at this point in the history
…#1867)

Co-authored-by: juliusmarminge <[email protected]>
  • Loading branch information
xelacast and juliusmarminge authored May 7, 2024
1 parent de2ad0b commit 304a67f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-ghosts-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

Parsed --dbprovider flag correctly and added related error message
3 changes: 2 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ jobs:
# FIXME: this is a bit hacky, would rather have --packages=trpc,tailwind,... but not sure how to setup the matrix for that
- run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} --drizzle=${{ matrix.drizzle }} --appRouter=${{ matrix.appRouter }} --dbProvider=${{ matrix.dbType }}
if: ${{ steps.matrix-valid.outputs.continue == 'true' }}
# can't use default mysql string cause t3-env blocks that
- run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }} && pnpm build
if: ${{ steps.matrix-valid.outputs.continue == 'true' }}
env:
NEXTAUTH_SECRET: foo
DATABASE_URL: mysql://root:root@localhost:3306/test # can't use url from example env cause we block that in t3-env
DISCORD_CLIENT_ID: bar
DISCORD_CLIENT_SECRET: baz
SKIP_ENV_VALIDATION: true

build-t3-app-with-bun:
runs-on: ubuntu-latest
Expand Down
24 changes: 17 additions & 7 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface CliFlags {
nextAuth: boolean;
/** @internal Used in CI. */
appRouter: boolean;
/** @internal Used in CI. */
dbProvider: DatabaseProvider;
}

interface CliResults {
Expand All @@ -59,6 +61,7 @@ const defaultOptions: CliResults = {
nextAuth: false,
importAlias: "~/",
appRouter: false,
dbProvider: "sqlite",
},
databaseProvider: "sqlite",
};
Expand Down Expand Up @@ -135,7 +138,7 @@ export const runCli = async (): Promise<CliResults> => {
`Choose a database provider to use. Possible values: ${databaseProviders.join(
", "
)}`,
defaultOptions.flags.importAlias
defaultOptions.flags.dbProvider
)
.option(
"--appRouter [boolean]",
Expand Down Expand Up @@ -180,18 +183,25 @@ export const runCli = async (): Promise<CliResults> => {
if (cliResults.flags.prisma) cliResults.packages.push("prisma");
if (cliResults.flags.drizzle) cliResults.packages.push("drizzle");
if (cliResults.flags.nextAuth) cliResults.packages.push("nextAuth");

if (cliResults.flags.prisma && cliResults.flags.drizzle) {
// We test a matrix of all possible combination of packages in CI. Checking for impossible
// combinations here and exiting gracefully is easier than changing the CI matrix to exclude
// invalid combinations. We are using an "OK" exit code so CI continues with the next combination.
logger.warn("Incompatible combination Prisma + Drizzle. Exiting.");
process.exit(0);
}
if (databaseProviders.includes(cliResults.flags.dbProvider) === false) {
logger.warn(
`Incompatible database provided. Use: ${databaseProviders.join(", ")}. Exiting.`
);
process.exit(0);
}

cliResults.databaseProvider = cliResults.packages.includes("drizzle")
? "planetscale"
: "sqlite";
cliResults.databaseProvider =
cliResults.packages.includes("drizzle") ||
cliResults.packages.includes("prisma")
? cliResults.flags.dbProvider
: "sqlite";

return cliResults;
}
Expand All @@ -203,8 +213,8 @@ export const runCli = async (): Promise<CliResults> => {
// Explained below why this is in a try/catch block
try {
if (process.env.TERM_PROGRAM?.toLowerCase().includes("mintty")) {
logger.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
logger.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
can provide the arguments from the CLI directly: https://create.t3.gg/en/installation#experimental-usage to skip the prompts.`);

throw new IsTTYError("Non-interactive environment");
Expand Down
24 changes: 17 additions & 7 deletions www/src/pages/en/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,34 @@ After your app has been scaffolded, check out the [first steps](/en/usage/first-

For our CI, we have some experimental flags that allow you to scaffold any app without any prompts. If this use case applies to you, you can use these flags. Please note that these flags are experimental and may change in the future without following semver versioning.

| Flag | Description |
| ------------ | ----------------------------------- |
| `--CI` | Let the CLI know you're in CI mode |
| `--trpc` | Include tRPC in the project |
| `--prisma` | Include Prisma in the project |
| `--nextAuth` | Include NextAuth.js in the project |
| `--tailwind` | Include Tailwind CSS in the project |
| Flag | Description |
| ------------------------- | -------------------------------------------- |
| `--CI` | Let the CLI know you're in CI mode |
| `--trpc` | Include tRPC in the project |
| `--prisma` | Include Prisma in the project |
| `--drizzle` | Inlcude Drizzle in the project |
| `--nextAuth` | Include NextAuth.js in the project |
| `--tailwind` | Include Tailwind CSS in the project |
| `--dbProvider [provider]` | Include a configured database in the project |

<Callout type="warning">
If you don't provide the `CI` flag, the rest of these flags have no effect.
</Callout>

You don't need to explicitly opt-out of the packages you don't want. However, if you prefer to be explicit, you can pass `false`, e.g. `--nextAuth false`.

The --dbProvider command has 4 database values to choose from: mysql, postgres, planetscale, sqlite. If the command is not provided the default value will be sqlite.

### Example

The following would scaffold a T3 App with tRPC and Tailwind CSS.

```bash
pnpm dlx create-t3-app@latest --CI --trpc --tailwind
```

The following would scaffold a T3 App with NextAuth.js, Tailwind CSS, Drizzle, and PostgreSQL.

```bash
pnpm dlx create-t3-app@latest --CI --nextAuth --tailwind --drizzle --dbProvider postgres
```

0 comments on commit 304a67f

Please sign in to comment.