From fe85a233c62af607e8a39bf5ca1b2358d43c6587 Mon Sep 17 00:00:00 2001 From: immi Date: Wed, 16 Oct 2024 17:17:54 +0500 Subject: [PATCH] feat: add more `scripts` (#1997) --- .changeset/red-rules-turn.md | 5 +++++ cli/src/installers/tailwind.ts | 14 ++++++++++++++ cli/template/base/package.json | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .changeset/red-rules-turn.md diff --git a/.changeset/red-rules-turn.md b/.changeset/red-rules-turn.md new file mode 100644 index 0000000000..becc31f97e --- /dev/null +++ b/.changeset/red-rules-turn.md @@ -0,0 +1,5 @@ +--- +"create-t3-app": patch +--- + +Add more scripts in `package.json` diff --git a/cli/src/installers/tailwind.ts b/cli/src/installers/tailwind.ts index e692392823..c50ab68dc7 100644 --- a/cli/src/installers/tailwind.ts +++ b/cli/src/installers/tailwind.ts @@ -1,5 +1,6 @@ import path from "path"; import fs from "fs-extra"; +import { type PackageJson } from "type-fest"; import { PKG_ROOT } from "~/consts.js"; import { type Installer } from "~/installers/index.js"; @@ -31,8 +32,21 @@ export const tailwindInstaller: Installer = ({ projectDir }) => { const cssSrc = path.join(extrasDir, "src/styles/globals.css"); const cssDest = path.join(projectDir, "src/styles/globals.css"); + // add format:* scripts to package.json + const packageJsonPath = path.join(projectDir, "package.json"); + + const packageJsonContent = fs.readJSONSync(packageJsonPath) as PackageJson; + packageJsonContent.scripts = { + ...packageJsonContent.scripts, + "format:write": 'prettier --write "**/*.{ts,tsx,js,jsx,mdx}" --cache', + "format:check": 'prettier --check "**/*.{ts,tsx,js,jsx,mdx}" --cache', + }; + fs.copySync(twCfgSrc, twCfgDest); fs.copySync(postcssCfgSrc, postcssCfgDest); fs.copySync(cssSrc, cssDest); fs.copySync(prettierSrc, prettierDest); + fs.writeJSONSync(packageJsonPath, packageJsonContent, { + spaces: 2, + }); }; diff --git a/cli/template/base/package.json b/cli/template/base/package.json index e13a5485ef..fff75519f8 100644 --- a/cli/template/base/package.json +++ b/cli/template/base/package.json @@ -7,7 +7,11 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "lint:fix": "next lint --fix", + "check": "next lint && tsc --noEmit", + "preview": "next build && next start", + "typecheck": "tsc --noEmit" }, "dependencies": { "@t3-oss/env-nextjs": "^0.10.1",