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

bauer-cli

v0.2.5

Published

Command-line interface for bauer-crawler.

Downloads

9

Readme

node-bauer-cli

Command-line interface for bauer-crawler.

Installation

This is a command line tool, therefore it must be installed globally.

npm install bauer-cli -g

Usage

  • bauer init script - Creates a new bauer script using an yeoman generator generator-bauer-script.
  • bauer init plugin - Creates a new bauer plugin using an yeoman generator generator-bauer-plugin.
  • bauer run - Run the bauer script in the current directory.
  • bauer add [PLUGIN] - Adds a plugin to the bauer script in the current directory.
  • bauer remove [PLUGIN] - Removes a plugin from the bauer script in the current directory.

Bauer Script

A bauer script is a node module that exports a function. The context variable is a bauer-crawler instance, which provides .promise method to start a promise chain. The function should return a Promise that tells the script to end or repeat when its resolved. It uses bluebird promise implementation extended with features from loaded plugins.

module.exports = function() {
  
  return this.Promise
    .fetch("http://http-bin.org")
    .scrape({
      "a[href]": {
        links: {
          url: "attr:href",
          name: "text"
        }
      }
    })
    .extract("$..url")
    .map(function(url) {
      
      return this.Promise
        .fetch(url)
        .then(function() {
          
        });
    })
    .catch(function(error) {
      console.log('something wrong happened',error);
    })
    .repeat();
};

The package.json file contains list of plugins to load and its configurations, besides common node module stuff.

{
  "name": "bauer-project",
  "plugins": [
    "bauer-plugin-fetch",
    "bauer-plugin-scrape",
    "bauer-plugin-extract"
  ],
  "config": {
    "fetch": {
      "workers": 3
    },
    "scrape": {
      "workers": 2
    },
    "extract": {
      "workers": 1
    }
  },
  "dependencies": {
    "bauer-plugin-fetch": "*",
    "bauer-plugin-scrape": "*",
    "bauer-plugin-extract": "*"
  }
}

Bauer Plugin

A bauer plugin is also a node module that follows a simple pattern. Usually it extends the Promise with new methods that request processing from workers and resolves when response comes. That's what a bauer plugin looks like:

module.exports = {
  
  // the name is used by configurations and workers
  name: "doSomething",
  
  // default configurations
  config: {
    workers: 2
  },
  
  // executed when starting main process (usually not necessary)
  master: function() {
    
  },
  
  // executed when starting each worker
  worker: function(worker,config) {
    
    worker.on('request',function(request,response) {
      // do something with the request and ...
      response.sendOk({ output: "yo" });
      // or if something goes wrong ...
      response.sendError(new Error("aw crap"));
    });
    
    // this is necessary to tell master the worker is ready to use
    worker.sendReady();
  },
  
  // extend the bluebird Promise prototype
  promise: {
    
    doSomething: function() {
      return this.requestWorker("doSomething",{
        input: value
      }).get("output");
    }
  }
  
};

If the plugin gets bigger then its possible to move each part to a separate file which will only be required by the process where it belongs, making each master/worker process as lean as possible.

module.exports = {
  
  name: "myPlugin",
  
  config: {
    // ...
  },
  
  // worker.js should export a function
  // required by the worker process only
  worker: __dirname + "/worker.js",
  
  // promise.js should export an object with methods to extend Promise prototype
  // required by the master process only
  promise: __dirname + "/promise.js"
  
};

License

MIT