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

kd

v1.0.1

Published

Wrapper around kd cli tool to extend it.

Downloads

174

Readme

node-kd

A thin node.js wrapper around kd cli tool.

What?

It's designed to be an extension layer on top of kd so that one could extend the functionality of each commands.

npm install --global kd

# it exposes a `kdx` binary.
kdx auth login
# => same as running kd auth login

Extending kd

  1. To match kdx your command create a file under src/commands/your/command.js
// commands/example/init.js

// this command will run when we type `kdx example init`

export default {
  run(args, { run }) {
    console.log('running init command')

    return askTeamAndBaseUrl().then(({baseurl, team}) => {
      return run(
        ['auth', 'login', '--baseurl', baseurl, '--team', team]
      )
    })
    .then(() => {
      return run(
        ['template', 'create']
      )
    })
  }
}

a command is a simple object containing the following keys:

  • before(initialArgs: Array<String>, { run: Function }) => args: Promise<Array<String>>

    Accepts initial args, and it's expected to return an array to be passed to the run function as args. If return value is a promise, the resolved value will be passed to run function.

    • tl;dr: Return a promise if you need to do async stuff.
  • run(args: <Array<String>>, { run: Function }) => Promise

    A function accepts the result of before function. If before function doesn't exist, it will be passed the original args.

  • after(result: any) => Promise

    A function accepts the result of run function.

IMPORTANT: You HAVE TO return either an array or a Promise which will return an array from before function. This result will either be passed to run function of the command if defined, or to the main kd command you are wrapping.

  1. Try your command:
cd /your/node-kd/path
npm run run-cli -- example init
# => running init command

or with npm link

cd /your/node-kd/path
npm link

kdx example init
# => running init command
  1. Add functionality to an existing command:
// file => src/commands/template/create.js
// cmd => kdx template create

export default {

  before(args) {

    console.log(' before template create ')

    return args
  }

  after(result) {

    console.log(' after template create ')

    return args
  }

}

run in terminal:

kdx template create
# => before template create
# => ...
# => ...
# => ... (running kd template create)
# => ...
# => ...
# => after template create

Since we didn't create a run function in src/commands/template/create.js it didn't override the main functionality of kd template create; it just ran before(args) before and after(result) after it.