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

node-clapi

v2.0.0

Published

call any cli program from a JS class object

Downloads

2,879

Readme

node-clapi

This is an experiment using Proxy in nodejs as well as trying out typescript.

This module, known as clapi generates node api wrappers around command line programs much like shelljs, but is much less useful :D.

const clapi = require('clapi');

For any given command line string such as eslint lib src controllers (4 args), you can wrap as much of the beginning of it in clapi as you want.

Method calls then dispatch the constructed CLI string and return a promise resolving to the stdout of the command.

As such, the following are equivalent:


const eslint = new clapi('eslint');

// 1.
eslint('lib src controllers'); // -> Promise<stdout>

// 2.
eslint('lib', 'src', 'controllers'); // -> Promise<stdout>

// 3.
eslint.lib('src', 'controllers'); // -> Promise<stdout>
                                  // any method call is treated equivalently as the first argument (!)

The Proxy implementation intercepts the property access to lib which is undefined, and instead returns a Function<Promise<stdout>> method that will forward its arguments to the command line via child_process.exec.

In shelljs this would be something like shelljs.exec(eslint lib src controllers).stdout;.

@todo: how do you maintain an open process with child_process.spawn?

Well... what can you even do with it?

I don't know! You can pretend to have node APIs for command line programs.


// Commit something?
const git = new clapi('git');
git.commit('-am work in progress').then(() => {

    return git.push();

});

// Compile and execute hello.cpp?

const gpp = new clapi('g++');

gpp['hello.cpp']('-o', 'hello').then(() => {

    const hello = new clapi('./hello');
    return hello();

}).then(output => {

    assert(output[0] === 'Hello, world!');
    const rm = new clapi('rm');

    return rm.hello();

});


// ???

const npm = new clapi('npm');

npm.ls('typescript'); // check a dependency
npm.test(); // run your tests