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

hubular

v1.1.0

Published

A framework for writing Hubot scripts. Inspired on Angular.

Downloads

3

Readme

Hubular

A Framework for writing complex Hubot Bots.

Inspired on Angular. Written in Typescript.

What is it like?

This is plain Hubot:

module.exports = (robot) ->
  robot.hear /badger/i, (res) ->
    res.send "Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS"

  robot.respond /open the pod bay doors/i, (res) ->
    res.reply "I'm afraid I can't let you do that."

This is Hubular:

import { HubularModule, HubularRobot, RobotHear, RobotRespond } from 'hubular';
import { Response } from 'hubot';

@HubularModule()
export class HeroesModule {

    @RobotHear(/badger/)
    protected badgers(res: Response<HubularRobot>) {
        res.send('Badgers? BADGERS? WE DON\'T NEED NO STINKIN BADGERS');
    }

    @RobotRespond(/open the pod bay doors/)
    protected openThePodBayDoors(res: Response<HubularRobot>) {
        res.send('I\'m afraid I can\'t let you do that.');
    }
}

Okay.. that's not so impressive..

Dependency Injection

Behind the hoods, Hubular uses injection-js to create a flat injector, you can inject providers into any @HubularModule() or @Injectable().

If you are familiar with Angular, this should ring a bell:

// door.serivce.ts
import { Injectable, Logger } from 'hubular';

@Injectable()
export class DoorService {

    constructor(private logger: Logger) { }

    public tryOpenThePodBayDoors() {
        // TODO: Open the doors, perhaps store status in brain?
        this.logger.info('Opening the doors');
        return true;
    }
}
// door.module.ts
import { HubularModule, HubularRobot, RobotHear } from 'hubular';
import { Response } from 'hubot';
import { DoorService } from './door.service';

@HubularModule({
    providers: [
        // Providers declared in any module can be injected into any module.
        DoorService
    ]
})
export class DoorModule {

    constructor(
        private door: DoorService,
        // private someOtherService: FromOtherModule
    ) { }

    @RobotHear(/open the pod bay doors/)
    protected openThePodBayDoors(res: Response<HubularRobot>) {
        if (this.door.tryOpenThePodBayDoors()) {
            res.send('The doors have been opened.');
        } else {
            res.send('I\'m afraid I can\'t let you do that.');
        }
    }
}
// app.module.ts
import { HubularModule, RobotCatchAll, HubularRobot } from 'hubular';
import { HeroesModule } from './heroes/heroes.module';
import { Response } from 'hubot';

@HubularModule({
    imports: [
        DoorModule
    ]
})
export class AppModule {

    // The AppModule is also resolved using DI
    // although it's only purpose should be to simply import other modules
    //constructor(robot: HubularRobot) {}

    @RobotCatchAll()
    protected onCatchAll(res: Response<HubularRobot>) {
        res.send('Sorry, can\'t help you with that.');
    }
}

Creating new Hubular Projects

You can use Yeoman to scaffold a brand new Hubular App:

yarn global add generator-hubular
yo hubular

If everything goes fine you should have a working Hubular App. Test it's working with

yarn start

Adding Hubular to existing Hubot

  1. Install Hubular in your Hubot project

    yarn add hubular reflect-metadata
    yarn add --dev typescript
  2. Temporary create a new Hubular project using the previous guide. This will get all the latest files for you, copy into your project the tsconfig.json and src/.

  3. Run tsc

  4. Run Hubot with --require hubular-scripts

    bin/hubot --require hubular-scripts