forked from t3-oss/create-t3-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prettier.ts
55 lines (50 loc) · 1.51 KB
/
prettier.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { type Installer } from "../installers/index.js";
import { type AvailableDependencies } from "./dependencyVersionMap.js";
import fs from "fs-extra";
import path from "path";
import { PKG_ROOT } from "~/consts.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";
import { addPackageScript } from "~/utils/addPackageScript.js";
export const installPrettier: Installer = ({ projectDir, packages }) => {
const packeagesToInstall: AvailableDependencies[] = [
"prettier",
"@types/prettier",
"@ianvs/prettier-plugin-sort-imports",
];
if (packages?.tailwind.inUse) {
packeagesToInstall.push("prettier-plugin-tailwindcss");
}
addPackageDependency({
projectDir,
dependencies: packeagesToInstall,
devMode: true,
});
addPackageScript({
projectDir,
scripts: [
{
name: "format",
value: "pnpm format:check --write",
},
{
name: "format:check",
value:
"pnpm prettier --check --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern",
},
],
});
if (packages?.tailwind.inUse) {
fs.copySync(
path.join(
PKG_ROOT,
"template/extras/config/prettier-with-tailwind.config.cjs",
),
path.join(projectDir, "prettier.config.cjs"),
);
} else {
fs.copySync(
path.join(PKG_ROOT, "template/extras/config/_prettier.config.cjs"),
path.join(projectDir, "prettier.config.cjs"),
);
}
};