Skip to content

Commit

Permalink
refactor: Replace husky with Lefthook (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode authored Aug 7, 2022
1 parent d6317e1 commit 9c41615
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 434 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
- name: 'Install, lint, and test'
run: |
yarn install --frozen-lockfile
yarn lint
yarn test:coverage
yarn test
if: |
contains(github.event.commits[0].message, '[skip ci]') == false &&
contains(github.event.commits[0].message, '[ci skip]') == false
Expand Down
5 changes: 0 additions & 5 deletions .huskyrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"*.{js,jsx,ts,tsx}": [
"eslint --ignore-path .gitignore --fix --quiet",
"prettier --ignore-path .gitignore --loglevel error --write"
]
"*.{js,jsx,ts,tsx}": ["eslint --ignore-path .gitignore --fix --quiet"]
}
47 changes: 26 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@ The **ts-node-starter** is a [template repository](https://docs.github.com/en/re

## Features

- **Static code analysis** powered by [ESLint](https://eslint.org/)
- **Code formatting** powered by [Prettier](https://prettier.io/)
- **Testing & code coverage** powered by [Jest](https://jestjs.io/)
- **Distribution pipeline** powered by [npm](https://www.npmjs.com/)
- **Automatic dependency updates** powered by [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates)
- **Type checking** powered by [TypeScript](https://www.typescriptlang.org/)
- **Cross-platform compatibility** powered by [cross-env](https://github.com/kentcdodds/cross-env)
- **Automatic changelog generation** powered by [generate-changelog](https://github.com/lob/generate-changelog)
- **Dependency management** powered by [yarn](https://yarnpkg.com/)
- **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)
- **Continuous integration pipeline** powered by [GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows)
1. **Automatic changelog generation** powered by [generate-changelog](https://github.com/lob/generate-changelog)
1. **Automatic code & config formatting** powered by [Lefthook](https://github.com/evilmartians/lefthook)
1. **Automatic dependency updates** powered by [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates)
1. **Code coverage reports** powered by [Codecov](https://about.codecov.io/)
1. **Config formatting** powered by [Prettier](https://prettier.io/)
1. **Continuous integration pipeline** powered by [GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows)
1. **Cross-platform compatibility** powered by [cross-env](https://github.com/kentcdodds/cross-env)
1. **Dependency management** powered by [yarn](https://yarnpkg.com/)
1. **Distribution pipeline** powered by [npm](https://www.npmjs.com/)
1. **Static code analysis** powered by [ESLint](https://eslint.org/)
1. **Testing & code coverage** powered by [Jest](https://jestjs.io/)
1. **Type checking** powered by [TypeScript](https://www.typescriptlang.org/)

## Usage

### Make it your own

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

### Build a CLI

**Source Code**

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

**References**

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

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

### Build a Library

**Source Code**

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

**References**

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

**Source Code**

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

**References**

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

## Conventions

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

> feat: My new feature
## Maintainers
## Contributors

[![Benny Neugebauer on Stack Exchange][stack_exchange_bennyn_badge]][stack_exchange_bennyn_url]
[![Benny Neugebauer on Stack Exchange][stack_exchange_bennycode_badge]][stack_exchange_bennycode_url]

[stack_exchange_bennyn_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
[stack_exchange_bennyn_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts
[![Panayiotis Lipiridis on Stack Exchange][stack_exchange_lipis_badge]][stack_exchange_lipis_url]

[stack_exchange_bennycode_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
[stack_exchange_bennycode_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts
[stack_exchange_lipis_badge]: https://stackexchange.com/users/flair/5282.png?theme=default
[stack_exchange_lipis_url]: https://stackexchange.com/users/5282/lipis?tab=accounts
8 changes: 8 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pre-commit:
parallel: false
commands:
1_prettier:
run: yarn pretty-quick --staged --ignore-path .gitignore
2_eslint:
glob: '*.{js,jsx,ts,tsx}'
run: yarn eslint {staged_files} --fix
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {},
"description": "",
"devDependencies": {
"@arkweid/lefthook": "0.7.7",
"@types/jest": "28.1.6",
"@types/node": "18.6.4",
"@typescript-eslint/eslint-plugin": "5.32.0",
Expand All @@ -20,9 +21,7 @@
"eslint-plugin-typescript-sort-keys": "2.1.0",
"eslint-plugin-unused-imports": "2.0.0",
"generate-changelog": "1.8.0",
"husky": "4.3.8",
"jest": "28.1.3",
"lint-staged": "13.0.3",
"prettier": "2.7.1",
"pretty-quick": "3.1.3",
"rimraf": "3.0.2",
Expand Down Expand Up @@ -54,23 +53,24 @@
"clean": "rimraf .nyc_output coverage dist",
"debug": "node --inspect -r ts-node/register ./src/start.ts",
"dist": "yarn clean && yarn build",
"fix": "yarn fix:other && yarn fix:code",
"fix": "yarn fix:config && yarn fix:code",
"fix:code": "yarn lint:code --fix --quiet",
"fix:other": "yarn prettier --write",
"lint": "yarn lint:types && yarn lint:code && yarn lint:other",
"lint:code": "eslint --ignore-path .gitignore --ext .js,.jsx,.ts,.tsx .",
"lint:other": "yarn prettier --list-different",
"lint:types": "tsc --noEmit",
"fix:config": "yarn prettier --write",
"lint": "yarn lint:code && yarn lint:config",
"lint:code": "eslint --ignore-path .gitignore --ext .js,.jsx,.ts,.tsx --no-error-on-unmatched-pattern .",
"lint:config": "yarn prettier --list-different",
"postinstall": "lefthook install -a",
"postversion": "git push origin && git push origin --tags && npm publish --access public",
"prettier": "prettier --ignore-path .gitignore --loglevel error \"**/*.{json,scss,yml}\"",
"prettier": "prettier --ignore-path .gitignore --loglevel error .",
"preversion": "git checkout main && git pull && yarn && yarn test && yarn dist",
"release:major": "generate-changelog -M -x \"chore,test\" && yarn changelog:commit && npm version major",
"release:minor": "generate-changelog -m -x \"chore,test\" && yarn changelog:commit && npm version minor",
"release:patch": "generate-changelog -p -x \"chore,test\" && yarn changelog:commit && npm version patch",
"start": "ts-node ./src/start.ts",
"test": "cross-env NODE_ENV=test jest ./src --passWithNoTests",
"test:coverage": "yarn test --coverage",
"test:types": "yarn lint:types"
"test": "yarn test:types && yarn test:unit:coverage",
"test:types": "tsc --noEmit",
"test:unit": "cross-env NODE_ENV=test jest ./src --passWithNoTests",
"test:unit:coverage": "yarn test:unit --coverage"
},
"version": "0.0.0"
}
Loading

0 comments on commit 9c41615

Please sign in to comment.