Skip to content

Commit

Permalink
chore: fixing linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gfidder committed Oct 17, 2023
1 parent b4688c0 commit 8ac1926
Show file tree
Hide file tree
Showing 22 changed files with 501 additions and 305 deletions.
20 changes: 14 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
plugins: [
// Provides extra useful rules:
// https://github.com/IsaacScript/isaacscript/tree/main/packages/eslint-plugin-isaacscript
"isaacscript",
"import",
],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: "latest", // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of import
tsconfigRootDir: __dirname,
project: [
"./tsconfig.eslint.json",
"./cli/tsconfig.eslint.json",
"./www/tsconfig.json",
],
},
overrides: [
{
extends: [
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
files: ["*.ts", "*.tsx"],
files: ["./cli/template/**/*.{ts,vue}"],
parserOptions: {
project: "tsconfig.json",
},
Expand All @@ -35,11 +48,6 @@ module.exports = {
},
},
],
parserOptions: {
ecmaVersion: "latest", // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of import
project: "./tsconfig.eslint.json", // Allows for the use of rules which require parserServices to be generated
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs.
"@typescript-eslint/no-explicit-any": "off",
Expand Down
26 changes: 13 additions & 13 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ export const runCli = async () => {
.description("A CLI for creating web applications with the t3 stack")
.argument(
"[dir]",
"The name of the application, as well as the name of the directory to create",
"The name of the application, as well as the name of the directory to create"
)
.option(
"--noGit",
"Explicitly tell the CLI to not initialize a new git repo in the project",
false,
false
)
.option(
"--noInstall",
"Explicitly tell the CLI to not run the package manager's install command",
false,
false
)
.option(
"-y, --default",
"Bypass the CLI and use all default options to bootstrap a new t3-app",
false,
false
)
/** START CI-FLAGS */
/**
Expand All @@ -85,25 +85,25 @@ export const runCli = async () => {
.option(
"--tailwind [boolean]",
"Experimental: Boolean value if we should install Tailwind CSS. Must be used in conjunction with `--CI`.",
(value) => !!value && value !== "false",
(value) => !!value && value !== "false"
)
/** @experimental Used for CI E2E tests. Used in conjunction with `--CI` to skip prompting. */
.option(
"--nextAuth [boolean]",
"Experimental: Boolean value if we should install NextAuth.js. Must be used in conjunction with `--CI`.",
(value) => !!value && value !== "false",
(value) => !!value && value !== "false"
)
/** @experimental - Used for CI E2E tests. Used in conjunction with `--CI` to skip prompting. */
.option(
"--prisma [boolean]",
"Experimental: Boolean value if we should install Prisma. Must be used in conjunction with `--CI`.",
(value) => !!value && value !== "false",
(value) => !!value && value !== "false"
)
/** @experimental - Used for CI E2E tests. Used in conjunction with `--CI` to skip prompting. */
.option(
"--trpc [boolean]",
"Experimental: Boolean value if we should install tRPC. Must be used in conjunction with `--CI`.",
(value) => !!value && value !== "false",
(value) => !!value && value !== "false"
)
/** END CI-FLAGS */
.version(getVersion(), "-v, --version", "Display the version number")
Expand All @@ -112,10 +112,10 @@ export const runCli = async () => {
`\n The t3 stack was inspired by ${chalk
.hex("#E8DCFF")
.bold(
"@t3dotgg",
"@t3dotgg"
)} and has been used to build awesome fullstack applications like ${chalk
.hex("#E24A8D")
.underline("https://ping.gg")} \n`,
.underline("https://ping.gg")} \n`
)
.parse(process.argv);

Expand Down Expand Up @@ -170,7 +170,7 @@ export const runCli = async () => {
// 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`,
`${CREATE_T3_APP} needs an interactive terminal to provide options`
);
logger.info(`Bootstrapping a default t3 app in ./${cliResults.appName}`);
} else {
Expand Down Expand Up @@ -246,11 +246,11 @@ const promptInstall = async (): Promise<boolean> => {
} else {
if (pkgManager === "yarn") {
logger.info(
`No worries. You can run '${pkgManager}' later to install the dependencies.`,
`No worries. You can run '${pkgManager}' later to install the dependencies.`
);
} else {
logger.info(
`No worries. You can run '${pkgManager} install' later to install the dependencies.`,
`No worries. You can run '${pkgManager} install' later to install the dependencies.`
);
}
}
Expand Down
17 changes: 9 additions & 8 deletions cli/src/helpers/git.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import chalk from "chalk";
import { execSync } from "child_process";
import path from "path";
import chalk from "chalk";
import { execa } from "execa";
import fs from "fs-extra";
import inquirer from "inquirer";
import ora from "ora";
import path from "path";

import { logger } from "~/utils/logger.js";

const isGitInstalled = (dir: string): boolean => {
Expand Down Expand Up @@ -77,7 +78,7 @@ export const initializeGit = async (projectDir: string) => {
name: "overwriteGit",
type: "confirm",
message: `${chalk.redBright.bold(
"Warning:",
"Warning:"
)} Git is already initialized in "${dirName}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,
default: false,
});
Expand All @@ -96,7 +97,7 @@ export const initializeGit = async (projectDir: string) => {
name: "initializeChildGitRepo",
type: "confirm",
message: `${chalk.redBright.bold(
"Warning:",
"Warning:"
)} "${dirName}" is already in a git worktree. Would you still like to initialize a new git repository in this directory?`,
default: false,
});
Expand All @@ -123,15 +124,15 @@ export const initializeGit = async (projectDir: string) => {
await execa("git", ["add", "."], { cwd: projectDir });
spinner.succeed(
`${chalk.green("Successfully initialized and staged")} ${chalk.green.bold(
"git",
)}\n`,
"git"
)}\n`
);
} catch (error) {
// Safeguard, should be unreachable
spinner.fail(
`${chalk.bold.red(
"Failed:",
)} could not initialize git. Update git to the latest version!\n`,
"Failed:"
)} could not initialize git. Update git to the latest version!\n`
);
}
};
12 changes: 6 additions & 6 deletions cli/src/helpers/installDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import chalk from "chalk";
import { execa } from "execa";
import ora, { Ora } from "ora";

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

type Options = {
interface Options {
projectDir: string;
};
}

/*eslint-disable @typescript-eslint/no-floating-promises*/
const runInstallCommand = async (
pkgManager: PackageManager,
projectDir: string,
projectDir: string
): Promise<Ora | null> => {
switch (pkgManager) {
// When using npm, inherit the stderr stream so that the progress bar is shown
Expand Down Expand Up @@ -76,7 +76,7 @@ export const installDependencies = async ({ projectDir }: Options) => {

// If the spinner was used to show the progress, use succeed method on it
// If not, use the succeed on a new spinner
(installSpinner || ora()).succeed(
chalk.green("Successfully installed dependencies!\n"),
(installSpinner ?? ora()).succeed(
chalk.green("Successfully installed dependencies!\n")
);
};
4 changes: 2 additions & 2 deletions cli/src/helpers/installPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const installPackages = (options: InstallPackagesOptions) => {
pkgOpts.installer(options);
spinner.succeed(
chalk.green(
`Successfully setup boilerplate for ${chalk.green.bold(name)}`,
),
`Successfully setup boilerplate for ${chalk.green.bold(name)}`
)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/helpers/logNextSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const logNextSteps = ({

if (packages?.prisma.inUse) {
logger.info(
` ${pkgManager === "npm" ? "npx" : pkgManager} prisma db push`,
` ${pkgManager === "npm" ? "npx" : pkgManager} prisma db push`
);
}

Expand Down
12 changes: 5 additions & 7 deletions cli/src/helpers/scaffoldProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export const scaffoldProject = async ({
if (fs.readdirSync(projectDir).length === 0) {
if (projectName !== ".") {
spinner.info(
`${chalk.cyan.bold(
projectName,
)} exists but is empty, continuing...\n`,
`${chalk.cyan.bold(projectName)} exists but is empty, continuing...\n`
);
}
} else {
Expand All @@ -41,7 +39,7 @@ export const scaffoldProject = async ({
name: "overwriteDir",
type: "list",
message: `${chalk.redBright.bold("Warning:")} ${chalk.cyan.bold(
projectName,
projectName
)} already exists and isn't empty. How would you like to proceed?`,
choices: [
{
Expand Down Expand Up @@ -88,7 +86,7 @@ export const scaffoldProject = async ({

if (overwriteDir === "clear") {
spinner.info(
`Emptying ${chalk.cyan.bold(projectName)} and creating t3 app..\n`,
`Emptying ${chalk.cyan.bold(projectName)} and creating t3 app..\n`
);
fs.emptyDirSync(projectDir);
}
Expand All @@ -100,13 +98,13 @@ export const scaffoldProject = async ({
fs.copySync(srcDir, projectDir);
fs.renameSync(
path.join(projectDir, "_gitignore"),
path.join(projectDir, ".gitignore"),
path.join(projectDir, ".gitignore")
);

const scaffoldedName =
projectName === "." ? "App" : chalk.cyan.bold(projectName);

spinner.succeed(
`${scaffoldedName} ${chalk.green("scaffolded successfully!")}\n`,
`${scaffoldedName} ${chalk.green("scaffolded successfully!")}\n`
);
};
4 changes: 2 additions & 2 deletions cli/src/helpers/selectBoilerplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const selectAuthShowcaseFile = ({
}: SelectBoilerplateProps) => {
const componentFileDir = path.join(
PKG_ROOT,
"template/extras/src/components/AuthShowcase",
"template/extras/src/components/AuthShowcase"
);

const usingTRPC = packages.trpc.inUse;
Expand Down Expand Up @@ -73,7 +73,7 @@ export const selectNuxtConfigFile = ({
}: SelectBoilerplateProps) => {
const configFileDir = path.join(
PKG_ROOT,
"template/extras/config/nuxt-config",
"template/extras/config/nuxt-config"
);

const usingTRPC = packages.trpc.inUse;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/installers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type PkgInstallerMap = {
};

export const buildPkgInstallerMap = (
packages: AvailablePackages[],
packages: AvailablePackages[]
): PkgInstallerMap => ({
nextAuth: {
inUse: packages.includes("nextAuth"),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/installers/nextAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const nextAuthInstaller: Installer = ({ projectDir, packages }) => {
const apiHandlerSrc = path.join(
extrasDir,
"src/server/api/auth",
packages?.prisma.inUse ? "with-prisma.ts" : "base.ts",
packages?.prisma.inUse ? "with-prisma.ts" : "base.ts"
);

const apiHandlerDest = path.join(projectDir, "server/api/auth/[...].ts");
Expand Down
2 changes: 1 addition & 1 deletion cli/src/installers/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const prismaInstaller: Installer = ({ projectDir, packages }) => {
const schemaSrc = path.join(
extrasDir,
"prisma/schema",
packages?.nextAuth.inUse ? "with-auth.prisma" : "base.prisma",
packages?.nextAuth.inUse ? "with-auth.prisma" : "base.prisma"
);
const schemaDest = path.join(projectDir, "prisma/schema.prisma");

Expand Down
4 changes: 2 additions & 2 deletions cli/src/installers/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export const trpcInstaller: Installer = ({ projectDir, packages }) => {
const exampleRouterSrc = path.join(
extrasDir,
"src/server/trpc/routers/example",
exampleRouterFile,
exampleRouterFile
);
const exampleRouterDest = path.join(
projectDir,
"server/trpc/routers/example.ts",
"server/trpc/routers/example.ts"
);

fs.copySync(apiHandlerSrc, apiHandlerDest);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/utils/addPackageDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const addPackageDependency = (opts: {
const { dependencies, devMode, projectDir } = opts;

const pkgJson = fs.readJSONSync(
path.join(projectDir, "package.json"),
path.join(projectDir, "package.json")
) as PackageJson;

dependencies.forEach((pkgName) => {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/utils/addScriptDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const addScriptDependency = (opts: {
const { script, projectDir } = opts;

const pkgJson = fs.readJSONSync(
path.join(projectDir, "package.json"),
path.join(projectDir, "package.json")
) as PackageJson;

if (pkgJson.scripts?.postinstall) {
Expand Down
Loading

0 comments on commit 8ac1926

Please sign in to comment.