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

@buttery/tools

v0.0.2

Published

A file based CLI designed to making writing a CLI as easy as exporting a few functions in a file

Downloads

73

Readme

Buttery CLI

A file-based mechanism (similar to Remix routes) for creating a fully typed and documented CLI.

Description

This CLI tool simplifies the process of creating command-line interfaces (CLIs) by dynamically generating commands from files within a specified folder. It's designed to streamline CLI development by automating command creation, making it easy to define, develop, and build custom Typescript CLIs; all driven by established industry conventions.

This tool and mechanism abstracts away all of the complexity needed to create CLIs; from the hash-bangs to the argv processing... the Buttery CLI makes it dead simple to create complex CLIs at scale.

Getting Started

1. Create a butter.config.ts config file

Add a file at the root of your repository. This adds some basic information about your CLI such as the name, description, and version.

import path from "path";
import { fileURLToPath } from "url";

const __dirname = fileURLToPath(new URL(".", import.meta.url));

export default {
  name: "butter",
  description: "A buttery smooth CLI. Let's spread it on!",
  version: "0.0.1",
  root: path.resolve(__dirname),
};

2. Add command files in the /commands directory

The name of the file is the name of the command. The name is deliniated by a period which indicates a parent-command/sub-command relationship. In this case, our file name is test.primary:

  • test - parent command
  • primary - sub-command
// Filename: `commands/test.primary.ts`
import type {
  CommandAction,
  CommandArgs,
  CommandMeta,
  CommandOptions,
} from "@buttery/cli";

// Some information about your command
export const meta: CommandMeta = {
  name: "data",
  description: "Cras mattis consectetur purus sit amet fermentum.",
};

export const options: CommandOptions = {
  background: {
    type: "value",
    alias: "b",
    description: "The color of a nebulous thing",
    required: false,
  },
  "should-load": {
    type: "boolean",
    alias: "sl",
    description: "If something should load",
    required: false,
  },
};

export const args: CommandArgs = [
  {
    name: "username",
    description: "user to login",
    required: true,
  },
  {
    name: "password",
    description: "password for user, if required",
    required: false,
  },
];

export const action: CommandAction<typeof args, typeof options> = async (
  params
) => {
  console.log(`Hello from the "test.primary" command.`, params);
};

3. Build your CLI

Build your CLI using the butter cli build command.

yarn butter cli build

3. Invoke your CLI

yarn butter test primary [email protected] pword --background=blue --should-load

Output

Hello from the "test.primary" command. {
  args: { username: '[email protected]', password: 'pword' },
  options: { background: 'blue', shouldLoad: true }
}

Conventions

Directories

/src

Contains all of the files that are needed for the CLI builder to work. This would include utilities for parsing commands and any handlebars templates for dynamic config variable insertion and creation.

The functions and other things in this directory should only be accessible via the CLI and they should not be able to be imported when the cli builder is installed.

/lib

Contains all of the files that can be publicly imported when this package is installed using any package manager. This would include things like the createConfig function which will properly type and add intellisense to creating a buttery.config.ts file.

This directory is built using the TS compiler even though some files inside of this directory are used for the CLI commands like build and dev

/types

Contains all of the types that are used for both the src and lib files and will be added and exposed following the conventions set fourth in each directory.

/scripts

These are internal scripts that are invoked using this packages package.json. This allows for this package to share the script.build.ts file that is used both internally to this packages commands directory as well as for development of the build command. Essentially, having this script directory allows this package dog-food the buttery cli build command buy actually using it.

Todos

1st Priority

  • Combine all build scripts into esbuild script. Remove need for tsc
  • All scripts must build the commands, entry file and package.json
  • Create a buttery.config.json[cli] namespace to allow for configuration options for configuring the CLI builder.
  • Create a createConfig function like vite

2nd Priority

  • Create dev scripts for writing the CLI
  • Create dev CLI command for developing
  • Create build CLI Command building
  • Finish hard typing the options and args based upon the command file (options & values)
  • should add a option type for pre-defined values
  • properly parse ts option boolean values.
  • Semantic release
  • Add init command to ensure a commands directory is there and some other things
  • Add an SEO command for creating a PWA manifest file
  • Add an SEO command for creating favicon files
  • Watch and entire directory instead of just some files so when a new command is added it's added to the build files
  • Make a static build instead of runtime evaluation. The development errors surface when instantiating the CLI rather than when developing it.
  • fix the createBuild script