Skip to content

Commit 692e23f

Browse files
committed
chore: updated the documentation. added lint-staged
1 parent 6b76976 commit 692e23f

File tree

8 files changed

+6863
-1370
lines changed

8 files changed

+6863
-1370
lines changed

.eslintrc.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
module.exports = {
22
parser: '@typescript-eslint/parser',
33
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
4+
plugins: ['@typescript-eslint', 'prettier'],
45
parserOptions: {
56
sourceType: 'module',
67
},
8+
env: {
9+
jest: true,
10+
browser: true,
11+
},
12+
root: true,
713
rules: {
814
'prettier/prettier': 'error',
15+
'max-len': [
16+
'error',
17+
160,
18+
2,
19+
{
20+
ignoreUrls: true,
21+
ignoreComments: false,
22+
ignoreRegExpLiterals: true,
23+
ignoreStrings: true,
24+
ignoreTemplateLiterals: true,
25+
},
26+
],
27+
'no-console': ['error', { allow: ['info', 'error'] }],
28+
'no-underscore-dangle': ['error', { allow: ['_id'] }],
29+
'import/no-named-as-default': 0,
30+
'implicit-arrow-linebreak': 0,
31+
'object-curly-newline': [
32+
'error',
33+
{
34+
consistent: true,
35+
},
36+
],
37+
'no-unneeded-ternary': 0,
938
},
10-
plugins: ['@typescript-eslint', 'prettier'],
1139
};

.github/workflows/publish.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release & Publish
22

33
on:
44
push:
5-
branches: [ <%= branch %> ]
5+
branches: [ <%= branch %> ] # TODO: add branch name
66

77
jobs:
88
publish:
@@ -13,7 +13,7 @@ jobs:
1313
id: release
1414
with:
1515
release-type: node
16-
package-name: uk-export-finance/<PACKAGE-NAME>
16+
package-name: uk-export-finance/<PACKAGE-NAME> # TODO: add package name
1717
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
1818
extra-files: |
1919
README.md
@@ -40,5 +40,5 @@ jobs:
4040
- name: Publish the package
4141
run: npm publish --access public
4242
env:
43-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
43+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} # TODO: add your NPM_TOKEN to Github secrets
4444
if: ${{ steps.release.outputs.release_created }}

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.lintstagedrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "*.ts": "npm run lint:fix" }

README.md

+51-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
1-
## Example TypeScript Package ready to be published to NPM
1+
## TypeScript Package ready to be published to NPM
22

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**.

jest.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
clearMocks: true,
3+
collectCoverage: true,
4+
collectCoverageFrom: ['tests/**/*.test.ts'],
5+
coverageDirectory: 'generated_reports/coverage/tests',
6+
coveragePathIgnorePatterns: ['/node_modules/'],
7+
testMatch: ['**/*.test.ts'],
8+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
9+
preset: 'ts-jest',
10+
testEnvironment: 'node',
11+
globals: {
12+
"ts-jest": {
13+
tsconfig: "tsconfig.json"
14+
}
15+
},
16+
};

0 commit comments

Comments
 (0)