Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Husky #1243

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run -w "@prosopo/hooks" hook:precommit

Check warning on line 1 in .husky/pre-commit

View workflow job for this annotation

GitHub Actions / check

File ignored by default.
1 change: 1 addition & 0 deletions dev/gh-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/node": "^20.11.4",
"tslib": "2.6.2",
"tsx": "^4.7.0",
"husky": "^9.0.11",
"typescript": "5.1.6"
},
"dependencies": {
Expand Down
10 changes: 10 additions & 0 deletions dev/hooks/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/node_modules/

Check warning on line 1 in dev/hooks/.npmignore

View workflow job for this annotation

GitHub Actions / check

File ignored by default.
/src/
/tests/
/artifacts/
tsconfig.json
tsconfig.tsbuildinfo
env.development
env.test
.env.*
webpack.*
Empty file added dev/hooks/README.md
Empty file.
35 changes: 35 additions & 0 deletions dev/hooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@prosopo/hooks",
"version": "1.0.1",
"private": true,
"description": "Typescript git hooks for husky",
"main": "dist/index.js",
"type": "module",
"engines": {
"node": ">=18",
"npm": ">=9"
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore --quiet",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
"prettier:fix": "npm run prettier -- --write",
"lint": "npm run eslint && npm run prettier",
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
"license": "tsx src/scripts/addCopyrightNotice.ts check",
"license:fix": "tsx src/scripts/addCopyrightNotice.ts license",
"hook:precommit": "npx tsx src/precommit.ts"
},
"author": "Prosopo Limited",
"license": "Apache-2.0",
"dependencies": {},
"devDependencies": {
"tsx": "^4.11.0",
"tslib": "2.6.2",
"typescript": "5.1.6",
"vitest": "^1.3.1"
}
}
57 changes: 57 additions & 0 deletions dev/hooks/src/precommit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// 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 } from 'child_process'

const main = async () => {
console.log('running precommit hook')

// get the the current branch name
const branch = await new Promise<string>((resolve, reject) => {
exec('git rev-parse --abbrev-ref HEAD', (err, stdout, stderr) => {

Check warning on line 21 in dev/hooks/src/precommit.ts

View workflow job for this annotation

GitHub Actions / check

'stderr' is defined but never used
if (err) {
reject(err)
} else {
resolve(stdout.trim())
}
})
})

// get the name of the default branch (usually 'main')
const defaultBranch = await new Promise<string>((resolve, reject) => {
exec("git remote show origin | grep 'HEAD branch'", (err, stdout, stderr) => {

Check warning on line 32 in dev/hooks/src/precommit.ts

View workflow job for this annotation

GitHub Actions / check

'stderr' is defined but never used
if (err) {
reject(err)
} else {
const parts = stdout.split(': ')
if (parts.length !== 2) {
reject(new Error('could not find default branch'))
}
const branch = (parts[1] as string).trim()
resolve(branch)
}
})
})

if (branch === defaultBranch) {
throw new Error(
`Commits to the default branch (${defaultBranch}) are not allowed. Please create a branch and submit a pull request.`
)
}
console.log('all good')
}

main().catch((err) => {
console.error(err)
process.exit(1)
})
11 changes: 11 additions & 0 deletions dev/hooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"target": "ES2018",
"rootDir": "./src",
"outDir": "./dist",
"lib": ["dom", "dom.iterable", "esnext"]
},
"include": ["src", "src/**/*.json"],
"references": []
}
19 changes: 19 additions & 0 deletions dev/hooks/typedoc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// 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.
export default {
entryPoints: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', 'src/**/*.jsx', 'src/**/*.json'],
includes: 'src',
extends: '../../typedoc.base.config.js',
readme: 'README.md',
}
54 changes: 45 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"lint:fix:workspace": "npm run eslint:fix:workspace && npm run prettier:fix:workspace",
"removePolkadotJSWarnings": "sed -i 's/console.warn\\(.*\\);//g' ./node_modules/@polkadot/util/versionDetect.js && sed -i 's/console.warn\\(.*\\);//g' ./node_modules/@polkadot/util/cjs/versionDetect.js || true",
"postinstall": "npm run removePolkadotJSWarnings",
"docs": "npx typedoc --plugin typedoc-plugin-missing-exports --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-zod 2>&1 | grep -v \"Serialized project contained a reflection\" && echo 'docs.prosopo.io' >> docs/CNAME"
"docs": "npx typedoc --plugin typedoc-plugin-missing-exports --plugin typedoc-plugin-mdn-links --plugin typedoc-plugin-zod 2>&1 | grep -v \"Serialized project contained a reflection\" && echo 'docs.prosopo.io' >> docs/CNAME",
"prepare": "husky"
},
"private": true,
"engines": {
Expand Down Expand Up @@ -111,6 +112,7 @@
"eslint-plugin-unused-imports": "^3.0.0",
"eslint-plugin-workspaces": "^0.9.0",
"eslint-plugin-yaml": "^0.5.0",
"husky": "^9.0.11",
"node-loader": "^2.0.0",
"nodemon": "^3.0.1",
"npm-check-updates": "^15.3.4",
Expand Down
Loading