Convert Figma logo to code with AI

infinitered logogluegun

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

2,951
147
2,951
54

Top Related Projects

8,977

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

node.js command-line interfaces made easy

11,076

yargs the modern, pirate-themed successor to optimist.

42,950

A tool for writing better scripts

24,306

Package your Node.js project into an executable

5,642

Node's framework for interactive CLIs

Quick Overview

Gluegun is a delightful toolkit for building Node-based command-line interfaces (CLIs), APIs, and automation tools. It provides a set of utilities and extensions that simplify the process of creating powerful and flexible command-line applications.

Pros

  • Easy to use and intuitive API for building CLIs
  • Extensive set of built-in tools and utilities
  • Supports plugins and extensions for added functionality
  • Cross-platform compatibility

Cons

  • Limited documentation for advanced use cases
  • Steeper learning curve for complex CLI applications
  • Some features may be overkill for simple projects
  • Relatively small community compared to other CLI frameworks

Code Examples

  1. Creating a simple CLI command:
module.exports = {
  name: 'greet',
  run: async (toolbox) => {
    const { print } = toolbox
    print.info('Hello, Gluegun!')
  }
}
  1. Using prompts to gather user input:
module.exports = {
  name: 'askName',
  run: async (toolbox) => {
    const { prompt, print } = toolbox
    const { name } = await prompt.ask({ type: 'input', name: 'name', message: 'What is your name?' })
    print.info(`Hello, ${name}!`)
  }
}
  1. Generating files using templates:
module.exports = {
  name: 'generate',
  run: async (toolbox) => {
    const { template, print } = toolbox
    await template.generate({
      template: 'model.js.ejs',
      target: 'app/models/user.js',
      props: { name: 'User' }
    })
    print.success('Generated User model')
  }
}

Getting Started

To get started with Gluegun, follow these steps:

  1. Install Gluegun globally:

    npm install -g gluegun
    
  2. Create a new CLI project:

    gluegun new my-cli
    cd my-cli
    
  3. Install dependencies:

    npm install
    
  4. Run your CLI:

    npm link
    my-cli
    

Now you can start building your own CLI commands by adding new files to the src/commands directory.

Competitor Comparisons

8,977

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

Pros of oclif

  • Built and maintained by Heroku, ensuring enterprise-level support and reliability
  • Extensive plugin system for easy extensibility and customization
  • Strong TypeScript support with auto-generated documentation

Cons of oclif

  • Steeper learning curve due to its more complex architecture
  • Heavier footprint and potentially slower startup times
  • Less flexibility in terms of project structure and conventions

Code Comparison

oclif:

import {Command, flags} from '@oclif/command'

export default class Hello extends Command {
  static description = 'Say hello'
  static flags = {
    name: flags.string({char: 'n', description: 'name to say hello to'})
  }
  async run() {
    const {flags} = this.parse(Hello)
    console.log(`Hello ${flags.name || 'world'}!`)
  }
}

Gluegun:

module.exports = {
  name: 'hello',
  run: async toolbox => {
    const { print, parameters } = toolbox
    const name = parameters.first || 'world'
    print.info(`Hello ${name}!`)
  }
}

Both oclif and Gluegun are powerful CLI development frameworks, each with its own strengths. oclif offers a more structured approach with strong TypeScript support, while Gluegun provides a more flexible and lightweight solution. The choice between them depends on project requirements, team preferences, and the desired level of structure and customization.

node.js command-line interfaces made easy

Pros of Commander.js

  • More mature and widely adopted, with a larger community and ecosystem
  • Simpler API, making it easier to get started for basic CLI applications
  • Lightweight with minimal dependencies

Cons of Commander.js

  • Less feature-rich compared to Gluegun's extensive toolkit
  • Limited built-in support for advanced features like prompts, spinners, or filesystem operations
  • Requires additional libraries for more complex CLI functionality

Code Comparison

Commander.js:

const program = require('commander');

program
  .version('0.1.0')
  .option('-p, --peppers', 'Add peppers')
  .option('-c, --cheese <type>', 'Add cheese')
  .parse(process.argv);

Gluegun:

const { build } = require('gluegun');

const cli = build()
  .src(__dirname)
  .help()
  .version()
  .create();

cli.run();

Both Commander.js and Gluegun are popular choices for building command-line interfaces in Node.js. Commander.js offers a straightforward approach with a focus on simplicity, making it ideal for smaller projects or developers who prefer a minimalist setup. Gluegun, on the other hand, provides a more comprehensive toolkit with built-in features for complex CLI applications, including prompts, spinners, and filesystem operations. While Commander.js has a larger user base and ecosystem, Gluegun offers more out-of-the-box functionality for advanced CLI development.

11,076

yargs the modern, pirate-themed successor to optimist.

Pros of yargs

  • More mature and widely adopted project with a larger community
  • Extensive documentation and examples available
  • Supports a wider range of command-line argument parsing scenarios

Cons of yargs

  • Steeper learning curve for complex use cases
  • Configuration can be verbose for simple CLI applications
  • Less focus on project scaffolding and boilerplate generation

Code Comparison

yargs:

