|
| 1 | +# Contributing |
| 2 | + |
| 3 | +This repository is created by using [Turborepo](https://turbo.build/repo). To understand the repository structure better, please check its [documentation](https://turbo.build/repo/docs). |
| 4 | + |
| 5 | +## Local Development |
| 6 | + |
| 7 | +After cloning the repository, we need to install the dependencies. |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install |
| 11 | +``` |
| 12 | + |
| 13 | +To start the demo Next.js app which uses the local version of `react-infinite-scroll-hook`, we can run `dev` script. |
| 14 | + |
| 15 | +```bash |
| 16 | +npm run dev |
| 17 | +``` |
| 18 | + |
| 19 | +After this, we can open `http://localhost:3000` in the browser to display the app. |
| 20 | + |
| 21 | +## Code Quality Checks |
| 22 | + |
| 23 | +We use automated checks by using [ESLint](https://eslint.org/), [Prettier](https://prettier.io/) and [TypeScript](https://www.typescriptlang.org/) to provide the highest quality code as it can be. |
| 24 | + |
| 25 | +All checks are run automatically before committing by using [husky](https://github.com/typicode/husky) and [lint-staged](https://github.com/lint-staged/lint-staged). |
| 26 | + |
| 27 | +The checks can be run manually by running the below command too. |
| 28 | + |
| 29 | +```bash |
| 30 | +npm run codequality:check |
| 31 | +``` |
| 32 | + |
| 33 | +And the same checks can be run also by enabling fixes for auto-fixable issues. |
| 34 | + |
| 35 | +```bash |
| 36 | +npm run codequality:fix |
| 37 | +``` |
| 38 | + |
| 39 | +`codequality` scripts run underlying ESLint (`lint`), Prettier (`format`) and TypeScript (`types`) scripts. To run these tools individually, we can also use the below scripts. |
| 40 | + |
| 41 | +```bash |
| 42 | +# ESLint checks |
| 43 | +npm run lint:check |
| 44 | +# ESLint fixes |
| 45 | +npm run lint:fix |
| 46 | + |
| 47 | +# Prettier checks |
| 48 | +npm run format:check |
| 49 | +# Prettier fixes |
| 50 | +npm run format:fix |
| 51 | + |
| 52 | +# TypeScript checks |
| 53 | +npm run types:check |
| 54 | +# There is no auto-fix script for TypeScript. |
| 55 | +``` |
| 56 | + |
| 57 | +## Updating Dependencies |
| 58 | + |
| 59 | +We use `npm-check-updates` package to automatically check if there are newer versions of our dependencies. |
| 60 | + |
| 61 | +To run it, we can use the below command. It starts an interactive CLI to check the dependencies of all the apps and packages, including the root dependencies. |
| 62 | + |
| 63 | +```bash |
| 64 | +npm run updates:check |
| 65 | +``` |
| 66 | + |
| 67 | +## Adding Contributors |
| 68 | + |
| 69 | +[all-contributors-cli](https://github.com/all-contributors/cli) is used for maintaining the contributors of this repository. |
| 70 | + |
| 71 | +To add a new contributor, we can run the below command and follow its instructions. |
| 72 | + |
| 73 | +```bash |
| 74 | +npm run contributors:add |
| 75 | +``` |
| 76 | + |
| 77 | +## Prepublish Checks |
| 78 | + |
| 79 | +To be sure everything is OK with the latest changes, we can use [publint](https://publint.dev/) and [Are the Types Wrong](https://github.com/arethetypeswrong/arethetypeswrong.github.io). |
| 80 | + |
| 81 | +Firstly, we need to build the bundle with the latest changes. |
| 82 | + |
| 83 | +```bash |
| 84 | +npm run build:bundle |
| 85 | +``` |
| 86 | + |
| 87 | +This command will create (or update) the `packages/react-infinite-scroll-hook/dist` folder, which will be used by the clients of this package. |
| 88 | + |
| 89 | +To be sure the output is OK for ESM and CJS clients, we can run the below commands and check their outputs. |
| 90 | + |
| 91 | +```bash |
| 92 | +# For `publint` |
| 93 | +npm run publint:check -w react-infinite-scroll-hook |
| 94 | + |
| 95 | +# For `Are the Types Wrong` |
| 96 | +npm run attw:check -w react-infinite-scroll-hook |
| 97 | +``` |
| 98 | + |
| 99 | +To see the content of the package which can be uploaded to [npm](https://www.npmjs.com/) can be seen by using the below command. It will create a tarball from `react-infinite-scroll-hook` package. |
| 100 | + |
| 101 | +```bash |
| 102 | +npm pack -w react-infinite-scroll-hook |
| 103 | +``` |
| 104 | + |
| 105 | +Or the below command can be used to only check the tarball contents without creating it. |
| 106 | + |
| 107 | +```bash |
| 108 | +npm pack --dry-run -w react-infinite-scroll-hook |
| 109 | +``` |
| 110 | + |
| 111 | +Lastly, we can run the below command to auto correct common errors in `package.json` of the package to be published. `npm publish` command already does these auto-fixes too. |
| 112 | + |
| 113 | +```bash |
| 114 | +npm pkg fix -w react-infinite-scroll-hook |
| 115 | +``` |
| 116 | + |
| 117 | +## Publishing the Package |
| 118 | + |
| 119 | +Firstly, we need to bump the package version which can be done by using the below commands. |
| 120 | + |
| 121 | +```bash |
| 122 | +npm version patch -w react-infinite-scroll-hook |
| 123 | +# Bumps the patch number like 0.0.0 -> 0.0.1 |
| 124 | + |
| 125 | +npm version minor -w react-infinite-scroll-hook |
| 126 | +# Bumps the patch number like 0.0.x -> 0.1.0 |
| 127 | + |
| 128 | +npm version major -w react-infinite-scroll-hook |
| 129 | +# Bumps the patch number like 0.x.y -> 1.0.0 |
| 130 | +``` |
| 131 | + |
| 132 | +And we can publish the new version now 🚀 |
| 133 | + |
| 134 | +```bash |
| 135 | +npm publish -w react-infinite-scroll-hook |
| 136 | +``` |
0 commit comments