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

@snailicide/cli-app

v0.4.0

Published

Node Cli App Boilerplate with yargs, zod, chalk

Downloads

36

Readme

@snailicide/cli-app 🐌

NPM License: MIT code style: prettier

Node Cli App Boilerplate with yargs, zod, chalk


NodeJS TypeScript Zod

Author

👤 Gillian Tunney

Recommended package manager is pnpm

PNPM

@snailicide/cli-app 🐌


The @snailicide/cli-app package is a builder application for making custom command-line interface (CLI) application. Developers can quickly bootstrap a boilerplate with powerful validation/parsing schemas. It leverages several libraries to provide robust and interactive user experience.

Key Features

  • Command-Line Parsing: Utilizes yargs and yargs-interactive for parsing command-line arguments and handling interactive prompts.
  • Schema Validation/Handling: Use zod schemas to parse/validate input, including resolving user options & application configurations, and generating Yargs-compatible option objects.
  • Configuration Management: Manages application configurations using schemas defined with zod. This ensures that configurations are validated and adhere to expected structures.
  • Title /HelpScreen Management: Manage custom cli options and customize appearance of title/help menu terminal output.

Installation

This library is published in the NPM registry and can be installed using any compatible package manager as a development dependency.

#pnpm
pnpm add @snailicide/cli-app

#yarn
yarn add @snailicide/cli-app

#npm
npm install @snailicide/cli-app

Example Usage

The cli-app package can be initialized and configured using the initApp function, which sets up the application based on provided schemas and options, and supports interactive prompts if needed.


import { z } from 'zod'

import {
  AppConfigIn,
  commonFlagsSchema,
  initApp,
  InitSuccessCallback,
  WrappedSchema,
  wrapSchema,
} from './index.js'

/** Define custom schema, wrapper is required to avoid typescript error */
const custom_schema = z.object({
  testarr: z.number().array().default([]).describe('test array'),
  testarr2: z.string().array().default([]).describe('test array'),
})
const my_merged_schema = wrapSchema<typeof commonFlagsSchema>(commonFlagsSchema)
  .merge(custom_schema)
  .transform((value) => {
    return value
  })
  .describe('this is a sample app that is made of fun')

type MergedSchema = WrappedSchema<typeof my_merged_schema>

/** Set the init function which will be called after app is intialized with typed arguments. */
const initFunc: InitSuccessCallback<MergedSchema> = <
  Schema extends
    | z.AnyZodObject
    | z.ZodEffects<z.AnyZodObject> = typeof commonFlagsSchema,
>(
  args: z.infer<Schema>,
) => {
  if (args['testarr']) {
    console.warn('RESOLVED APP ARGS: ', args)
  }
  console.log(JSON.stringify(args))
  return true
}

/** Example app configuration options */
const exampleAppConfigOptions: AppConfigIn<MergedSchema> = {
  description: 'This is an example to demonstrate use',
  //code editor error
  examples: [
    ['$0 --config "~/config.json"', 'Use custom config'],
    ['$0 --safe', 'Start in safe mode'],
  ],
  flag_aliases: {
    outDir: 'o',
    rootDir: 'r',
    // help: 'h',
    //version: 'v',
  },
  hidden: ['debug', 'testarr2'],
  name: 'Example App',
}

/** Initialize App */
const initialize = async (): Promise<'SUCCESS' | 'ERROR'> => {
  const instance_yargs = await initApp<MergedSchema>(
    my_merged_schema,
    exampleAppConfigOptions,
    initFunc,
  )
  if (instance_yargs === undefined) {
    process.exit(1)
    return 'ERROR'
  }
  process.exit(0)
  return 'SUCCESS'
}

export default initialize()

Helpful Links