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

srun

v0.0.9

Published

define atomic steps, then build scripts with them. a global context object between steps is included for you!

Downloads

15

Readme

node-step-runner (srun)

define atomic steps, then build scripts with them. a global context object between steps is included for you!

mind you, this runner is pretty opinionated

Why not grunt?

grunt is hella confusing

Usage

CLI usage

run scripts with:

srun --script=<scriptname> [--verbose]

# e.g. srun --script=postpublish # runs ./scripts/postpublish.js

steps

steps are individual actions of a script and go in ./lib/steps.

module.exports = {
    // the pretty/formatted name of the step, only used for display
    name: 'Hello Step',

    // a description of your step, used to help clients understand
    // what it does and its sideeffects
    description: 'Says hello',
    
    options: {
        // define options here so people don't have to look through
        // your code to find them. `step-runner` will handle extracting
        // and validating the presence of all the options
        'name': 'Name to say hello to'
    },

    // the action function is given an options parameter and a callback
    action: function(opt, cb) {
        // use the options defined above (given a client has provided them)
        // form the `opt` parameter
        console.log('Hello %s!', opt.name);
        cb();
    }
}

Scripts

scripts go in ./scripts and call steps with ./lib/step-runner.js.

var StepRunner = require('../lib/step-runner');

module.exports = function(cb) {
    var stepRunner = new StepRunner({
        verbose: this.verbose
    });
    
    // you could alternately use promises to control flow
    stepRunner.runStep('increment-version', {
        packagePath: __dirname + '/../package.json'
    }, function() {
        stepRunner.runStep('git-add', {
            files: ['package.json']
        }, function() {
            stepRunner.runStep('git-commit', {
                commitMessage: 'Release ' + this['increment-version'].oldVersion,
            }, function() {
                cb();
            });
        });
    });
}

Global context

when a step runs, it gets a context of this[stepName], where this is the context of the step-runner callbacks and stepName is the name of the step based on the filename. thus, you can set values onto the context and access them in your script to configure later steps:

// ./lib/steps/number-maker.js
module.exports = {
    name: 'Number Maker',
    description: 'Adds a random number to the context',
    options: {},
    action: function(opt, cb) {
        // setting `this[something]` in a step will make it available in your script later
        this.number = Math.random() * 1000;
    }
}

then:

stepRunner.runStep('number-maker', {}, function() {
    // access the context values in your script:
    console.log('give me a number... %s', this['number-maker'].number);
    
    // say some other step needs a number to configure...
    stepRunner.runStep('something-else', {
        'number-input': this['number-maker'].number
    }, function() {
        // the context can be accessed later, as well
        console.log('i still have this number: %s!', this['number-maker'].number);
        // ... do something
    });
});

Using with npm postpublish

i made this with the mindset of easily importing my postpublish script into my package.json file:

npm install srun --save-dev

add to package.json

...
"scripts": {
    "postpublish": "./node_modules/.bin/srun --script=postpublish"
}
...

every time your npm publish your module, the patch number will increment by one and you will get a git commit notifying of the release. neato!