Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kd

Package Overview
Dependencies
Maintainers
4
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kd

Wrapper around kd cli tool to extend it.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
decreased by-33.33%
Maintainers
4
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 11 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc