Skip to content

How to use cbf in your JavaScript with a package.json file

Joshua Vernon edited this page Jan 3, 2020 · 3 revisions

Here is the cbf package.json file. As you can see there is a lot of useful commands under the scripts attribute. They can be run by running npm and then the name of the attribute. However, since there are a lot it can be hard to remember them all and annoying to type. Let alone learn when you're working on a project for the first time. So cbf can parse them and turn them into a CLI 🦥

{
  "name": "cbf",
  "version": "2.0.10",
  "description": "A package for creating scripts to store and run your most commonly used CLI commands for a repo or just in general",
  "main": "index.js",
  "scripts": {
    "refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
    "lint": "eslint \"./**/*.js\"",
    "lint:fix": "eslint \"./**/*.js\" --fix",
    "circular": "madge --circular ./index.js",
    "format": "prettier --write \"**/*.js\" -l \"warn\" && standard --fix",
    "test": "mocha src --file ./test/setup.js --recursive --exit || if [ \"$?\" = 1 ]; then echo 1; else echo 0; fi",
    "build": "npm install . -g",
    "clean": "npm uninstall . -g",
    "tag:latest": "echo $(git describe --tags --abbrev=0)",
    "tag:latest-annotated": "echo $(git --no-pager log --tags -n1 --oneline --pretty=\"%s\")",
    "tag:changes-since-latest": "echo \"$(git --no-pager log $(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1))..$(git describe --tags --abbrev=0) --no-merges --oneline --pretty=format:'- %s')\"",
    "tag:build-annotated": "echo \"$(npm run --silent tag:latest-annotated)\n\n$(npm run --silent tag:changes-since-latest)\"",
    "tag:update-latest": "git tag -f \"$(npm run --silent tag:latest)\" \"$(npm run --silent tag:latest)\"^{} -a -m \"$(npm run --silent tag:build-annotated)\"",
    "version": "genversion --semi version.js && git add version.js",
    "postversion": "npm run --silent tag:update-latest && git push -u origin $(git rev-parse --abbrev-ref HEAD) && git push --follow-tags",
    "current-version": "echo $npm_package_version",
    "latest-published-version": "npm view cbf version"
  },
  "author": "Joshua Vernon",
  "engines": {
    "node": ">=0.10"
  },
  "license": "MIT",
  "dependencies": {
    ...
  },
  "devDependencies": {
    ...
  },
  "keywords": [
    ...
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/joshuatvernon/cbf"
  },
  "bin": {
    "cbf": "index.js"
  }
}

Then all you have to do to run them is run and they'll open in a CLI (optionally, use to -d flag to see what command will be run)

$ cbf
Running scripts from package.json file

? Choose an option (Use arrow keys)
❯ refresh
  lint ↓
  circular
  format
  test
  build
  clean
(Move up and down to reveal more choices)

or

cbf -j
Running scripts from package.json file

? Choose an option (Use arrow keys)
❯ refresh
  lint ↓
  circular
  format
  test
  build
  clean
(Move up and down to reveal more choices)

Check out cbf's 🦥 site to get started!

Clone this wiki locally