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

console-craft

v1.0.5

Published

Simplify console program development, standardize program parameters and log output, and support user interaction or command-line parameter methods to launch the main program and subcommands.

Downloads

1

Readme

console-craft

(english/简体中文)

Simplify console program development, standardize program parameters and log output, and provide support for user interaction or command-line parameters to start the main program and subcommands.。

Use Cases

  • Support multiple subcommands.

  • Global parameters and subcommand parameters.

  • Program parameters can be obtained from environment variables and the command line.

  • Built-in dotenv handling, program parameters can also be obtained from dotenv.

  • Parameter source priority: interactive input > command-line parameters > environment variables > dotenv.

  • You can select subcommands and parameters through user interaction.

  • You can directly launch subcommands through command-line parameters.

  • It includes the log4js library, and you can set the log format through parameters.

  • It includes Commander, Inquirer, and Chalk for enriching program interaction and appearance.

Example

import { execa } from "execa";
import { cli } from "console-craft";
import { service } from "./serve";
const commands = [
  { name: "serve", args: [{ flags: "-p, --port <port>", default: 3000 }] },
  { name: "test", args: ["-r, --round <round>"] },
];
cli.initialize(commands, {
  globalArgs: [
    { flags: "-c, --config <config>", description: "config file" },
    "-log,  --log-level",
  ],
  author: "topabomb([email protected])",
  description: "node console app.",
});
cli.command("serve", async ({ name, args, logger }) => {
  const port = Number(args["port"]);
  await service.start(port);
  logger.level = args["log-level"] ? args["log-level"] : "debug";
  logger.info(`${name} listening : http://localhost:${args["port"]}`);
});
cli.command("test", async ({ name, args, logger }) => {
  await service.start(3000);
  const round = args["round"] ? Number(args["round"]) : 1;
  for (let i = 0; i < round; i++)
    await execa("npm", ["run", "test"]).pipeStdout(process.stdout);
  await service.close();
  logger.log("test complete.");
});
void cli.run();
  • Interactive mode screenshot

    • serve

    • test

  • Command-line parameter mode screenshot

    • serve

    • test

Install

npm install console-craft

Usage

cli

  • initialize

    cli.initialize(commands, {
      globalArgs: [
        { flags: "-c, --config <config>", description: "config file" },
        "-log,  --log-level",
      ],
      author: "topabomb([email protected])",
      description: "node console app.",
    });

    flags format:

    -short, --long <name>
    -short, --long [name]
    -short, --long
    -short
    --long
  • command

    cli.command("serve", async (cmd) => {
      const port = Number(cmd.args["port"]);
      await service.start(port);
      cmd.logger.info(
        `${cmd.name} listening : http://localhost:${cmd.args["port"]}`
      );
    });
  • run

    void cli.run();

inquirer

GitHub - SBoudrias/Inquirer.js: A collection of common interactive command line user interfaces.

chalk

GitHub - chalk/chalk: 🖍 Terminal string styling done right

logger

https://log4js-node.github.io/log4js-node/