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

@unimpaired/cli

v0.0.1

Published

This package is designed to be used as a CLI for node projects

Downloads

1

Readme

CAM CLI

This is the cam cli. It's here because we are dumb and forget stuff.

Usage

  1. build the monorepo project with: rushx build
  2. run npm link from this projects directory
  3. type cam into your shell

Adding New Commands

After any updates, you must re run rush build and you must navigate to this projects directory and run npm link.

IMPORTANT NOTE: This is a rush repo, so using npm link can be screwy. If you get errors, run rush unlink and try again. Note that you will not be able to run npm link inside of the "scripts." That will cause issues with Rush.

Basic Example

Step 1 - Create a function that does shit in any file in src/helpers/whatever-you-want.ts

import 'zx' // the $ syntax won't work without this
const printShitToConsole = async (shit: string) => {
  await $`echo "${shit}"`
}

Step 2 - Add a function that returns a new command with Commander to src/commands.ts

import { Command } from 'commander'
import { printShitToConsole } from './helpers/printShitToConsole'
const doShitCommand = () =>
  new Command('printShit') // "cam printShit" is the text you would type to run this command
    .alias('ps') // you could use "cam ps" instead of "cam printShit"
    .addHelpText('after', "You can't be helped") // if you ran "cam ps --help" then this text would be displayed after
    .description('prints stupid shit to console') // If you ran "cam" without arguments, this text would show up next to the command
    .action(() => {
      // This is the stuff that happens when the command is run
      printShitToConsole('shit')
    })

Step 3 - Add command to object inside of src/cli.ts

src / cli.js

const UNIMPAIRED_CLI = new Command('cam')
  // ... all commands are in this chain
  .addCommand(doShitCommand()) // This is the line you will add to this file

How to Add A Select Field

We use the inquirer package to do this

import inquirer from 'inquirer'
const askForDisability = () => {
  const prompt = inquirer.prompt(
    // First Question
    [
      name: 'firstQuestion',
      message: 'Do you want to quit life?',
      type: 'confirm',
      choices: ['yes', 'no'],
    ]
    // Second Question
    [
      name: 'secondQuestion',
      message: 'Which character traits match you?',
      type: 'checkbox', // they will select check the options they want
      choices: ['idiot', 'freak', 'sexual deviant', 'mindless murderer']
    ]
  ).then((prompt) => {
    // prompt is an object whose 'keys' equal the 'name' property in the prompt
    // the value is equal to the 'choices' that the user decided
    const firstQuestionData = prompt.firstQuestion
    const secondQuestionData = prompt.secondQuestion
    console.log('Go fuck yourself, ', secondQuestionData.join(' '))
  })
}

NOTES

File Structure

/src
  cli.ts // This is the file we run/export to use the command line
  commands.ts // This file contains all the commands that we use
  /helpers
    // ... any code that is imported into the above files
    // ... there really shouldn't be that much shit here.  Keep it simple.

Important Packages

  • commander: creates the CLI
  • inquirer: allows the cli to prompt a user for multiple options
  • zx: allows us to run bash scripts in our TS code