npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lenne.tech/gluegun-menu

v0.0.6

Published

Menu for gluegun CLIs

Downloads

67

Readme

Gluegun Menu

The Gluegun Menu is an extension for Gluegun CLIs. It generates an interactive menu structure from the commands of the CLI.

Gluegun Menu Demo

The extension can be integrated into any Gluegun project. It is already integrated in the lenne.Tech CLI Starter, which can be initialized comfortably via the lenne.Tech CLI.

Integration

It can be easily integrated into your CLI:

1. Install extension:

$ npm install @lenne.tech/gluegun-menu

2. Integrate extension as plugin:

src/cli.ts:

// ...
const cli = build()
  // ...
  .plugin(__dirname + '/../node_modules/@lenne.tech/gluegun-menu/dist', {
    commandFilePattern: '*.js',
    extensionFilePattern: '*.js'
  })
  // ...
  .create();
// ...

3. Prepare main commands

src/commands/YOUR_COMMAND/YOUR_COMMAND.ts:

import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';

/**
 * YOUR_COMMAND menu
 */
module.exports = {
  name: 'YOUR_COMMAND',
  alias: ['YOUR_COMMAND_ALIAS'],
  description: 'YOUR_DESCRIPTION',
  hidden: true,
  run: async (toolbox: GluegunMenuToolbox) => {
    await toolbox.menu.showMenu('(PARANT_COMMANDS) YOUR_COMMAND');
  }
};

Parameters of showMenu

  1. parentCommands?: string
    command name OR parent names + command name

  2. options?: object

    • level?: number => Level of the current section (0 = main section)
    • headline?: string => Headline for the current section
    • showHelp?: boolean => If you want to show the help command at the top
    • hideBack?: boolean => If you want to hide the back command at the bottom
    • setCache?: boolean => Re-use these options in subsequent menus (doesn't apply for level, headline or setCache)
    • backLabel?: string => custom label to indicate go back action
    • cancelLabel?: string => custom label to indicate cancel action
    • byeMessage?: string => custom bye message

Note: If the options in the main menu are to be used, for example to define the headline, null or an empty string '' must be passed as the first parameter:
showMenu(null, {headline: 'Main menu'})

Example

Example file structure:

src/commands/
    section1/
        subsection1/
            subsection1.ts
            yyy1.ts
            yyy2.ts
        section1.ts
        xxx1.ts
        xxx2.ts
    section2/
        section2.ts
        zzz1.ts
        zzz2.ts
    brand.ts

src/commands/brand.ts:

import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';

/**
 * Main menu
 */
module.exports = {
  name: 'brand',
  description: 'Welcome to brand CLI',
  hidden: true,
  run: async (toolbox: GluegunMenuToolbox) => {
    await toolbox.menu.showMenu();
  }
};

src/commands/section1/section1.ts:

import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';

/**
 * Section1 menu
 */
module.exports = {
  name: 'section1',
  alias: ['s1'],
  description: 'Description for section1',
  hidden: true,
  run: async (toolbox: GluegunMenuToolbox) => {
    await toolbox.menu.showMenu('section1');
  }
};

src/commands/section1/subsection1/subsection1.ts:

import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';

/**
 * Subsection1 menu
 */
module.exports = {
  name: 'subsection1',
  alias: ['sub1'],
  description: 'Description for subsection1',
  hidden: true,
  run: async (toolbox: GluegunMenuToolbox) => {
    await toolbox.menu.showMenu('section1 subsection1', { headline: 'Subsection1 commands' });
  }
};

Extensions of the toolbox

toolbox.menu

The menu extends the toolbox by the functionality to execute commands via a menu in the terminal (see above).

toolbox.fromMenu

Extends the toolbox to the possibility to determine during the execution of a command whether the command was called via the menu.

const NewCommand: GluegunCommand = {
  // ...
  run: async (toolbox: GluegunMenuToolbox) => {
    //...

    if (toolbox.fromMenu()) {
      console.log('I was called via the menu');
    } else {
      console.log('I was called via a direct command in the terminal');
    }

    // ...
  }
};
export default NewCommand;

Additional parameter options

toolbox.parameters.options.fromGluegunMenu

Flag that shows whether the command was called via the menu.

Thanks

Many thanks to the developers of Glugun and all the developers whose packages are used here.

Many thanks also to:

  • pascal-klesse for the support during the development
  • Tazaf for the idea to set the fromGlueguneMenu flag

License

MIT - see LICENSE