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

{
  "name": "cbf",
  "author": "Joshua Vernon",
  "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"
  }
}

As you can see there is a lot of useful commands under the scripts attribute.

They can be run by running npm <command_name>. However, if you don't know they're there you'll have to open to package.json file and copy and paste them or just try to learn and remember them.

Instead, cbf can actually just parse them in real time and turn them into a CLI 🦥 for you!

All you have to do is run cbf or cbf -j (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