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

clii

v1.5.0

Published

Build cli app by writing plain js functions. Invoke these functions from cli directly.

Downloads

9

Readme

Clii

Build cli app by writing plain js functions. Invoke these functions from cli directly.

examples/demo.mjs

Quick Start

  1. Write some js code
/**
 * Another command
 * @param {Object} options
 * @param {number} options.num - Num variable
 * @param {("prod"|"dev"|"stage")} options.mode - Build mode
 * @param {string} message - Positional param
 */
export async function cmd2(options, message) {
}
  1. Install clii package.
npm i clii
yarn add clii
  1. Add follow content to your file.
import clii from "clii";

clii(import.meta.url);

All done.

clii automatically convert your file to cli app.

Try it in your terminal

$ node demo.mjs cmd2 -h
demo.mjs cmd2 <message> [options]

Another command

Positionals:
  message  Positional param                                  [string] [required]

Options:
      --port     Default port number                    [number] [default: 3000]
      --num      Num variable                                           [number]
      --mode     Build mode           [string] [choices: "prod", "dev", "stage"]

$ node demo.mjs cmd2 --num 3 --mode prod 'hello world'
{"options":{"num":3,"mode":"prod"},"message":"hello world"}

clii parse your ast js module file, generate cli interface according comments and exports semantics.

Export variable settings will be parsed as global options.

export const settings = {
  // Default port number
  port: 3000,
};
Options:
      --port     Default port number                    [number] [default: 3000]

Export function cmd2 will be parsed as subcommand. It's parameters will be parsed as subcommand's options.

Commands:
  demo.mjs cmd2 <message> [options]  Another command

The export default function will be th default command.

Cli tool

Usage: clii <cmd> [options]

Options:
      --version  Show version number                                   [boolean]
  -f, --file     Specific clii file                                     [string]
  -w, --workdir  Specific working directory                             [string]
  -h, --help     Show help                                             [boolean]

By defualt. clii looks for file cliifile.mjs in the current directory and upwards, so you can invoke it from any subdirectory of your project.

You can specify a file with option --file <path-to-script.mjs>.

The workdir will be the folder contains the mjs file. Use option ---workdir <path-to-dir> to change it.

Since clii can run js functions directly from cli, it can be used as task runner / build tool.

For examples, Write the following to the file cliifile.mjs.

import sh from "shelljs";

export function lint() {}

/**
 * @param {("prod"|"dev"|"stage")} mode
 */
export function build(mode) {
  lint();
  sh.exec(`tsc tsconfig.${mode}.json`);
}
clii lint
clii build

License

Apache-2.0