Skip to content

Commit

Permalink
chore: add pre commit tools and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
SMAKSS committed Sep 12, 2023
1 parent e7615f1 commit f394130
Show file tree
Hide file tree
Showing 11 changed files with 1,450 additions and 27 deletions.
10 changes: 10 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Build files
dist

# Rollup configs
rollup.config.js

# lint-staged config
lint-staged.config.cjs

# commitlint config
commitlint.config.cjs
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Resolves #0000 <!-- link to issue or task card if one exists -->

<!--
Share context about the problem or feature request.
Share context about the problem or feature request.
Why is this change beneficial for the users of this hook?
-->

Expand Down Expand Up @@ -45,4 +45,4 @@ Resolves #0000 <!-- link to issue or task card if one exists -->

**Note**: once this PR is merged, a new release or update might be required for the users.

- Main changes or updates introduced in this release.
- Main changes or updates introduced in this release.
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: PR Checks

on:
pull_request:
branches: [main, develop]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ["18"]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Print head and base refs
run: |
echo "Head ref: ${{ github.head_ref }}"
echo "Base ref: ${{ github.base_ref }}"
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Cache dependencies
uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
- name: Install dependencies
run: yarn install

- name: Type check
run: yarn typecheck
continue-on-error: false

- name: Check code quality
run: |
set -e
trap 'echo "Error in $BASH_COMMAND at line $LINENO"' ERR
yarn lint
yarn format:check
yarn run --if-present generate
- name: Security Audit
run: yarn audit --level moderate
continue-on-error: true

- name: Archive production artifacts
if: always()
uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: ./build/

- name: Error handling
if: ${{ failure() }}
run: echo "CI failed. Please check the logs."
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit ${1}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package.json
.cache
.shadowenv.d
.vscode
build
dist
node_modules
public
.github
tmp
*.yml
3 changes: 3 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};
4 changes: 4 additions & 0 deletions lint-staged.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
"*.+(js|jsx|ts|tsx)": ["yarn lint", () => "yarn typecheck"],
"*.+(js|jsx|json|yml|yaml|css|ts|tsx|md|graphql|mdx)": ["yarn format"],
};
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
},
"description": "Detect scroll direction in react applications.",
"devDependencies": {
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^11.1.1",
"@types/react": "^18.2.6",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"eslint": "^8.41.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^3.0.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"prettier": "^2.8.8",
"rollup": "^3.2.3",
"typescript": "^5.0.4"
},
Expand Down Expand Up @@ -55,9 +59,13 @@
"url": "git+https://github.com/SMAKSS/react-scroll-direction.git"
},
"scripts": {
"format": "prettier --write \"**/*.+(js|jsx|json|yml|yaml|css|ts|tsx|md|gql|graphql|mdx)\"",
"format:check": "prettier -l \"**/*.+(js|jsx|json|yml|yaml|css|ts|tsx|md|gql|graphql|mdx)\"",
"generate": "rollup -c",
"lint": "tsc --noEmit && eslint src/**/*.ts --cache --max-warnings=0",
"lint:fix": "eslint src/**/*.ts --fix"
"lint": "eslint --cache --cache-location ./node_modules/.cache/.eslintcache --ext js,jsx,ts,tsx --max-warnings=0 .",
"lint:fix": "eslint src/**/*.ts --fix",
"postinstall": "husky install",
"typecheck": "tsc -b ."
},
"type": "module",
"version": "2.2.1"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["./src/**/*.ts"],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

Expand Down
Loading

0 comments on commit f394130

Please sign in to comment.