Skip to content

Commit 9c41615

Browse files
authored
refactor: Replace husky with Lefthook (#518)
1 parent d6317e1 commit 9c41615

File tree

7 files changed

+57
-434
lines changed

7 files changed

+57
-434
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ jobs:
2727
- name: 'Install, lint, and test'
2828
run: |
2929
yarn install --frozen-lockfile
30-
yarn lint
31-
yarn test:coverage
30+
yarn test
3231
if: |
3332
contains(github.event.commits[0].message, '[skip ci]') == false &&
3433
contains(github.event.commits[0].message, '[ci skip]') == false

.huskyrc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

.lintstagedrc.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"*.{js,jsx,ts,tsx}": [
3-
"eslint --ignore-path .gitignore --fix --quiet",
4-
"prettier --ignore-path .gitignore --loglevel error --write"
5-
]
2+
"*.{js,jsx,ts,tsx}": ["eslint --ignore-path .gitignore --fix --quiet"]
63
}

README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,44 @@ The **ts-node-starter** is a [template repository](https://docs.github.com/en/re
44

55
## Features
66

7-
- **Static code analysis** powered by [ESLint](https://eslint.org/)
8-
- **Code formatting** powered by [Prettier](https://prettier.io/)
9-
- **Testing & code coverage** powered by [Jest](https://jestjs.io/)
10-
- **Distribution pipeline** powered by [npm](https://www.npmjs.com/)
11-
- **Automatic dependency updates** powered by [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates)
12-
- **Type checking** powered by [TypeScript](https://www.typescriptlang.org/)
13-
- **Cross-platform compatibility** powered by [cross-env](https://github.com/kentcdodds/cross-env)
14-
- **Automatic changelog generation** powered by [generate-changelog](https://github.com/lob/generate-changelog)
15-
- **Dependency management** powered by [yarn](https://yarnpkg.com/)
16-
- **Automatic code & config formatting** powered by [husky](https://github.com/typicode/husky), [lint-staged](https://github.com/okonet/lint-staged) & [pretty-quick](https://github.com/azz/pretty-quick)
17-
- **Continuous integration pipeline** powered by [GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows)
7+
1. **Automatic changelog generation** powered by [generate-changelog](https://github.com/lob/generate-changelog)
8+
1. **Automatic code & config formatting** powered by [Lefthook](https://github.com/evilmartians/lefthook)
9+
1. **Automatic dependency updates** powered by [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates)
10+
1. **Code coverage reports** powered by [Codecov](https://about.codecov.io/)
11+
1. **Config formatting** powered by [Prettier](https://prettier.io/)
12+
1. **Continuous integration pipeline** powered by [GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows)
13+
1. **Cross-platform compatibility** powered by [cross-env](https://github.com/kentcdodds/cross-env)
14+
1. **Dependency management** powered by [yarn](https://yarnpkg.com/)
15+
1. **Distribution pipeline** powered by [npm](https://www.npmjs.com/)
16+
1. **Static code analysis** powered by [ESLint](https://eslint.org/)
17+
1. **Testing & code coverage** powered by [Jest](https://jestjs.io/)
18+
1. **Type checking** powered by [TypeScript](https://www.typescriptlang.org/)
1819

1920
## Usage
2021

2122
### Make it your own
2223

2324
1. Replace all occurrences of "bennycode" with your own username (or the name of your organization)
2425
2. Start writing your code in the ["src" directory](./src)
25-
3. There is no step 3 😁
26+
3. Run `yarn` and be happy! 😊
2627

2728
### Build a CLI
2829

2930
**Source Code**
3031

31-
If you want to build a CLI tool for Node.js, you can have a look at ["src/cli.ts"](./src/cli.ts).
32+
If you want to build a CLI tool for Node.js, you can have a look at ["src/cli.ts"](./src/cli.ts).
3233

3334
**References**
3435

35-
In the ["package.json" file](./package.json) you will also discover a "bin" property which defines the executable name of your tool and the entry point to its transpiled JavaScript code.
36+
In the ["package.json" file](./package.json) you will also discover a "bin" property which defines the executable name of your tool and the entry point to its transpiled JavaScript code.
3637

3738
If you don't want to publish a CLI, simply remove the "bin" property and the CLI script.
3839

3940
### Build a Library
4041

4142
**Source Code**
4243

43-
If you want to distribute your code as a Node.js library on [npm](https://www.npmjs.com/), you can have a look at ["src/index.ts"](./src/index.ts). If you build a library, I recommend to always ship an index file from where you export the code of your library for others.
44+
If you want to distribute your code as a Node.js library on [npm](https://www.npmjs.com/), you can have a look at ["src/index.ts"](./src/index.ts). If you build a library, I recommend to always ship an index file from where you export the code of your library for others.
4445

4546
**References**
4647

@@ -50,11 +51,11 @@ In the ["package.json" file](./package.json) you will also discover a "main" pro
5051

5152
**Source Code**
5253

53-
If you just want to write and run a Node.js app, checkout ["src/start.ts"](./src/start.ts).
54+
If you just want to write and run a Node.js app, checkout ["src/start.ts"](./src/start.ts).
5455

5556
**References**
5657

57-
You can start your application by executing `yarn start`. If you want to debug your code, run `yarn debug` ([Debug Instructions](https://dev.to/typescripttv/debug-your-node-js-app-with-chrome-devtools-4c98)).
58+
You can start your application by executing `yarn start`. If you want to debug your code, run `yarn debug` ([Debug Instructions](https://dev.to/typescripttv/debug-your-node-js-app-with-chrome-devtools-4c98)).
5859

5960
## Conventions
6061

@@ -70,9 +71,13 @@ The automatic changelog generation is based on [Semantic Commit Messages](https:
7071

7172
> feat: My new feature
7273
73-
## Maintainers
74+
## Contributors
7475

75-
[![Benny Neugebauer on Stack Exchange][stack_exchange_bennyn_badge]][stack_exchange_bennyn_url]
76+
[![Benny Neugebauer on Stack Exchange][stack_exchange_bennycode_badge]][stack_exchange_bennycode_url]
7677

77-
[stack_exchange_bennyn_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
78-
[stack_exchange_bennyn_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts
78+
[![Panayiotis Lipiridis on Stack Exchange][stack_exchange_lipis_badge]][stack_exchange_lipis_url]
79+
80+
[stack_exchange_bennycode_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
81+
[stack_exchange_bennycode_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts
82+
[stack_exchange_lipis_badge]: https://stackexchange.com/users/flair/5282.png?theme=default
83+
[stack_exchange_lipis_url]: https://stackexchange.com/users/5282/lipis?tab=accounts

lefthook.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pre-commit:
2+
parallel: false
3+
commands:
4+
1_prettier:
5+
run: yarn pretty-quick --staged --ignore-path .gitignore
6+
2_eslint:
7+
glob: '*.{js,jsx,ts,tsx}'
8+
run: yarn eslint {staged_files} --fix

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {},
99
"description": "",
1010
"devDependencies": {
11+
"@arkweid/lefthook": "0.7.7",
1112
"@types/jest": "28.1.6",
1213
"@types/node": "18.6.4",
1314
"@typescript-eslint/eslint-plugin": "5.32.0",
@@ -20,9 +21,7 @@
2021
"eslint-plugin-typescript-sort-keys": "2.1.0",
2122
"eslint-plugin-unused-imports": "2.0.0",
2223
"generate-changelog": "1.8.0",
23-
"husky": "4.3.8",
2424
"jest": "28.1.3",
25-
"lint-staged": "13.0.3",
2625
"prettier": "2.7.1",
2726
"pretty-quick": "3.1.3",
2827
"rimraf": "3.0.2",
@@ -54,23 +53,24 @@
5453
"clean": "rimraf .nyc_output coverage dist",
5554
"debug": "node --inspect -r ts-node/register ./src/start.ts",
5655
"dist": "yarn clean && yarn build",
57-
"fix": "yarn fix:other && yarn fix:code",
56+
"fix": "yarn fix:config && yarn fix:code",
5857
"fix:code": "yarn lint:code --fix --quiet",
59-
"fix:other": "yarn prettier --write",
60-
"lint": "yarn lint:types && yarn lint:code && yarn lint:other",
61-
"lint:code": "eslint --ignore-path .gitignore --ext .js,.jsx,.ts,.tsx .",
62-
"lint:other": "yarn prettier --list-different",
63-
"lint:types": "tsc --noEmit",
58+
"fix:config": "yarn prettier --write",
59+
"lint": "yarn lint:code && yarn lint:config",
60+
"lint:code": "eslint --ignore-path .gitignore --ext .js,.jsx,.ts,.tsx --no-error-on-unmatched-pattern .",
61+
"lint:config": "yarn prettier --list-different",
62+
"postinstall": "lefthook install -a",
6463
"postversion": "git push origin && git push origin --tags && npm publish --access public",
65-
"prettier": "prettier --ignore-path .gitignore --loglevel error \"**/*.{json,scss,yml}\"",
64+
"prettier": "prettier --ignore-path .gitignore --loglevel error .",
6665
"preversion": "git checkout main && git pull && yarn && yarn test && yarn dist",
6766
"release:major": "generate-changelog -M -x \"chore,test\" && yarn changelog:commit && npm version major",
6867
"release:minor": "generate-changelog -m -x \"chore,test\" && yarn changelog:commit && npm version minor",
6968
"release:patch": "generate-changelog -p -x \"chore,test\" && yarn changelog:commit && npm version patch",
7069
"start": "ts-node ./src/start.ts",
71-
"test": "cross-env NODE_ENV=test jest ./src --passWithNoTests",
72-
"test:coverage": "yarn test --coverage",
73-
"test:types": "yarn lint:types"
70+
"test": "yarn test:types && yarn test:unit:coverage",
71+
"test:types": "tsc --noEmit",
72+
"test:unit": "cross-env NODE_ENV=test jest ./src --passWithNoTests",
73+
"test:unit:coverage": "yarn test:unit --coverage"
7474
},
7575
"version": "0.0.0"
7676
}

0 commit comments

Comments
 (0)