Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beuluis/hook-cli

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beuluis/hook-cli

A small hook cli that can be used with for example husky

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Contributors Forks Stargazers Issues


Logo

hook-cli

A small hook cli

· Report Bug · Request Feature ·

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

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

TODOs:

  • Add command to check version between package.json and package-lock.json
  • Add command to check engine
  • Add command to check types
  • Add command to check peerDependencies

Contact

Luis Beu - me@luisbeu.de

Keywords

FAQs

Package last updated on 16 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc