docs/README.md
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.
You might want to use Gluegun if:
If so ... welcome!
Just run the gluegun CLI like this:
# spin up your new CLI
npx gluegun new movies
# choose TypeScript or Modern JavaScript
# now jump into the source
cd movies
# and link your new executable
yarn link
# and run it!
movies help
You should see your new CLI help. Open the folder in your favorite editor and start building your CLI!
Let's start with what a gluegun CLI looks like.
// in movie/src/cli.[js|ts]...
// ready
const { build } = require('gluegun')
// aim
const movieCLI = build('movie')
.src(`${__dirname}/src`)
.plugins('node_modules', { matching: 'movie-*' })
.help()
.version()
.defaultCommand()
.create()
// fire!
movieCLI.run()
Commands
Commands are simple objects that provide a name, optional aliases, and a function to run.
// in movie/src/commands/foo.js
module.exports = {
name: 'foo',
alias: 'f',
run: async function (toolbox) {
// gluegun provides all these features and more!
const { system, print, filesystem, strings } = toolbox
// ...and be the CLI you wish to see in the world
const awesome = strings.trim(await system.run('whoami'))
const moreAwesome = strings.kebabCase(`${awesome} and a keyboard`)
const contents = `đ¨ Warning! ${moreAwesome} coming thru! đ¨`
const home = process.env['HOME']
filesystem.write(`${home}/realtalk.json`, { contents })
print.info(`${print.checkmark} Citius`)
print.warning(`${print.checkmark} Altius`)
print.success(`${print.checkmark} Fortius`)
},
}
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!
We've assembled an all-star cast of libraries to help you build your CLI.
âď¸ ejs for templating
âď¸ semver for version investigations
âď¸ fs-jetpack for the filesystem
âď¸ yargs-parser, enquirer, colors, ora and cli-table3 for the command line
âď¸ axios & apisauce for web & apis
âď¸ cosmiconfig for flexible configuration </br> âď¸ cross-spawn for running sub-commands</br> âď¸ execa for running more sub-commands</br> âď¸ node-which for finding executables</br> âď¸ pluralize for manipulating strings</br>
Node.js 12.0+ is required.
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 is sponsored by Infinite Red, a premium custom mobile app and web design and development agency. We are a team of designers and developers distributed across the USA and based near Portland, Oregon. Our specialties are UI/UX design, React and React Native, Node, and more. Email [email protected] if you'd like to talk about your project!