Context API

Let's explore the inside of the Weex Toolkit “Context API”.

module.exports = {
  name: 'dostuff',
  alias: 'd',
  run: async (context) => {
    // great! now what?
  },
}

Here‘s what’s available inside the context object you see all over Gluegun.

nameprovides the...3rd party
metainformation about the currently running CLI
configconfiguration options from the app or plugin
fsability to copy, move & delete files & directoriesfs-jetpack
httpability to talk to the webapisauce
parameterscommand line arguments and optionsyargs-parser
patchingmanipulating file contents easilyfs-jetpack
printtools to print output to the command linecolors, ora
inquirertools to acquire extra command line user inputinquirer
semverutilities for working with semantic versioningsemver
stringssome string helpers like case conversion, etc.lodash & ramda
systemability to executenode-which, execa, cross-spawn
openability to open filesopen, chrome-opn

The context has “drawers” full of useful tools for building CLIs. For example, the context.meta.version function can be invoked like this:

module.exports = {
  name: 'dostuff',
  alias: 'd',
  run: async (context) => {
    // use them like this...
    context.logger.info(context.meta.version())

    // or destructure!
    const {
      logger: { info },
      meta: { version },
    } = toolbox
    info(version())
  },
}

To learn more about each tool, explore the rest of the context-*.md files in this folder.