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

circle-cli-util

v1.2.0

Published

Set of helpful CLI utilities

Downloads

6

Readme

circle-cli-util

Circle CI npm version License Inline docs

Set of helpful CLI utilities

Installation

npm install circle-cli-util --save

Action

let cli      = require('circle-cli-util');
let promise  = circle.projects(project).info();
let projects = yield cli.action('getting project', promise);
console.log(`project name: ${project.name}`);

// getting project... done
// project name: project

Note: to use yield you need to wrap this in a co block.

Prompt

Callback style

let cli = require('circle-cli-util');
cli.prompt('email', {}, function (_, email) {
  console.log(`your email is: ${email}`);
});

Promise style

let cli = require('circle-cli-util');
cli.prompt('email', {}).then(function (email) {
  console.log(`your email is: ${email}`);
});

Generator style (must be wrapped in a co block)

let cli   = require('circle-cli-util');
let email = yield cli.prompt('email', {});
console.log(`your email is: ${email}`);

cli.prompt options

cli.prompt('email', {
  mask: true, // mask input field after submitting
  hide: true // mask characters while entering
});

Confirm App

Supports the same async styles as prompt(). Errors if not confirmed.

Basic

let cli = require('circle-cli-util');
yield cli.confirmApp('appname', context.flags.confirm);

// !     WARNING: Destructive Action
// !     This command will affect the app appname
// !     To proceed, type appname or re-run this command with --confirm appname

> appname

Custom message

let cli = require('circle-cli-util');
yield cli.confirmApp('appname', context.flags.confirm, 'foo');

// !     foo
// !     To proceed, type appname or re-run this command with --confirm appname

> appname

Errors

let cli = require('circle-cli-util');
cli.error("App not found");
// !    App not found

Warnings

let cli = require('circle-cli-util');
cli.warn("App not found");
// !    App not found

Dates

let cli = require('circle-cli-util');
let d   = new Date();
console.log(cli.formatDate(d));
// 2001-01-01T08:00:00.000Z

Hush

Use hush for verbose logging when CIRCLE_DEBUG=1.

let cli = require('circle-cli-util');
cli.hush('foo');
// only prints if CIRCLE_DEBUG is set

Debug

Pretty print an object.

let cli = require('circle-cli-util');
cli.debug({foo: [1,2,3]});
// { foo: [ 1, 2, 3 ] }

Stylized output

Pretty print a header and hash

let cli = require('circle-cli-util');
cli.styledHeader("MyApp");
cli.styledHash({name: "myapp", collaborators: ["[email protected]", "[email protected]"]});

Produces

=== MyApp
Collaborators: [email protected]
               [email protected]
Name:          myapp

Table

cli.table([
  {app: 'first-app',  language: 'ruby', dyno_count: 3},
  {app: 'second-app', language: 'node', dyno_count: 2},
], {
  columns: [
    {key: 'app'},
    {key: 'dyno_count', label: 'Dyno Count'},
    {key: 'language', format: language => cli.color.red(language)},
  ]
});

Produces:

app         Dyno Count  language
──────────  ──────────  ────────
first-app   3           ruby
second-app  2           node

Mocking

Mock stdout and stderr by using cli.log() and cli.error().

let cli = require('circle-cli-util');
cli.log('message 1'); // prints 'message 1'
cli.mockConsole();
cli.log('message 2'); // prints nothing
cli.stdout.should.eq('message 2\n');

Command

Used for initializing a plugin command.

It expects you to return a promise chain. This is usually done with co.

let cli     = require('circle-cli-util');
let co      = require('co');
let request = require('request');
module.exports.commands = [
  {
    topic: 'apps',
    command: 'info',
    needsAuth: true,
    needsApp: true,
    run: cli.command(function (context) {
      return co(function* () {
        let projects = yield request.get('https://circleci.com/api/v1/projects');
        console.dir(app);
      });
    })
  }
];

With options:

let cli = require('circle-cli-util');
let co  = require('co');
module.exports.commands = [
  {
    topic: 'apps',
    command: 'info',
    needsAuth: true,
    needsApp: true,
    run: cli.command(
      {preauth: true},
      function (context) {
        return co(function* () {
          let projects = yield request.get('https://circleci.com/api/v1/projects');
          console.dir(app);
        });
      }
    )
  }
];

Tests

npm install
npm test

License

ISC