-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactoring file structure, readme docs
- Loading branch information
Showing
11 changed files
with
249 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
# run directly, without docker support | ||
# pnpm commitlint --edit "${1}" | ||
|
||
# through docker-compose | ||
pnpm commitlint --edit "${1}" |
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,33 @@ | ||
// @ts-check | ||
|
||
/** | ||
* This files overrides the base lint-staged.config.js present in the root directory. | ||
* It allows to run eslint based the package specific requirements. | ||
* {@link https://github.com/okonet/lint-staged#how-to-use-lint-staged-in-a-multi-package-monorepo} | ||
* {@link https://github.com/belgattitude/nextjs-monorepo-example/blob/main/docs/about-lint-staged.md} | ||
*/ | ||
|
||
const { concatFilesForPrettier, getEslintFixCmd } = require('../../lint-staged.common.js') | ||
|
||
/** | ||
* @type {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} | ||
*/ | ||
const rules = { | ||
'**/*.{js,jsx,ts,tsx,mjs,cjs}': filenames => { | ||
return getEslintFixCmd({ | ||
cwd: __dirname, | ||
fix: true, | ||
cache: true, | ||
// when auto-fixing staged-files a good tip is to disable react-hooks/exhaustive-deps, cause | ||
// a change here can potentially break things without proper visibility. | ||
rules: ['react-hooks/exhaustive-deps: off'], | ||
maxWarnings: 25, | ||
files: filenames, | ||
}) | ||
}, | ||
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': filenames => { | ||
return [`prettier --write ${concatFilesForPrettier(filenames)}`] | ||
}, | ||
} | ||
|
||
module.exports = rules |
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 |
---|---|---|
@@ -1,71 +1,188 @@ | ||
# Commitlint Config | ||
<br> | ||
|
||
Shareable commitlint configuration. | ||
<div align="center"> | ||
<img width="456" src="https://raw.githubusercontent.com/wayofdev/next-starter-tpl/master/assets/logo.gh-light-mode-only.png#gh-light-mode-only"> | ||
<img width="456" src="https://raw.githubusercontent.com/wayofdev/next-starter-tpl/master/assets/logo.gh-dark-mode-only.png#gh-dark-mode-only"> | ||
</div> | ||
|
||
## Install | ||
<br> | ||
|
||
<br> | ||
|
||
<div align="center"> | ||
<a href="https://actions-badge.atrox.dev/wayofdev/npm-shareable-configs/goto"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fwayofdev%2Fnext-starter-tpl%2Fbadge&style=flat-square"/></a> | ||
<a href="https://www.npmjs.com/package/@wayofdev/commitlint-config"><img alt="GitHub package.json version" src="https://img.shields.io/npm/v/@wayofdev/commitlint-config?style=flat-square"></a> | ||
<a href="https://www.npmjs.com/package/@wayofdev/commitlint-config?activeTab=versions"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@wayofdev/commitlint-config?style=flat-square"></a> | ||
<a href="LICENSE.md"><img src="https://img.shields.io/github/license/wayofdev/npm-shareable-configs.svg?style=flat-square&color=blue" alt="Software License"/></a> | ||
</div> | ||
|
||
<br> | ||
|
||
# Shareable Commitlint Config | ||
|
||
## 📄 About | ||
|
||
A shareable [commitlint](https://commitlint.js.org/#/) configuration for enforcing consistent commit messages in your projects. | ||
|
||
### → Purpose | ||
|
||
Consistent commit messages are important for project collaboration, maintainability, and project history. This commitlint configuration provides a set of rules to ensure that all commits in your project follow a consistent structure, making it easier for your team to understand what changes were made and why. | ||
|
||
<br> | ||
|
||
To use this configuration, you'll need to install the `@commitlint/cli` package as a devDependency in your project: | ||
|
||
```bash | ||
# install with yarn | ||
$ yarn add -D @commitlint/cli @wayofdev/commitlint-config | ||
# Install as dev-dependency into root of monorepo | ||
$ pnpm add -wD @commitlint/cli @wayofdev/commitlint-config | ||
``` | ||
|
||
# install with pnpm | ||
$ pnpm add -Dw @commitlint/cli @wayofdev/commitlint-config | ||
This package should be added to the root of your monorepo, where you have a file `commitlint.config.js` and a `package.json` file. Within your monorepo, you should have a structure with directories for your apps and packages, such as: | ||
|
||
```bash | ||
. | ||
├── commitlint.config.js (root) | ||
├── package.json (root) | ||
├── apps | ||
│ └── my-first-app | ||
│ ├── package.json | ||
│ └── ... (other app files) | ||
└── packages | ||
└── my-first-package | ||
├── package.json | ||
└── ... (other package files) | ||
``` | ||
|
||
## Usage | ||
<br> | ||
|
||
**`commitlint.config.js`** | ||
### → Configure | ||
|
||
```js | ||
module.exports = { | ||
extends: ['@wayofdev/commitlint-config'], | ||
}; | ||
1. To configure the `commitlint.config.js` file, include the following line: | ||
|
||
```javascript | ||
module.exports = { | ||
extends: ["@wayofdev/commitlint-config"], | ||
} | ||
``` | ||
|
||
This extends the `@wayofdev/commitlint-config` configuration and uses its [pre-defined configuration](https://github.com/wayofdev/npm-shareable-configs/blob/master/packages/commitlint-config/index.js). | ||
|
||
Alternatively the configuration can be defined in a `commitlint.config.js`, `.commitlintrc.js`, `.commitlintrc`, `.commitlintrc.json`, `.commitlintrc.yml` file or a `commitlint` field in `package.json`. | ||
|
||
2. Install Husky | ||
|
||
Install `husky` as devDependency, a handy git hook helper available on npm. | ||
|
||
```bash | ||
# Install as dev-dependency into root of monorepo | ||
$ pnpm add -wD husky is-ci | ||
|
||
# Activate hooks | ||
$ pnpm husky install | ||
``` | ||
|
||
3. Add hook | ||
|
||
```bash | ||
$ npx husky add .husky/commit-msg 'pnpm commitlint --edit "${1}"' | ||
``` | ||
|
||
4. Add scripts to `package.json` | ||
|
||
```bash | ||
$ pnpm pkg set scripts.lint:commits="pnpm commitlint --from HEAD~1 --to HEAD --verbose" | ||
$ pnpm pkg set scripts.prepare="is-ci || husky install" | ||
``` | ||
|
||
<br> | ||
|
||
## 💻 Usage | ||
|
||
### → Test simple usage | ||
|
||
For a first simple usage test of commitlint you can do the following: | ||
|
||
```bash | ||
# using pnpm | ||
$ pnpm commitlint --from HEAD~1 --to HEAD --verbose | ||
|
||
# or, using npx | ||
$ npx commitlint --from HEAD~1 --to HEAD --verbose | ||
|
||
# or, if script was added | ||
$ pnpm lint:commits | ||
``` | ||
|
||
This will check your last commit and return an error if invalid or a positive output if valid. | ||
|
||
### → Test the hook | ||
|
||
You can test the hook by simply committing. You should see something like this if everything works. | ||
|
||
```bash | ||
$ git commit -m "foo: this will fail" | ||
husky > commit-msg (node v10.1.0) | ||
No staged files match any of provided globs. | ||
⧗ input: foo: this will fail | ||
✖ type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum] | ||
|
||
✖ found 1 problems, 0 warnings | ||
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint | ||
|
||
husky > commit-msg hook failed (add --no-verify to bypass) | ||
``` | ||
|
||
## Extending | ||
<br> | ||
|
||
## 🛠️ Extending | ||
|
||
This shows, how config can be extended with your custom rules. | ||
|
||
**`commitlint.config.js`** | ||
|
||
```js | ||
module.exports = { | ||
extends: ['@wayofdev/commitlint-config'], | ||
rules: { | ||
'body-leading-blank': [2, 'always'], | ||
}, | ||
}; | ||
extends: ["@wayofdev/commitlint-config"], | ||
rules: { | ||
"body-leading-blank": [2, "always"], | ||
}, | ||
} | ||
``` | ||
|
||
## Add a Husky Hook | ||
<br> | ||
|
||
Install husky: | ||
## 🤝 License | ||
|
||
```bash | ||
# using yarn | ||
$ yarn dlx husky-init --yarn2 && yarn && npm pkg set scripts.prepare="husky install" && yarn prepare | ||
[](./LICENSE) | ||
|
||
# using pnpm | ||
$ pnpm dlx husky-init && pnpm install && pnpm pkg set scripts.prepare="husky install" && pnpm prepare | ||
``` | ||
<br> | ||
|
||
Add the hook: | ||
## 🧱 Credits and Useful Resources | ||
|
||
```bash | ||
# using npm | ||
$ npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "${1}"' | ||
Based on: | ||
|
||
# using yarn | ||
$ yarn dlx husky add .husky/pre-commit 'npx --no -- commitlint --edit "${1}"' | ||
- [shareable-configs](https://github.com/waldronmatt/shareable-configs) from [waldronmatt](https://github.com/waldronmatt) | ||
|
||
# using pnpm | ||
$ pnpm dlx husky add .husky/pre-commit 'npx --no -- commitlint --edit "${1}"' | ||
``` | ||
Guides: | ||
|
||
- [Official commitlint setup guide](https://commitlint.js.org/#/./guides-local-setup?id=guides-local-setup) | ||
|
||
<br> | ||
|
||
## 🙆🏼♂️ Author Information | ||
|
||
This repository was created in **2023** by [lotyp / wayofdev](https://github.com/wayofdev). | ||
|
||
## Under The Hood | ||
<br> | ||
|
||
### `index.js` | ||
## 🙌 Want to Contribute? | ||
|
||
- `@commitlint/config-conventional` | ||
Thank you for considering contributing to the wayofdev community! | ||
We are open to all kinds of contributions. If you want to: | ||
|
||
## License | ||
- 🤔 Suggest a feature | ||
- 🐛 Report an issue | ||
- 📖 Improve documentation | ||
- 👨💻 Contribute to the code | ||
|
||
MIT | ||
You are more than welcome. Before contributing, kindly check our [guidelines](https://next-starter-tpl-docs.wayof.dev/contribution). |
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,33 @@ | ||
// @ts-check | ||
|
||
/** | ||
* This files overrides the base lint-staged.config.js present in the root directory. | ||
* It allows to run eslint based the package specific requirements. | ||
* {@link https://github.com/okonet/lint-staged#how-to-use-lint-staged-in-a-multi-package-monorepo} | ||
* {@link https://github.com/belgattitude/nextjs-monorepo-example/blob/main/docs/about-lint-staged.md} | ||
*/ | ||
|
||
const { concatFilesForPrettier, getEslintFixCmd } = require('../../lint-staged.common.js') | ||
|
||
/** | ||
* @type {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>} | ||
*/ | ||
const rules = { | ||
'**/*.{js,jsx,ts,tsx,mjs,cjs}': filenames => { | ||
return getEslintFixCmd({ | ||
cwd: __dirname, | ||
fix: true, | ||
cache: true, | ||
// when auto-fixing staged-files a good tip is to disable react-hooks/exhaustive-deps, cause | ||
// a change here can potentially break things without proper visibility. | ||
rules: ['react-hooks/exhaustive-deps: off'], | ||
maxWarnings: 25, | ||
files: filenames, | ||
}) | ||
}, | ||
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': filenames => { | ||
return [`prettier --write ${concatFilesForPrettier(filenames)}`] | ||
}, | ||
} | ||
|
||
module.exports = rules |
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 |
---|---|---|
|
@@ -17,18 +17,32 @@ | |
"directory": "packages/commitlint-config" | ||
}, | ||
"license": "MIT", | ||
"author": "[email protected]", | ||
"main": "index.js", | ||
"author": { | ||
"name": "Andrij Orlenko", | ||
"email": "[email protected]", | ||
"url": "https://github.com/lotyp" | ||
}, | ||
"exports": { | ||
".": { | ||
"require": "./src/index.js" | ||
} | ||
}, | ||
"main": "src/index.js", | ||
"files": [ | ||
"index.js", | ||
"src/*", | ||
"scripts/*" | ||
], | ||
"scripts": { | ||
"test": "echo \"No test specified\"" | ||
"clean": "rimraf ./dist ./coverage ./tsconfig.tsbuildinfo", | ||
"lint": "eslint --ext .ts,.js,.cjs,.mjs --cache --cache-location ../../.cache/eslint/commitlint-config.eslintcache", | ||
"lint:fix": "eslint --ext .ts,.tsx,.js,.jsx,.mjs,.cjs,.mts,.cts --fix --cache --cache-location ../../.cache/eslint/commitlint-config.eslintcache" | ||
}, | ||
"dependencies": { | ||
"@commitlint/config-conventional": "^17.4.2" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^4.1.2" | ||
}, | ||
"peerDependencies": { | ||
"@commitlint/cli": ">= 17" | ||
}, | ||
|
File renamed without changes.
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.