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

@whop-cli/runtime

v0.0.9

Published

The provided CLI runner allows you to create a command-line interface with various commands and flags. Each command can be associated with specific flags, and you can execute these commands through the terminal.

Downloads

23

Readme

@whop-cli/runtime

The provided CLI runner allows you to create a command-line interface with various commands and flags. Each command can be associated with specific flags, and you can execute these commands through the terminal.

Getting Started

To use the CLI runner, you need to follow these steps:

  1. Install the required dependencies:

    npm install @whop-cli/runtime
  2. Create your command files in the cmd directory following the structure mentioned below.

  3. Use the cli function to run the CLI and execute commands.

Command File Structure

The CLI runner expects the following structure for your command files:

  • Each command is represented by a separate folder inside the cmd directory.
  • For each command, there should be an index.js file that exports the function that will be executed when the command is run.
  • Optionally, you can include a config.js file that provides additional information about the command, such as a description, flags, and aliases.

Adding a New Command

To add a new command, follow these steps:

  1. Create a new folder inside the cmd directory with the desired command name.

  2. Inside the new folder, create an index.js file that exports the function to be executed when the command is run. The function should accept two arguments: input (containing flag values) and context (containing additional context data).

  3. Optionally, create a config.js file in the same folder to provide a description, flags, and aliases for the command. The config.js file should export an object with the following properties:

    • description (optional): A description of the command.
    • flags (required): An object defining the flags for the command. Flags can be of different types, such as string, number, boolean, etc.
    • alias (optional): An array of strings representing the aliases for the command.
  4. Run the cli function in your main file (e.g., index.js) to initialize the CLI and execute the commands.

Command Configuration

The config.js file for a command can include the following properties:

  • description: A description of the command that will be displayed in the CLI help.

  • flags: An object defining the flags for the command. Each flag should be defined using one of the following interfaces:

    • StringFlag: A single string flag.
    • StringsFlag: Multiple string flags.
    • NumberFlag: A single number flag.
    • NumbersFlag: Multiple number flags.
    • BooleanFlag: A boolean flag.
  • alias (optional): An array of strings representing the aliases for the command. Aliases can be used as shortcuts for the main command.

Running the CLI

To run the CLI, call the cli function in your main file (e.g., index.js). The CLI will parse the command-line arguments and execute the corresponding command based on the provided input.

Example

Here's an example of how you can add a new command:

  1. Create a new folder named greet inside the cmd directory.

  2. Inside the greet folder, create an index.js file with the following content:

    import type { default as init } from '@/commands/init';
    import type { Command } from '@whop-cli/runtime';
    import type { flags } from './config';
    
    const command: Command<typeof flags, typeof init> = async ({ name }) => {
      console.log(`Hello, ${name}!`);
    };
    
    export default command;
  3. Optionally, create a config.js file in the greet folder with the following content:

    import { FlagsConfig } from '@whop-cli/runtime';
    
    export const alias = ['i'];
    
    export const description = 'Describe the command here';
    
    export const flags = {
      name: {
        type: 'string',
        required: true,
        message: 'Enter your name:',
      },
    } as const satisfies FlagsConfig;
  4. In your main file (e.g., index.js), call the cli function to run the CLI:

     #!/usr/bin/env node
    
     import { cli } from '@whop-cli/runtime';
    
     cli(import.meta.url);
  5. Add the binary binding to your package.json

    {
      "type": "module",
      "bin": {
        "mycommand": "index.js"
      }
    }

Now, you can execute the new command from the terminal:

node index.js greet --name John

This will output: Hello, John!