Skip to content

Latest commit

 

History

History
88 lines (69 loc) · 2.03 KB

README.md

File metadata and controls

88 lines (69 loc) · 2.03 KB

command-check

Version License PRs Welcome

Checks whether the command exists and whether it matches the specified version.

Installation

npm install cmd-check
// or
// yan add cmd-check

Usage

CLI mode

Usage: cmd-check [options]

Options:
  -f, --file [file]          # configuration file path. default: command-check.json
  -v, --version              # output the version number

Run cmd-check in the root folder of a git repository or run as npm script, it will read configuration from ./command-check.json or command-check option of ./package.json file.

package.json example:

{
  "command-check": {
    "node": true,
    "yarn": ">=1.22.0"
  }
}

command-check.json example:

{
  "node": true,
  "yarn": {
    "version": ">=1.22.0",
    "versionCommand": "yarn -v"
  }
}

code mode

import { commandCheck } from 'cmd-check';

// should match command name
const isExistSoffice = commandCheck('soffice');

// should match command name and version
const isExistYarn = commandCheck('yarn', '>1.22.0');

Configuration

Example

{
  "node": true,
  "yarn": {
    "version": ">=1.22.0",
    "versionCommand": "yarn -v"
  }
}

Props

version

  • type: string | true
  • description: Use semver to match versions. If set to true, no specific version matching is required. If set to true, it means that no specific version needs to be matched

versionCommand

  • type: string
  • description: Customize the command for obtaining the version. If not provided, the default version obtaining method will be used.

License

MIT