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

feat: add import order sorting via prettier #1392

Merged
merged 26 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
FinnDore committed May 5, 2023
commit 882177e262cdcd13d118dd3e9f4b4793777b943e
15 changes: 13 additions & 2 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { type AvailablePackages } from "~/installers/index.js";
import { availablePackages } from "~/installers/index.js";
import chalk from "chalk";
import { Command } from "commander";
import inquirer from "inquirer";
import { CREATE_T3_APP, DEFAULT_APP_NAME } from "~/consts.js";
import {
availablePackages,
type AvailablePackages,
} from "~/installers/index.js";
import { getVersion } from "~/utils/getT3Version.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";
Expand All @@ -15,6 +17,7 @@ interface CliFlags {
noInstall: boolean;
default: boolean;
importAlias: string;
strictEslintAndPrettier: boolean;

/** @internal Used in CI. */
CI: boolean;
Expand Down Expand Up @@ -47,6 +50,7 @@ const defaultOptions: CliResults = {
prisma: false,
nextAuth: false,
importAlias: "~/",
strictEslintAndPrettier: false,
},
};

Expand Down Expand Up @@ -114,6 +118,11 @@ export const runCli = async () => {
"Explicitly tell the CLI to use a custom import alias",
defaultOptions.flags.importAlias,
)
.option(
"-ep -eslint-pretteier",
"enable prettier and a strict eslint config",
defaultOptions.flags.strictEslintAndPrettier,
)
/** END CI-FLAGS */
.version(getVersion(), "-v, --version", "Display the version number")
.addHelpText(
Expand Down Expand Up @@ -153,6 +162,8 @@ export const runCli = async () => {
if (cliResults.flags.tailwind) cliResults.packages.push("tailwind");
if (cliResults.flags.prisma) cliResults.packages.push("prisma");
if (cliResults.flags.nextAuth) cliResults.packages.push("nextAuth");
if (cliResults.flags.strictEslintAndPrettier)
cliResults.packages.push("strictEslintAndPrettier");
}

// Explained below why this is in a try/catch block
Expand Down
8 changes: 7 additions & 1 deletion cli/src/installers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { type PackageManager } from "~/utils/getUserPkgManager.js";
import { envVariablesInstaller } from "~/installers/envVars.js";
import { nextAuthInstaller } from "~/installers/nextAuth.js";
import { prismaInstaller } from "~/installers/prisma.js";
import { strictEsLintAndPrettier } from "~/installers/strictEslintAndPrettier.js";
import { tailwindInstaller } from "~/installers/tailwind.js";
import { trpcInstaller } from "~/installers/trpc.js";
import { type PackageManager } from "~/utils/getUserPkgManager.js";

// Turning this into a const allows the list to be iterated over for programatically creating prompt options
// Should increase extensability in the future
Expand All @@ -13,6 +14,7 @@ export const availablePackages = [
"tailwind",
"trpc",
"envVariables",
"strictEslintAndPrettier",
] as const;
export type AvailablePackages = (typeof availablePackages)[number];

Expand Down Expand Up @@ -56,4 +58,8 @@ export const buildPkgInstallerMap = (
inUse: true,
installer: envVariablesInstaller,
},
strictEslintAndPrettier: {
inUse: true,
installer: strictEsLintAndPrettier,
},
});
74 changes: 74 additions & 0 deletions cli/src/installers/strictEslintAndPrettier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import fs from "fs-extra";
import path from "path";
import { PKG_ROOT } from "~/consts";
import { type Installer } from "~/installers/index";

// import defaultESlintConfig from "~/tesmplate/base/_eslintrc.cjs";
// import { addPackageDependency } from "~/utils/addPackageDependency.js";

export const strictEsLintAndPrettier: Installer = ({
projectDir,
packages,
}) => {
const usingTailwind = packages?.prisma.inUse;
console.log(defaultESlintConfig);
addPackageDependency({
projectDir,
dependencies: ["prettier", "@types/prettier"],
devMode: true,
});

const eslintExtra = path.join(PKG_ROOT, "template/extras/src/.eslintrc.js");
fs.copySync(eslintExtra, projectDir);
};

// const getEnvContent = (usingAuth: boolean, usingPrisma: boolean) => {
// let content = `
// # When adding additional environment variables, the schema in "/src/env.mjs"
// # should be updated accordingly.
// `
// .trim()
// .concat("\n");
//
// if (usingPrisma)
// content += `
// # Prisma
// # https://www.prisma.io/docs/reference/database-reference/connection-urls#env
// DATABASE_URL="file:./db.sqlite"
// `;
//
// if (usingAuth)
// content += `
// # Next Auth
// # You can generate a new secret on the command line with:
// # openssl rand -base64 32
// # https://next-auth.js.org/configuration/options#secret
// # NEXTAUTH_SECRET=""
// NEXTAUTH_URL="http:https://localhost:3000"
//
// # Next Auth Discord Provider
// DISCORD_CLIENT_ID=""
// DISCORD_CLIENT_SECRET=""
// `;
//
// if (!usingAuth && !usingPrisma)
// content += `
// # Example:
// # SERVERVAR="foo"
// # NEXT_PUBLIC_CLIENTVAR="bar"
// `;
//
// return content;
// };
//
// const exampleEnvContent = `
// # Since the ".env" file is gitignored, you can use the ".env.example" file to
// # build a new ".env" file when you clone the repo. Keep this file up-to-date
// # when you add new variables to \`.env\`.
//
// # This file will be committed to version control, so make sure not to have any
// # secrets in it. If you are cloning this repo, create a copy of this file named
// # ".env" and populate it with your secrets.
// `
// .trim()
//
35 changes: 35 additions & 0 deletions cli/template/extras/config/_strict-eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require("path");

/** @type {import("eslint").Linter.Config} */
const config = {
overrides: [
{
extends: [
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
files: ["*.ts", "*.tsx"],
parserOptions: {
project: path.join(__dirname, "tsconfig.json"),
},
},
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: path.join(__dirname, "tsconfig.json"),
},
plugins: ["@typescript-eslint"],
extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended"],
rules: {
"@typescript-eslint/consistent-type-imports": [
"warn",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
},
};

module.exports = config;