1.2.1 • Published 2 years ago
@beuluis/hook-cli v1.2.1
About The Project
A small hook cli that can be used with for example husky.
Disclaimer
I know that most of this stuff is already solved by some awesome tools. So this is really just a CLI playground for me.
Installation
npm i -D @beuluis/hook-cliUsage
Run commands. For example using the hooks in .husky.
```bash
npx hook-cli [command] [...]
```Commands
- checkCommitMessageIssueKey
- checkCommitMessagePattern
- checkForFileChanged
- checkForVulnerabilities
- checkPackageVersion
- checkPackageVersionInFile
- updateReminder
checkCommitMessageIssueKey
Check the pattern of a commit message
| Option | Description | Type | default |
|---|---|---|---|
-p, --prefix | Prefix of the issue key. | string | |
-m, --message | Get message from command line instead of file. | string | |
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | false |
Example usage
npx hook-cli checkCommitMessageIssueKey "$1" -p "HelloWorld"npx hook-cli checkCommitMessageIssueKey .git/COMMIT_EDITMSG -p "KEY"npx hook-cli checkCommitMessageIssueKey -m "KEY-12 message" -p "KEY"npx hook-cli checkCommitMessageIssueKey -m "KEY-12 message" -p "KEY" -ncheckCommitMessagePattern
Check the pattern of a commit message
| Option | Description | Type | default |
|---|---|---|---|
-p, --pattern | Regex pattern to check the message against. | string | |
-m, --message | Get message from command line instead of file. | string | |
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | false |
Example usage
npx hook-cli checkCommitMessagePattern "$1" -p "HelloWorld"npx hook-cli checkCommitMessagePattern .git/COMMIT_EDITMSG -p "HelloWorld"npx hook-cli checkCommitMessagePattern -m "I say HelloWorld" -p "HelloWorld"npx hook-cli checkCommitMessagePattern -m "I say HelloWorld" -p "HelloWorld" -ncheckForFileChanged
Check if a staged file like a changelog was changed locale or remote compared to another branch
| Option | Description | Type | default |
|---|---|---|---|
-b, --branch | Branch to compare to. | string | main |
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | true |
Example usage
npx hook-cli checkForFileChanged CHANGELOG.mdnpx hook-cli checkForFileChanged CHANGELOG.md -b trunknpx hook-cli checkForFileChanged CHANGELOG.md -nnpx hook-cli checkForFileChanged CHANGELOG.md -b trunk -ncheckForVulnerabilities
Runs a package audit and collects the results.
| Option | Description | Type | default |
|---|---|---|---|
-m, --package-manager | The package manager you want to use. Keep in mind that both package managers report differently. | yarn, npm | npm |
-l, --audit-level | The severity of the vulnerabilities what the script will report. | info, low, moderate, high, critical | critical |
-p, --prod | If true only run audit for prod dependencies and skip dev ones. | boolean | false |
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | false |
Example usage
npx hook-cli checkForVulnerabilitiesnpx hook-cli checkForVulnerabilities --package-manager yarnnpx hook-cli checkForVulnerabilities --audit-level lownpx hook-cli checkForVulnerabilities --no-failnpx hook-clicheckForVulnerabilities --prodnpx hook-cli checkForVulnerabilities -l high -m yarn -n -pcheckPackageVersion
Check if the version field is the same for package.json and package-lock.json
| Option | Description | Type | default |
|---|---|---|---|
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | false |
Example usage
npx hook-cli checkPackageVersioncheckPackageVersionInFile
Check if the version field is the same for package.json and file
| Option | Description | Type | default |
|---|---|---|---|
-p, --json-path | Path in json file to check | string | |
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | false |
Example usage
npx hook-cli checkPackageVersionInFile hello.json -p 'path.version'npx hook-cli checkPackageVersionInFile hello.json -p 'path.version' -nupdateReminder
Prints a list of packages that have updates.
| Option | Description | Type | default |
|---|---|---|---|
-m, --package-manager | The package manager you want to use. Keep in mind that both package managers report differently. | yarn, npm | npm |
-n, --no-fail | If true only prints warning messages and do not exit with not zero code. | boolean | false |
Example usage
npx hook-cli updateRemindernpx hook-cli updateReminder -m yarnnpx hook-cli updateReminder -nnpx hook-cli updateReminder -m yarn -nRegister new command
- Create new command module at
src/modules.
touch src/modules/helloWorld.ts- Use the register helper to register a module and export it. See the Jsdoc for more usage information.
import { registerCommandModule } from '../util/commandModule.helper';
export = registerCommandModule()({
command: 'helloWorld',
describe: 'HelloWorld',
handler: () => console.log('HelloWorld'),
});Useful
- Print help page for command
npx hook-cli [command] --help- Test command during development (Exit codes get not correctly forwarded).
npm run hook-cli -- [command]- Test command during development with correct exi code.
npx ts-node src/index.ts [command]Contributing
Follow contributing.