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

@yuanqing/cli

v0.0.9

Published

## Quick start

Downloads

128

Readme

@yuanqing/cli npm Version build

Quick start

$ npm install --dev @yuanqing/cli
#!/usr/bin/env node

import { createCli } from '@yuanqing/cli'

const config = {
  name: 'my-cli',
  version: '1.0.0'
}
const commandConfig = {
  positionals: [
    {
      type: 'STRING',
      name: 'glob-pattern',
      description: 'Glob of input files.',
      required: true,
    }
  ],
  options: [
    {
      type: 'BOOLEAN',
      name: 'minify',
      aliases: ['m'],
      description: 'Whether to minify the output.',
      default: false
    },
    {
      type: 'STRING',
      name: 'output',
      aliases: ['o'],
      description: "Set the output directory. Defaults to './build'.",
      default: './build'
    },
    {
      type: 'NON_ZERO_POSITIVE_INTEGER',
      name: 'parallel',
      aliases: ['p'],
      description: "Set the maximum number of files to process concurrently. Defaults to '3'.",
      default: 3
    }
  ],
  examples: [
    "'*' --minify",
    "'*' --output './dist'",
    "'*' --parallel 10"
  ]
}

try {
  const result = createCli(config, commandConfig)(process.argv.slice(2))
  if (typeof result !== 'undefined') {
    const { positionals, options, remainder } = result
    console.log(positionals)
    console.log(options)
    console.log(remainder)
  }
} catch (error) {
  console.error(error.message)
  process.exit(1)
}

Parses positional arguments and options:

$ my-cli 'src/**/*' --minify --output './dist' --parallel 42
{ globPattern: 'src/**/*' }
{ minify: true, output: './dist', parallel: 42 }
[]

Handles option aliases:

$ my-cli 'src/**/*' -m -o './dist' -p 42
{ globPattern: 'src/**/*' }
{ minify: true, output: './dist', parallel: 42 }
[]

Throws an error if any required positional arguments (or options) were not specified:

$ my-cli
Argument <files> is required

Throws an error if any options (or positional arguments) were invalid:

$ my-cli 'src/**/*' -x
Invalid option: -x
$ my-cli 'src/**/*' --parallel 0
Option --parallel must be a non-zero positive integer but got '0'

Uses the configured default value for unspecified options (or positional arguments):

$ my-cli 'src/**/*'
{ globPattern: 'src/**/*' }
{ minify: false, output: './build', parallel: 3 }
[]

Handles remainder arguments:

$ my-cli 'src/**/*' foo -- bar --baz
{ globPattern: 'src/**/*' }
{ minify: false, output: './build', parallel: 3 }
[ 'foo', 'bar', '--baz' ]

Prints a nice usage message with --help or -h:

$ my-cli --help

  Usage:
    $ my-cli <glob-pattern> [options]

  Arguments:
    <glob-pattern>  Glob of input files.

  Options:
    -h, --help      Print this message.
    -m, --minify    Whether to minify the output.
    -o, --output    Set the output directory. Defaults to './build'.
    -p, --parallel  Set the maximum number of files to process concurrently.
                    Defaults to '3'.
    -v, --version   Print the version.

  Examples:
    $ my-cli '*' --minify
    $ my-cli '*' --output './dist'
    $ my-cli '*' --parallel 10

Prints the version with --version or -v:

$ my-cli --version
1.0.0

License

MIT