Skip to content

Commit

Permalink
format scaffolded project after creation and check in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansunbury committed Jan 15, 2025
1 parent d27c29f commit 6ad3205
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ jobs:
appRouter: ["true", "false"]
drizzle: ["true", "false"]
dbType: ["planetscale", "sqlite", "mysql", "postgres"]
# linter: ["eslint", "biome"]
eslint: ["true", "false"]
biome: ["true", "false"]

name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }}"
name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }}-${{matrix.eslint}}-${{matrix.biome}}"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -45,7 +46,7 @@ jobs:
- name: Check valid matrix
id: matrix-valid
run: |
echo "continue=${{ (matrix.prisma == 'false' || matrix.drizzle == 'false') && (matrix.drizzle == 'true' || matrix.prisma == 'true' || matrix.dbType == 'sqlite') }}" >> $GITHUB_OUTPUT
echo "continue=${{ (matrix.prisma == 'false' || matrix.drizzle == 'false') && (matrix.drizzle == 'true' || matrix.prisma == 'true' || matrix.dbType == 'sqlite') && (matrix.eslint == 'false' || matrix.biome == 'false') && (matrix.eslint == 'true' || matrix.biome == 'true')}}" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup
if: ${{ steps.matrix-valid.outputs.continue == 'true' }}
Expand All @@ -56,21 +57,30 @@ jobs:
# has to be scaffolded outside the CLI project so that no lint/tsconfig are leaking
# through. this way it ensures that it is the app's configs that are being used
# 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 }} --eslint
- 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 }} --eslint=${{ matrix.eslint }} --biome=${{ matrix.biome }}
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
- run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }}-${{matrix.eslint}}-${{matrix.biome}} && pnpm build
if: ${{ steps.matrix-valid.outputs.continue == 'true' }}
env:
AUTH_SECRET: foo
AUTH_DISCORD_ID: bar
AUTH_DISCORD_SECRET: baz
SKIP_ENV_VALIDATION: true

# setup eslint correctly, and run it in correct directory
- run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }} && pnpm format:check && pnpm check
if: ${{ steps.matrix-valid.outputs.continue == 'true' }}
# Check formatting for eslint / prettier
- run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }}-${{matrix.eslint}}-${{matrix.biome}} && pnpm format:check && pnpm check
if: ${{ steps.matrix-valid.outputs.continue == 'true' && matrix.eslint == 'true' }}
env:
AUTH_SECRET: foo
AUTH_DISCORD_ID: bar
AUTH_DISCORD_SECRET: baz
SKIP_ENV_VALIDATION: true

# Check formatting for biome
- run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }}-${{matrix.eslint}}-${{matrix.biome}} && pnpm check
if: ${{ steps.matrix-valid.outputs.continue == 'true' && matrix.biome == 'true' }}
env:
AUTH_SECRET: foo
AUTH_DISCORD_ID: bar
Expand Down
33 changes: 33 additions & 0 deletions cli/src/helpers/format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import chalk from "chalk";
import { execa } from "execa";
import ora from "ora";

import type { PackageManager } from "~/utils/getUserPkgManager.js";

Check failure on line 5 in cli/src/helpers/format.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer using inline type specifiers instead of a top-level type-only import
import { logger } from "~/utils/logger.js";

// Runs format and lint command to ensure created repository is tidy upon creation
export const formatProject = async ({
pkgManager,
projectDir,
eslint,
biome,
}: {
pkgManager: PackageManager;
projectDir: string;
eslint: boolean;
biome: boolean;
}) => {
logger.info("Formatting project...");
const spinner = ora("Running format command\n").start();

if (eslint) {
await execa(pkgManager, ["format:write"], {
cwd: projectDir,
});
} else if (biome) {
await execa(pkgManager, ["check:unsafe"], {
cwd: projectDir,
});
}
spinner.succeed(`${chalk.green("Successfully formatted project")}`);
};
5 changes: 3 additions & 2 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";
import { renderTitle } from "~/utils/renderTitle.js";
import { formatProject } from "./helpers/format.js";
import { installDependencies } from "./helpers/installDependencies.js";
import { getVersion } from "./utils/getT3Version.js";
import {
Expand All @@ -38,7 +39,7 @@ const main = async () => {
const {
appName,
packages,
flags: { noGit, noInstall, importAlias, appRouter },
flags: { noGit, noInstall, importAlias, appRouter, eslint, biome },
databaseProvider,
} = await runCli();

Expand Down Expand Up @@ -89,7 +90,7 @@ const main = async () => {
await initializeGit(projectDir);
}

// TODO run format command
await formatProject({ pkgManager, projectDir, eslint, biome });

await logNextSteps({
projectName: appDir,
Expand Down

0 comments on commit 6ad3205

Please sign in to comment.