|
1 |
| -## Example TypeScript Package ready to be published to NPM |
| 1 | +## TypeScript Package ready to be published to NPM |
2 | 2 |
|
3 |
| -This is an example TypeScript Package ready to be published to NPM. It has been set up with automated tests and package publishing workflow using GitHub Actions CI/CD. |
4 |
| -This package could serve as a starter/boilerplate/demo them. |
| 3 | +This is a template TypeScript Package ready to be published to NPM. It has been set up with automated tests and package publishing workflow using GitHub Actions. |
| 4 | + |
| 5 | +The template uses [google-github-actions/release-please-action](https://github.com/google-github-actions/release-please-action) which handles the following use cases: |
| 6 | +1. Automated releases based on conventional commits |
| 7 | +2. Automated `CHANGELOG` generation |
| 8 | +3. Automated version bumps based on commit messages. It does all of these by parsing the git history, it looks for [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/) messages and it creates PR releases. |
| 9 | + |
| 10 | +It uses `npm`, `TypeScript`, `Jest`, `ESLint`, `Prettier`, `Husky`, `pinst`, `commitlint` and `lint-staged`. The production files include CommonJS, ES Modules and TypeScript declaration files. |
| 11 | + |
| 12 | +#### Install dependencies |
| 13 | +Install dependencies with npm: |
| 14 | +```bash |
| 15 | +npm install |
| 16 | +``` |
| 17 | + |
| 18 | +#### Write your code |
| 19 | +1. Update the `TODO`s inside `.github/workflows/publish.yml` file |
| 20 | +2. Make the necessary changes in package.json (name, version, description, keywords, author, etc). |
| 21 | +3. Write your code in `src/` folder and unit test in `tests/` folder, replacing the original files. |
| 22 | + |
| 23 | +#### Build: |
| 24 | +To build/compile the code, simply run: |
| 25 | +```bash |
| 26 | +npm run build |
| 27 | +``` |
| 28 | + |
| 29 | +This command will generate CommonJS, ES Module as well as TypeScript declaration files inside the `lib/` folder. |
| 30 | + |
| 31 | +#### Test |
| 32 | +Test your code with Jest: |
| 33 | +```bash |
| 34 | +npm run test |
| 35 | +``` |
| 36 | + |
| 37 | +### Publish |
| 38 | +This package is configured to use GitHub Actions CI/CD to automate the publishing of a package to `npm`. |
| 39 | + |
| 40 | +Follow [npm's official instruction](https://docs.npmjs.com/creating-and-viewing-access-tokens) to create an npm token. |
| 41 | + |
| 42 | +If you use 2FA, then make sure it's enabled for **authorization** only instead of **authorization and publishing** (**Edit Profile** -> **Modify 2FA**). |
| 43 | + |
| 44 | +On the page of your newly created or existing GitHub repo, click **Settings** -> **Secrets** -> **New repository secret**, the **Name** should be `NPM_TOKEN` and the **Value** should be your npm token. |
| 45 | + |
| 46 | + |
| 47 | +### Writing Conventional Commits |
| 48 | +The most important prefixes you should have in mind are: |
| 49 | + |
| 50 | +1. `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) **patch**. |
| 51 | +2. `feat:` which represents a new feature, and correlates to a [SemVer](https://semver.org/) **minor**. |
| 52 | +3. `feat!:`, `fix!:` or `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a [SemVer](https://semver.org/) **major**. |
0 commit comments