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

ronin-coffeescript

v1.0.2

Published

Libary to build shining CLI tools using coffeescript

Downloads

3

Readme

Ronin (Coffeescript Fork)

Toolkit for building shining CLI programs in Node.js using coffeescript.

This is the coffeescript fork of Ronin. The original javascript version is Ronin. The changes are to make it work with .coffee files instead of .js. I'm actively using this project so I will do my best to keep it up-to-date with the original project.

I don't use the middleware functionality so I didn't convert that to coffeescript. It uses a named function which we can't really do in coffeescript other than with just plain escaped JS. I'm pretty sure it should work if your middleware files are .js. If not feel free to submit a pull request to patch that.

Installation

npm install ronin-coffeescript --global

Getting Started

Creating basic structure

Execute the following command to generate basic skeleton for your program:

ronin new hello-world

Ronin will create a hello-world directory (if it does not exists or empty) and put everything that's needed to start developing your CLI tool immediately.

Initialization

Here's how to initialize CLI program using Ronin:

ronin = require 'ronin'
program = ronin __dirname
program.run()

Creating commands

Next, to setup some commands, simply create folders and files. The structure you create, will be reflected in your program. For example, if you create such folders and files:

commands/
--  apps.coffee
--  apps/
    -- add.coffee
    -- remove.coffee
--  keys/
    -- dump.coffee

In result, Ronin, will generate these commands for you automatically:

$ hello-world apps
$ hello-world apps add
$ hello-world apps remove
$ hello-world keys dump

Each folder is treated like a namespace and each file like a command, where file name is command name.

To actually create handlers for those commands, in each file, Command should be defined:

Command = require('ronin').Command

AppsAddCommand = module.exports = Command.extend
    desc: 'This command adds application'
    run: (name) ->
        // create an app with name given in arguments

To run this command, execute:

$ hello-world apps add great-app

Whatever arguments passed to command after command name, will be passed to .run() method in the same order they were written.

Specifying options

You can specify options and their properties using options object.

AppsDestroyCommand = module.exports = Command.extend
    desc: 'This command removes application'
    options:
        name: 'string'
        force:
            type: 'boolean'
            alias: 'f'
    run: (name, force) ->
        unless force
            throw new Error '--force option is required to remove application'
        // remove app

Note: Options will be passed to .run() method in the same order they were defined.

Customizing help

By default, Ronin generates help for each command and for whole program automatically. If you wish to customize the output, override .help() method in your command (program help can not be customized at the moment):

HelloCommand = Command.extend
    help: ->
        "Usage: #{@programName} #{@name} [OPTIONS]"
    desc: 'Hello world'

Customizing command delimiter

By default, Ronin separates sub-commands with a space. If you want to change that delimiter, just specify this option when initializing Ronin:

program = ronin()

program.set
    path: __dirname
    delimiter: ':'

program.run()

After that, apps create command will become apps:create.

Middleware

There are often requirements to perform the same operations/checks for many commands. For example, user authentication. In order to avoid code repetition, Ronin implements middleware concept. Middleware is just a function, that accepts the same arguments as .run() function + callback function. Middleware functions can be asynchronous, it makes no difference for Ronin.

Let's take a look at this example:

var UsersAddCommand = Command.extend({
    use: ['auth', 'beforeRun'],
    
    run: function (name) {
        // actual users add command
    },
    
    beforeRun: function (name, next) {
        // will execute before .run()
        
        // MUST call next() when done
        next();
    }
});

In this example, we've got 2 middleware functions: auth and beforeRun. Ronin allows you to write middleware functions inside commands or inside root/middleware directory. So in this example, Ronin will detect that beforeRun function is defined inside a command and auth function will be required from root/middleware/auth.js file.

Note: To interrupt the whole program and stop execution, just throw an error.

Tests

npm test

License

Ronin is released under the MIT License.