Gluegun

A delightful toolkit for building TypeScript-powered command-line apps.

README

npm module CircleCI code style: prettier

Gluegun


gluegun

Gluegun is a delightful toolkit for building Node-based command-line interfaces (CLIs) in TypeScript or modern JavaScript, with support for:

🌯 _parameters_ - command-line arguments and options
🎛 _template_ - generating files from templates
🗄 _patching_ - manipulating file contents
💾 _filesystem_ - moving files and directories around
⚒ _system_ - executing other command-line scripts
🎅 _http_ - interacting with API servers
🛎 _prompt_ - auto-complete prompts
💃 _print_ - printing pretty colors and tables
👩‍✈️ _semver_ - working with semantic versioning
🎻 _strings_ - manipulating strings & template data
📦 _packageManager_ - installing NPM packages with Yarn or NPM

In addition, gluegun supports expanding your CLI's ecosystem with a robust set of easy-to-write plugins and extensions.

Notice


Gluegun is at a stable point and we aren't planning on building new features for it, although the community continues to send in PRs and we release them. Read the Community Supported section to learn more.

Why use Gluegun?


You might want to use Gluegun if:

- You need to build a CLI app
- You want to have powerful tools at your fingertips
- And you don't want to give up flexibility at the same time

If so ... welcome!

Quick Start


Just run the gluegun CLI like this:

  1. ```
  2. # spin up your new CLI
  3. npx gluegun new movies

  4. # choose TypeScript or Modern JavaScript
  5. # now jump into the source
  6. cd movies

  7. # and link your new executable
  8. yarn link

  9. # and run it!
  10. movies help
  11. ```

You should see your new CLI help. Open the folder in your favorite editor and start building your CLI!

Code


Let's start with what a gluegun CLI looks like.

  1. ```js
  2. // in movie/src/cli.[js|ts]...

  3. // ready
  4. const { build } = require('gluegun')

  5. // aim
  6. const movieCLI = build('movie')
  7.   .src(`${__dirname}/src`)
  8.   .plugins('node_modules', { matching: 'movie-*' })
  9.   .help()
  10.   .version()
  11.   .defaultCommand()
  12.   .create()

  13. // fire!
  14. movieCLI.run()
  15. ```

Commands

Commands are simple objects that provide a name, optional aliases, and a function to run.

  1. ```js
  2. // in movie/src/commands/foo.js
  3. module.exports = {
  4.   name: 'foo',
  5.   alias: 'f',
  6.   run: async function (toolbox) {
  7.     // gluegun provides all these features and more!
  8.     const { system, print, filesystem, strings } = toolbox

  9.     // ...and be the CLI you wish to see in the world
  10.     const awesome = strings.trim(await system.run('whoami'))
  11.     const moreAwesome = strings.kebabCase(`${awesome} and a keyboard`)
  12.     const contents = ` Warning! ${moreAwesome} coming thru! `
  13.     const home = process.env['HOME']
  14.     filesystem.write(`${home}/realtalk.json`, { contents })

  15.     print.info(`${print.checkmark} Citius`)
  16.     print.warning(`${print.checkmark} Altius`)
  17.     print.success(`${print.checkmark} Fortius`)
  18.   },
  19. }
  20. ```

See the toolbox api docs for more details on what you can do.

See the runtime docs for more details on building your own CLI and join us in the #gluegun channel of the Infinite Red Community Slack (community.infinite.red) to get friendly help!

Who Is Using This?


- Ignite CLI - React Native CLI and starter kit
- Solidarity - audits your system dependencies so you can develop in peace
- Sara Vieira's Fiddly - Create beautiful and simple HTML pages from your Readme.md files - https://fiddly.netlify.com
- Graph CLI - CLI for building and managing subgraphs that index data from Ethereum and IPFS - https://thegraph.com/explorer
- Vts - Vanilla TypeScript library starter CLI tool

Additionally, the first versions of the AWS Amplify CLI (a CLI toolchain for simplifying serverless web and mobile development) used Gluegun. They've since integrated Gluegun's functionality into their CLI in a bespoke way, but you can still see Gluegun patterns in their CLI.

What's under the hood?


We've assembled an _all-star cast_ of libraries to help you build your CLI.

⭐️ [ejs](https://github.com/mde/ejs) for templating
⭐️ [semver](https://github.com/npm/node-semver) for version investigations
⭐️ [fs-jetpack](https://github.com/szwacz/fs-jetpack) for the filesystem
⭐️ [yargs-parser](https://github.com/yargs/yargs-parser), [enquirer](https://github.com/enquirer/enquirer), [colors](https://github.com/Marak/colors.js), [ora](https://github.com/sindresorhus/ora) and [cli-table3](https://github.com/cli-table/cli-table3) for the command line
⭐️ [axios](https://github.com/mzabriskie/axios) & [apisauce](https://github.com/infinitered/apisauce) for web & apis
⭐️ [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for flexible configuration
⭐️ [cross-spawn](https://github.com/IndigoUnited/node-cross-spawn) for running sub-commands
⭐️ [execa](https://github.com/sindresorhus/execa) for running more sub-commands
⭐️ [node-which](https://github.com/npm/node-which) for finding executables
⭐️ [pluralize](https://github.com/blakeembrey/pluralize) for manipulating strings

Node.js 12.0+ is required.

Community CLIs and Plugins


Here are a few community CLIs based on Gluegun plus some plugins you can use. Is yours missing? Send a PR to add it!

- Gluegun-Menu - A command menu for Gluegun-based CLIs
- Gluegun CLI-Starter - A CLI Starter for your next Gluegun CLI project

Community Supported


While Gluegun is no longer actively developed by Infinite Red, it has built a community that cares deeply about it. Infinite Red won't be building new features ourselves for Gluegun, but we encourage the community to continue to send high quality pull requests. We will try to review and merge them in a timely manner.

If you're looking for alternatives, here's a list:

Rust CLI -- Rust is a rapidly growing community and hot language, and has the benefit of speed and not needing to rely on a local Node engine.
oclif - oclif is used by some large CLIs and is very actively maintained
commander and yeoman - commander and yeoman have been around a long time and have very large communities. Keep in mind that we built Gluegun to avoid Commander and Yeoman, so YMMV
vorpal - unfortunately looks like it isn't actively maintained
just make your own - you don't need a framework to make a Node CLI. Check out this article from Twilio