-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add import order sorting via prettier (#1392)
* added import order sorting * cli format * format www * . * done? * lint * we do a little reverse * fixed format:check writing * smoll changes * split out installers * removed eslint from base project * added eslint back * formatting * fixed linting * fixed base project * rip ci time * Update cli/template/extras/config/_prettier.config.cjs * need to test this but. * removed uneeded resolve * docs update * Moved over to a seperate prompt * yuh * spelling * this? --------- Co-authored-by: Julius Marminge <[email protected]>
- Loading branch information
1 parent
5d6108e
commit e1a5245
Showing
16 changed files
with
226 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { type Installer } from "./index.js"; | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { PKG_ROOT } from "~/consts.js"; | ||
import { addPackageDependency } from "~/utils/addPackageDependency.js"; | ||
|
||
export const installExtendedEslint: Installer = ({ projectDir }) => { | ||
addPackageDependency({ | ||
dependencies: ["eslint-config-next"], | ||
devMode: true, | ||
projectDir, | ||
}); | ||
|
||
const configDir = path.join(PKG_ROOT, "template/extras/config"); | ||
|
||
// Remove the default config | ||
fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); | ||
|
||
fs.copySync( | ||
path.join(configDir, "_eslintrc.cjs"), | ||
path.join(projectDir, ".eslintrc.cjs"), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"), | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import sortPackageJson from "sort-package-json"; | ||
import { type PackageJson } from "type-fest"; | ||
|
||
export const addPackageScript = (opts: { | ||
scripts: { name: string; value: string }[]; | ||
projectDir: string; | ||
}) => { | ||
const pkgJson = fs.readJSONSync( | ||
path.join(opts.projectDir, "package.json"), | ||
) as PackageJson; | ||
|
||
if (!pkgJson.scripts) { | ||
pkgJson.scripts = {}; | ||
} | ||
|
||
for (const script of opts.scripts) { | ||
pkgJson.scripts[script.name] = script.value; | ||
} | ||
const sortedPkgJson = sortPackageJson(pkgJson); | ||
|
||
fs.writeJSONSync(path.join(opts.projectDir, "package.json"), sortedPkgJson, { | ||
spaces: 2, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.