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

dynamic_cli_creator

v0.0.1-a

Published

It creates CLI, by reading commands from YAML files and allows for integrating external libraries in command execution.

Downloads

4

Readme

Dynamic CLI

This is a vorpal wrapper. It provides a way to dynamically configure your commands with the help of simple yaml files.

It's main feature is to integration with the third party library functions, inside command executing function i.e. inside action.

Its work in progress, I am yet to integrate all possible vorpal options via YAML config.

Installation

To install it via npm

npm install dynamic_cli_creator

Another way is to mention it in package.json shown below

 "dependencies": {
    "dynamic_cli_creator" : "git://github.com/bmhaskar/DynamicCLI.git#master"
  }

Import it via ES6 syntax like

import  DynamicCLI from 'dynamic_cli_creator';

How to use

To create CLI, create an instance of imported class i.e. DynamicCLI with props having following interface

export interface cliPropsExtensionsInterface {
 [index:string]:{"extFunc":Function, options:Object}
}
export interface cliPropsInterface {
 cliName?:string;
 pathToCommandFiles?:string;
 extensions?:cliPropsExtensionsInterface;
}

For example


//I am using typescript in example, it does not restrict use of library 
//to typescript, it also can be used with ES6/ES5

const simulatorOptions = <cliPropsInterface> {
    cliName: "dataSimulator",
    pathToCommandFiles: path.resolve(__dirname , 'commands'),
    extensions: {"dataGenerator": { "extFunc": dataGenerator, options: {name: "commentsGenerator"}}}
} ;

const dataSimulator = new DynamicCLI(simulatorOptions);

For YAML command syntax checkout the example/commands/command.yml The interface of YAML config is as follows

export interface vorpalCommandConfigInterface {
    command:commandInterface,
    action:(args:Object, cb?:Function) => void | Promise<void>,
    description?:string,
    alias?:string,
    autocomplete?:autoCompleteInterface,
    option?:commandOptionsInterface |  Array<commandOptionsInterface>,
    types?:Object,
    hidden?:boolean,
    parse?:(command:string, args:Object) => string,
    help?:(args:Object) => void
    validate?:(args:Object) => boolean | string,
    cancel?:() => void,
    use?:any;
}

example for above is

command: 'foo <requiredArg> [optionalArg]'
option:
  optionName: "-v"
  description: "Option description"
description: 'Outputs "bar"'
alias: 'fooseball'
action: !!js/function >
          function (args, cb) {

            this.parent.generateData(args);
            console.log( 'Wow! JS-YAML Rocks!', args);

            cb();
          }
help: "This is a dummy command just logs arguments you passed."
cancel: !!js/function > 
          function() {
            console.log('Cancel function was called')
          }

option can be an array like

option: 
   - 
     optionName: "-o1"
     description: "Option1 description"
   - 
     optionName: "-o2"
     description: "Option2 description"

Use cases

This can be used when your porject need to do have Command Line Interface and you dont want to recode stuff you already have you can use this library to create a CLI and integrate your existing code/functions.

This library helps in quick bootstrapping of CLI. No need of writting the boilerplate for your commands, YAML configuration saves, writing code and testing the same.

TODO

  • [ ] Add how it works
  • [ ] Create NPM package
  • [ ] Add tests
  • [ ] Add code coverage