Skip to content

Commit c5041eb

Browse files
Merge pull request #203 from laststance/fix/template-files-path
2 parents b121195 + e864e37 commit c5041eb

20 files changed

+1353
-10
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Project Overview
7+
8+
The `prettier-husky-lint-staged-installer` is a CLI tool that automatically sets up Prettier, Husky, and lint-staged in a project to enable automatic code formatting on pre-commit.
9+
10+
## Key Components
11+
12+
- [bin/cli.js](mdc:bin/cli.js) - The main CLI entry point that performs the installation
13+
- [package.json](mdc:package.json) - Project configuration and dependencies
14+
15+
## Main Features
16+
17+
- Detects package manager (npm, pnpm, or bun) automatically
18+
- Installs Prettier, Husky, and lint-staged as dev dependencies
19+
- Sets up a pre-commit hook that runs Prettier on staged files
20+
- Configures lint-staged to run Prettier on all file types
21+
- Copies default Prettier configuration files to the project
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Installation Workflow
7+
8+
The installer follows a specific workflow to set up the formatting tools:
9+
10+
1. **Detection** - Checks which package manager is used (npm, pnpm, or bun) by looking for lock files
11+
2. **Installation** - Installs husky, lint-staged, and prettier as dev dependencies
12+
3. **Husky Setup** - Initializes husky
13+
4. **Configuration** - Sets up lint-staged in package.json
14+
5. **File Setup** - Copies .prettierrc and .prettierignore files
15+
6. **Hook Setup** - Configures the pre-commit hook to run lint-staged
16+
17+
This process is handled in [bin/cli.js](mdc:bin/cli.js) with detailed steps for each package manager.

.cursor/rules/03-dependencies.mdc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Project Dependencies
7+
8+
## Runtime Dependencies
9+
10+
- **@clack/prompts** - Terminal UI library for user interactions
11+
- **execa** - Process execution library for running commands
12+
13+
## DevDependencies
14+
15+
- **eslint** with various plugins - For code linting
16+
- **prettier** - Code formatting
17+
- **husky** - Git hooks management
18+
- **lint-staged** - Run linters on staged files
19+
- **typescript** - Type checking
20+
21+
The [package.json](mdc:package.json) file contains the complete list of dependencies.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Package Manager Handling
7+
8+
The installer supports three package managers automatically:
9+
10+
## Detection Logic
11+
12+
The CLI detects which package manager is being used by checking for lock files:
13+
- `package-lock.json` → npm
14+
- `pnpm-lock.yaml` → pnpm
15+
- `bun.lockb` → bun
16+
17+
## Manager-Specific Commands
18+
19+
Each package manager requires different commands:
20+
21+
### npm
22+
```javascript
23+
precommitFileBody = 'npx lint-staged'
24+
await $`npm install --save-dev husky lint-staged prettier`
25+
await $`npx husky init`
26+
```
27+
28+
### pnpm
29+
```javascript
30+
precommitFileBody = 'pnpm lint-staged'
31+
await $`pnpm install --save-dev husky lint-staged prettier`
32+
await $`pnpm exec husky init`
33+
```
34+
35+
### bun
36+
```javascript
37+
precommitFileBody = 'bunx lint-staged'
38+
await $`bun install -D husky lint-staged prettier`
39+
await $`bunx husky init`
40+
```
41+
42+
This detection and execution logic is implemented in [bin/cli.js](mdc:bin/cli.js).
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Coding Standards
7+
8+
This project follows specific coding standards enforced by its own tools:
9+
10+
## Prettier Configuration
11+
12+
The project uses a standard Prettier configuration defined in [.prettierrc](mdc:.prettierrc):
13+
14+
```json
15+
{
16+
"semi": false,
17+
"singleQuote": true,
18+
"tabWidth": 2,
19+
"trailingComma": "all"
20+
}
21+
```
22+
23+
## ESLint Configuration
24+
25+
The project uses ESLint with TypeScript support as defined in [.eslintrc.cjs](mdc:.eslintrc.cjs).
26+
27+
## Git Hooks
28+
29+
The project uses Husky to manage Git hooks:
30+
- Pre-commit hook runs Prettier on staged files via lint-staged
31+
32+
## Scripts
33+
34+
Common development scripts are available in [package.json](mdc:package.json):
35+
- `npm run prettier` - Run Prettier on all files
36+
- `npm run lint` - Run ESLint
37+
- `npm run lint:fix` - Run ESLint with auto-fix
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Contribution Guidelines
7+
8+
This project welcomes contributions from the community. The contribution process is documented in:
9+
10+
- [CONTRIBUTING.md](mdc:CONTRIBUTING.md) - General contribution guidelines
11+
- [CODE_OF_CONDUCT.md](mdc:CODE_OF_CONDUCT.md) - Community code of conduct
12+
13+
## Development Workflow
14+
15+
1. Fork the repository
16+
2. Create a feature branch
17+
3. Make your changes
18+
4. Ensure the code passes linting and formatting rules
19+
5. Create a pull request
20+
21+
## Release Process
22+
23+
The project uses [release-it](mdc:https:/github.com/release-it/release-it) for managing releases, configured in [.release-it.json](mdc:.release-it.json).
24+
25+
Run `npm run release` to create a new release, which will:
26+
1. Bump the version
27+
2. Create a git tag
28+
3. Push to GitHub
29+
4. Publish to npm
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Usage Examples
7+
8+
The `prettier-husky-lint-staged-installer` can be run using different package managers.
9+
10+
## Running with npx (npm)
11+
12+
```bash
13+
npx prettier-husky-lint-staged-installer
14+
```
15+
16+
## Running with pnpm
17+
18+
```bash
19+
pnpm dlx prettier-husky-lint-staged-installer
20+
```
21+
22+
## Running with bun
23+
24+
```bash
25+
bunx prettier-husky-lint-staged-installer
26+
```
27+
28+
## What Gets Installed
29+
30+
After running the installer, your project will have:
31+
32+
1. Husky, lint-staged, and Prettier installed as dev dependencies
33+
2. A pre-commit hook that runs Prettier on staged files
34+
3. A `.prettierrc` config file with sensible defaults
35+
4. A `.prettierignore` file
36+
5. Package.json scripts for running Prettier manually
37+
38+
## Resulting Configuration
39+
40+
The installer adds this to your package.json:
41+
42+
```json
43+
"lint-staged": {
44+
"*": "prettier --ignore-unknown --write"
45+
},
46+
"scripts": {
47+
"prettier": "prettier --ignore-unknown --write ."
48+
}
49+
```
50+
51+
And creates a pre-commit hook to run lint-staged.

.github/actions/prepare/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ name: Prepare
44

55
runs:
66
steps:
7-
- uses: pnpm/action-setup@v2
7+
- uses: pnpm/action-setup@v4
88
with:
9-
version: 9
10-
- uses: actions/setup-node@v3
9+
version: 10
10+
- uses: actions/setup-node@v4
1111
with:
1212
cache: pnpm
1313
node-version: '20'

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: ./.github/actions/prepare
15+
- name: Run tests
16+
run: pnpm test

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://json.schemastore.org/prettierrc",
2+
"$schema": "https://json.schemastore.org/prettierrc",
33
"singleQuote": true,
44
"semi": false
55
}

0 commit comments

Comments
 (0)