const argv = require('yargs')
  .option('name', {
    alias: 'n',
    describe: 'Your name'
  })
  .demandOption(['name'])
  .argv;

console.log(`Hello, ${argv.name}!`);

gluegun:

module.exports = {
  name: 'greet',
  run: async toolbox => {
    const { print, parameters } = toolbox;
    const name = parameters.first;
    print.info(`Hello, ${name}!`);
  }
};

Summary

yargs is a robust and flexible command-line argument parsing library, while gluegun is a toolkit for building CLIs with a focus on simplicity and rapid development. yargs excels in complex argument parsing scenarios, while gluegun offers a more opinionated structure and includes additional features like project scaffolding. The choice between the two depends on the specific requirements of your CLI project and your preferred development style.

42,950

A tool for writing better scripts

Pros of zx

  • Simpler syntax and more intuitive for developers familiar with JavaScript
  • Built-in support for common shell operations and utilities
  • Seamless integration with Node.js modules and ecosystem

Cons of zx

  • Less extensive CLI building features compared to Gluegun
  • Limited plugin system and extensibility options
  • Fewer built-in tools for managing project configuration and settings

Code Comparison

zx:

#!/usr/bin/env zx

await $`echo "Hello, World!"`
let name = await question('What is your name? ')
console.log(`Hello, ${name}!`)

Gluegun:

module.exports = {
  name: 'greet',
  run: async toolbox => {
    const { print } = toolbox
    print.info('Hello, World!')
    const name = await toolbox.prompt.ask('What is your name?')
    print.info(`Hello, ${name}!`)
  }
}

Both zx and Gluegun aim to simplify command-line scripting, but they take different approaches. zx focuses on providing a more JavaScript-like syntax for shell operations, while Gluegun offers a more structured approach to building CLI tools with additional features for managing plugins and project configuration. The choice between the two depends on the specific needs of your project and your preferred development style.

24,306

Package your Node.js project into an executable

Pros of pkg

  • Simplifies distribution by packaging Node.js applications into standalone executables
  • Supports multiple target platforms (Windows, macOS, Linux) from a single build
  • Includes Node.js runtime, reducing dependency issues on end-user systems

Cons of pkg

  • Limited customization options for the packaging process
  • May increase the size of the final executable significantly
  • Potential compatibility issues with certain native modules or dependencies

Code Comparison

pkg:

const pkg = require('pkg')

pkg.exec(['index.js', '--target', 'node12-win-x64'])
  .then(() => console.log('Packaging complete'))
  .catch(error => console.error('Packaging failed:', error))

Gluegun:

const { build } = require('gluegun')

const cli = build()
  .src(__dirname)
  .plugin('./commands')
  .create()

cli.run()

Key Differences

  • pkg focuses on packaging Node.js applications into standalone executables
  • Gluegun is a toolkit for building CLIs with a plugin-based architecture
  • pkg is more suitable for distributing applications to end-users
  • Gluegun offers more flexibility in creating custom CLI tools and commands

Both tools serve different purposes in the Node.js ecosystem, with pkg simplifying distribution and Gluegun providing a framework for building extensible command-line interfaces.

5,642

Node's framework for interactive CLIs

Pros of Vorpal

  • More mature and established project with a larger community
  • Extensive documentation and examples available
  • Built-in support for auto-completion and command validation

Cons of Vorpal

  • Less active development in recent years
  • More complex setup and configuration compared to Gluegun
  • Limited built-in tooling for modern JavaScript development

Code Comparison

Vorpal:

const vorpal = require('vorpal')();

vorpal
  .command('hello <name>')
  .action(function(args, callback) {
    this.log(`Hello, ${args.name}!`);
    callback();
  });

vorpal.delimiter('myapp$').show();

Gluegun:

module.exports = {
  name: 'hello',
  run: async (toolbox) => {
    const { print, parameters } = toolbox;
    const name = parameters.first;
    print.info(`Hello, ${name}!`);
  },
};

Both Vorpal and Gluegun are powerful CLI development tools, but they have different approaches. Vorpal offers a more traditional command-line interface with built-in features like auto-completion and command validation. It has a larger community and extensive documentation, making it easier for beginners to get started.

Gluegun, on the other hand, provides a more modern and flexible approach to CLI development. It offers a simpler setup process and includes built-in tooling for modern JavaScript development. Gluegun's plugin-based architecture allows for easier extensibility and customization.

While Vorpal has been around longer and has a larger user base, Gluegun is actively maintained and continues to evolve with modern JavaScript practices. The choice between the two depends on the specific needs of your project and your preferred development style.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

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 if they are performance, stability, types, or other similar enhancements. Read the Community Supported section to learn more.

Why use Gluegun?

Introductory YouTube video by our CTO, Jamon Holmgren: https://www.youtube.com/watch?v=_KEqXfLOSQY

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:

# 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!

Code

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!

Who Is Using This?

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 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
⭐️ cross-spawn for running sub-commands
⭐️ execa for running more sub-commands
⭐️ node-which for finding executables
⭐️ 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!

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

And of course, check out your favorite React Native Consultants, Infinite Red!.

NPM DownloadsLast 30 Days