1.2.1 • Published 8 months ago

@beuluis/hook-cli v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Contributors Forks Stargazers Issues

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

Usage

Run commands. For example using the hooks in .husky.

```bash
npx hook-cli [command] [...]
```

Commands

checkCommitMessageIssueKey

Check the pattern of a commit message

OptionDescriptionTypedefault
-p, --prefixPrefix of the issue key.string
-m, --messageGet message from command line instead of file.string
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleanfalse
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" -n

checkCommitMessagePattern

Check the pattern of a commit message

OptionDescriptionTypedefault
-p, --patternRegex pattern to check the message against.string
-m, --messageGet message from command line instead of file.string
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleanfalse
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" -n

checkForFileChanged

Check if a staged file like a changelog was changed locale or remote compared to another branch

OptionDescriptionTypedefault
-b, --branchBranch to compare to.stringmain
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleantrue
Example usage
npx hook-cli checkForFileChanged CHANGELOG.md
npx hook-cli checkForFileChanged CHANGELOG.md -b trunk
npx hook-cli checkForFileChanged CHANGELOG.md -n
npx hook-cli checkForFileChanged CHANGELOG.md -b trunk -n

checkForVulnerabilities

Runs a package audit and collects the results.

OptionDescriptionTypedefault
-m, --package-managerThe package manager you want to use. Keep in mind that both package managers report differently.yarn, npmnpm
-l, --audit-levelThe severity of the vulnerabilities what the script will report.info, low, moderate, high, criticalcritical
-p, --prodIf true only run audit for prod dependencies and skip dev ones.booleanfalse
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleanfalse
Example usage
npx hook-cli checkForVulnerabilities
npx hook-cli checkForVulnerabilities --package-manager yarn
npx hook-cli checkForVulnerabilities --audit-level low
npx hook-cli checkForVulnerabilities --no-fail
npx hook-clicheckForVulnerabilities --prod
npx hook-cli checkForVulnerabilities -l high -m yarn -n -p

checkPackageVersion

Check if the version field is the same for package.json and package-lock.json

OptionDescriptionTypedefault
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleanfalse
Example usage
npx hook-cli checkPackageVersion

checkPackageVersionInFile

Check if the version field is the same for package.json and file

OptionDescriptionTypedefault
-p, --json-pathPath in json file to checkstring
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleanfalse
Example usage
npx hook-cli checkPackageVersionInFile hello.json -p 'path.version'
npx hook-cli checkPackageVersionInFile hello.json -p 'path.version' -n

updateReminder

Prints a list of packages that have updates.

OptionDescriptionTypedefault
-m, --package-managerThe package manager you want to use. Keep in mind that both package managers report differently.yarn, npmnpm
-n, --no-failIf true only prints warning messages and do not exit with not zero code.booleanfalse
Example usage
npx hook-cli updateReminder
npx hook-cli updateReminder -m yarn
npx hook-cli updateReminder -n
npx hook-cli updateReminder -m yarn -n

Register new command

  1. Create new command module at src/modules.
touch src/modules/helloWorld.ts
  1. 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.

1.2.0

12 months ago

1.2.1

12 months ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago