Skip to content

Commit

Permalink
Merge pull request #12 from thiagoolsilva/v1_0_5
Browse files Browse the repository at this point in the history
V1 0 5
  • Loading branch information
thiagoolsilva authored Jan 11, 2023
2 parents 82debad + 32ab919 commit 860e808
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 1,080 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Common
on:
pull_request:
branches:
- "*"

jobs:
eslint:
name: Run eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "14"
- run: |
cd library/
yarn install --frozen-lockfile
yarn static-analysis:lint
build:
name: Build code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "14"
- run: |
cd library/
yarn install --frozen-lockfile
yarn build
19 changes: 19 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Testing
on:
pull_request:
branches:
- "*"

jobs:
unit-testing:
name: Run Unit Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "14"
- run: |
cd library/
yarn install --frozen-lockfile
yarn test:unit-testing:coverage
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

### The library gonna help you to configure all your husky hooks

![Version](https://img.shields.io/badge/version-1.0.4-blue.svg?cacheSeconds=2592000)
![Version](https://img.shields.io/badge/version-1.0.5-blue.svg?cacheSeconds=2592000)
![Prerequisite](https://img.shields.io/badge/node-%3E%3D14.0.0-blue.svg)
[![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/thiagoolsilva/husky-hook-creator#readme)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/thiagoolsilva/husky-hook-creator/graphs/commit-activity)
[![License: Apache License 2.0](https://img.shields.io/github/license/thiagoolsilva/@husky-hook-creator/core)](https://github.com/thiagoolsilva/husky-hook-creator/blob/main/LICENSE)

### 🏠 [Homepage](https://github.com/thiagoolsilva/husky-hook-creator#readme)

Expand Down
4 changes: 2 additions & 2 deletions library/.husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

cd library
yarn lint
yarn format
yarn static-analysis:lint
yarn static-analysis:format
1 change: 1 addition & 0 deletions library/.husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

cd library
yarn static-analysis:branch-name
./node_modules/.bin/pretty-quick --staged --bail
3 changes: 1 addition & 2 deletions library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

### The library gonna help you to configure all your husky hooks

![Version](https://img.shields.io/badge/version-1.0.4-blue.svg?cacheSeconds=2592000)
![Version](https://img.shields.io/badge/version-1.0.5-blue.svg?cacheSeconds=2592000)
![Prerequisite](https://img.shields.io/badge/node-%3E%3D14.0.0-blue.svg)
[![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/thiagoolsilva/husky-hook-creator#readme)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/thiagoolsilva/husky-hook-creator/graphs/commit-activity)
[![License: Apache License 2.0](https://img.shields.io/github/license/thiagoolsilva/@husky-hook-creator/core)](https://github.com/thiagoolsilva/husky-hook-creator/blob/main/LICENSE)

### 🏠 [Homepage](https://github.com/thiagoolsilva/husky-hook-creator#readme)

Expand Down
40 changes: 27 additions & 13 deletions library/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@husky-hook-creator/core",
"version": "1.0.4",
"version": "1.0.5",
"author": "thiago lopes da silva <thiagoolsilva@gmail.com>, kaio monteiro calás da costa <kaiomonteiro151@gmail.com>",
"main": "./dist-cjs/src/index.js",
"types": "./dist-types/src/index.d.ts",
"module": "./dist-es/src/index.js",
"license": "Apache License 2.0",
"license": "Apache-2.0",
"private": false,
"repository": {
"type": "git",
Expand All @@ -15,49 +15,63 @@
"url": "https://github.com/thiagoolsilva/husky-starter/issues"
},
"homepage": "https://github.com/thiagoolsilva/husky-starter#readme",
"keywords": [
"husky",
"init",
"git",
"hooks",
"pre-commit"
],
"scripts": {
"build:types": "tsc -p tsconfig.types.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:es": "tsc -p tsconfig.es.json",
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
"lint": "eslint --quiet --ext .ts .",
"lint:fix": "eslint --fix --ext .ts .",
"format": "yarn prettier --write .",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"clean:all": "rimraf ./dist-* && rimraf *.tsbuildinfo && rimraf node_modules",
"test:unit-testing": "jest --runInBand --detectOpenHandles --testRegex='.spec.ts' --testPathPattern=tests/unit-tests -c tests/unit-tests/jest.config.ts",
"test:unit-testing:coverage": "jest --coverage --testRegex='.spec.ts' --testPathPattern=tests/unit-tests -c tests/unit-tests/jest.config.ts",
"create-hooks": "ts-node script/src/create-hooks.ts"
"create-hooks": "ts-node script/src/create-hooks.ts",
"static-analysis:lint": "eslint --quiet --ext .ts .",
"static-analysis:lint:fix": "eslint --fix --ext .ts .",
"static-analysis:format": "yarn prettier --write .",
"static-analysis:branch-name": "ts-node script/src/check-branch-name.ts"
},
"dependencies": {
"shelljs": "0.8.5"
},
"engines": {
"node": ">=14.0.0",
"node": ">=14.0.0"
},
"peerDependencies": {
"husky": ">=7.0.2"
},
"devDependencies": {
"@commitlint/cli": "16.1.0",
"@commitlint/config-conventional": "16.0.0",
"@jest/globals": "29.3.1",
"@tsconfig/node14": "1.0.3",
"@types/jest": "27.4.0",
"@types/node": "18.11.15",
"@types/shelljs": "0.8.9",
"@typescript-eslint/eslint-plugin": "5.2.0",
"@typescript-eslint/parser": "5.2.0",
"concurrently": "7.2.0",
"eslint": "8.1.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-plugin-import": "2.25.2",
"eslint": "8.31.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-sort-imports-es6-autofix": "0.6.0",
"husky": "7.0.2",
"jest": "27.5.0",
"@jest/globals": "29.3.1",
"jest": "29.3.1",
"jest-mock-extended": " 3.0.1",
"ts-jest": "29.0.3",
"prettier": "2.4.1",
"pretty-quick": "3.1.1",
"rimraf": "3.0.2",
"ts-jest": "27.1.3",
"ts-node": "10.3.0",
"typescript": "4.4.3"
},
"resolutions": {
"eslint-plugin-import/debug": "3.1.0"
}
}
33 changes: 33 additions & 0 deletions library/script/src/check-branch-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2022 Thiago Lopes da Silva
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { exec, exit } from 'shelljs';

(() => {
const regexBranchName = /HHC-\d+$/gm;
const getBranchNameScript = 'git rev-parse --abbrev-ref HEAD';
const { stdout: branchName } = exec(getBranchNameScript, {
silent: true,
});
const checkBranchResult = branchName.match(regexBranchName);

// check branch name
if (!checkBranchResult) {
// eslint-disable-next-line no-console
console.log('\x1b[33m ---> The branch name does not match the pattern HHC-\\d+$. \x1b[0m');
exit(1);
}
})();
7 changes: 5 additions & 2 deletions library/script/src/create-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import { CommandHookFactory, HuskyRunnerFactory } from '../../src/index';
),
)
.addCommand(CommandHookFactory.createHookCommand('pre-commit', 'cd library'))
.addCommand(CommandHookFactory.createHookCommand('pre-commit', 'yarn lint'))
.addCommand(CommandHookFactory.createHookCommand('pre-commit', 'yarn format '))
.addCommand(CommandHookFactory.createHookCommand('pre-commit', 'yarn static-analysis:lint'))
.addCommand(CommandHookFactory.createHookCommand('pre-commit', 'yarn static-analysis:format '))
.addCommand(CommandHookFactory.createHookCommand('pre-push', 'cd library'))
.addCommand(
CommandHookFactory.createHookCommand('pre-push', 'yarn static-analysis:branch-name'),
)
.addCommand(
CommandHookFactory.createHookCommand(
'pre-push',
Expand Down
32 changes: 32 additions & 0 deletions library/tests/unit-tests/runner/husky-runner.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Thiago Lopes da Silva
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, expect } from '@jest/globals';
import { mock } from 'jest-mock-extended';
import { CommandHookFactory, ExecutorInterface, HuskyRunner } from '../../../src';

describe('husky-runner', () => {
test(' should call command method if provided one', async () => {
const executor = mock<ExecutorInterface>();
const huskyRunner = new HuskyRunner(executor);

await huskyRunner
.addCommand(CommandHookFactory.createHookCommand('pre-commit', 'fake command'))
.runAllCommands();

expect(executor.exec).toBeCalledTimes(1);
});
});
Loading

0 comments on commit 860e808

Please sign in to comment.