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

drone-plugin

v1.0.5

Published

parse CI and plugin params for drone plugins

Downloads

2

Readme

drone-plugin - argument parsing for drone plugins

Build Status npm version Coverage Status

This package provies an API for parsing and validating the CI_* and PLUGIN_* envvars that are used by drone to pass build context to plugins.

Installation

yarn add drone-plugin

Example

Assume the following pipeline structure for your plugin in .drone.yml

pipeline:
  my-plugin:
    image: myrepo/post-message-to-chat
    webhook: 'http://some.chatserver.com/some/path?query=string'
    timeout: 42

This module makes it easy to parse, validate and coerce those plugin parameters as well as the drone build state variables, which are passed to your plugin in the environment in upper-case variable names. It will also do the same for the CI-context metadata (variables matching /^CI_.+/).

Example:

const { argParse } = require('drone-plugin');
const { webhook, timeout = 10, ci } = argParse()
  .arg('webhook=s!', 'timeout=n')
  .parse();

const req = require('request')({
  uri: webhook,
  timeout: (timeout * 1000),
  json: {
    text: `build #${ci.buildNumber} of ${ci.repoName} ${ci.buildStatus}`
  },
});
// and so forth...

Parsing arguments and CI context

drone creates UPPER_CASE named envvars for both CI-context and plugin parameters, but for purely aesthetic reasons, this API converts them to camelCase representations, dropping the CI_ or PLUGIN_ prefix.

The argParse() function returns an instance of class Args, which has various chainable methods for informing the argument parser of the plugin arguments, their types and whether or not they are required. The parse() method returns an object that contains all of this information as well as an embedded object named drone with the CI context (all of the CI_ args).

Argument spec strings

The .arg() method can be used to declare argument(s) along with type and demand hints included after an = in the name.

| hint char | purpose | | --------- | ------------------------------- | | s | string (default when no hint) | | n | numeric | | b | boolean | | t | timestamp (seconds since epoch) | | d | date | | o | object (also {}) | | a | array (slice) also [] | | ! | flag argument as required |

The array type can be combined with a scalar type.

Example:

.arg('timeout=n', 'title=s!', 'tags=as')

The above declares two arguments:

  • timeout is a numeric argument
  • title is a string argument and is required
  • tags is an array of strings

The step in the drone.yml file that should exist for the above example would look like this:

  myplugin:
    image: my/drone-plugin:latest
    timeout: 5
    title: hello world
    tags: [ beta, 1.0.11, latest ]

Args methods

.arg(spec[, ...])

chainable, this is detailed above. Note that you may pass a list of argument specs in one call to .arg() or you may invoke .arg() for each argument you are declaring.

These are all equivalent:

argParse().arg('name=s').arg('age=n');     //...
argParse().arg('name=s', 'age=n!');        // ...
argParse().string('name').number('age=!'); // ...
.boolean(name [,...])
.number(name [,...])
.string(name [,...])
.date(name [,...])
.object(name [,...])

chainable, declare an argument as a particular type. You may append =! to any name to indicate that it is a required parameter.

.demand(name [,...])

chainable, indicate that the named parameter is required.

.parse()

This returns an object containing all of the parsed arguments as well as an embedded object named ci that contains the drone CI-context.

Args properties

.ci

The drone environment variables, camelized and coerced.

.plugin

The plugin environment variables, camelized.

.env

An object containing both the ci and plugin variables.

See Also

License

View the LICENSE file (MIT).