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

@keg-hub/cli-utils

v0.9.0

Published

Utility methods for writing Custom Tasks consumed by the Keg-CLI

Downloads

4,853

Readme

Keg-Hub Cli-Utils

  • Common utility methods for developing Node CLI's and writing custom tasks
  • This makes the process faster easier, and removes code duplication across projects

Install

With yarn

yarn add @keg-hub/cli-utils

With npm

npm install @keg-hub/cli-utils

CLI task setup

  • runTask - Find and execute a task
    • This method allows resolving a task based on the passed in tasks object and arguments
    • It's recommended to add a call it from a node script within your project
    • Then add a reference to that script in your package.json - scripts section
      • This allows calling it from a package manager such as yarn or npm like this =>
          // In your package.json file
          "scripts": {
            // ...other scripts
            "task": "node ./tasks/runTask.js",
          }
                
          // In tasks/runTask.js
          const { runTask } = require('@keg-hub/cli-utils')
          const taskDefinitions = require('./taskDefinitions')
        
          runTask(
            // Object containing all tasks definitions for the project
            taskDefinitions,
            // Default params passed to all tasks
            { env: process.env.NODE_ENV || 'local' }
          )
      • This above script can then be called like this => yarn task <task-name> <task-options>
        • Assuming a start task definition exists, running yarn task start will call the start task
    • This method will handle
      • Loading the global config defined at ~/.kegConfig/cli.config.json if it exists
      • Parsing options relative to a task-definitions options property
        • They are then passed to the task as the params key of the args object
  • setAppRoot - Register a taps root directory
    • When calling custom tasks outside of the keg-cli, calling this method is recommended
      • It ensures that in mono-repo or sym-linked situations, the project root can be properly resolved
      • That said, in most cases calling this method is NOT needed
        • But, since nothing is inversely affected by it, it's recommended to set it and forget it
        • Add it to the top of a tasks script file like this =>
            const { setAppRoot } = require('@keg-hub/cli-utils')
            setAppRoot(appRoot)
          
            module.exports = { customTask: { ...taskDefinition } }
        • See tap-vistapps-app tasks/index.js file for an example
  • registerTasks - Register Custom Tasks
    • In most situations calling registerTasks is NOT needed
      • It could be used when passing the tasks in the first argument of runTask is not possible
        • For example in a third-party package installed as a node module
      • It must be called prior to the call to the runTask method to ensure the tasks are loaded
        • It takes a single Object argument that should contain key/value pairs task name/definitions For example => registerTasks({ taskName: { ...taskDefinition } })