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

nss-run

v0.4.0

Published

nss-run (not so simple run) is a very simplistic build tool.

Downloads

384

Readme

nss-run npm version

nss-run (not so simple run) is a very simplistic build tool.

You can find the source code on github.

Instead of something like gulp or grunt where you are required to execute all your build steps through plugins nss-run just gives you an easy way to call any external tool without having to find a special plugin first.

In version >=0.2 the style of this plugin got changed from being sync to async (through Promise) only. This change allows way more complex tasks. In most cases it should be very simply to migrate. Please take a look at the UPGRADE documentation!

Get started

Install globally (for a command line script):

npm install nss-run -g

or

yarn global add nss-run

Install in your project (to use nss-run api inside your nss-runfile.js):

npm install nss-run --save-dev

or

yarn add nss-run --dev

If you want to use Babel (7.x)

npm install babel-core babel-preset-env babel-register --save-dev

or

yarn add @babel/core @babel/preset-env @babel/register --dev

Create a nss-runfile.js (if you don't want to use babel) / nss-runfile.babel.js (if you want to use babel)

import { task, taskGroup, runTask, run } from "nss-run";

task("create:component", function (name) {
    console.log("Component with name " + name + " created");
});

task("lint", function () {
    return runTask("lint:test")
        .then(function () {
            return runTask("lint:source");
        });
});

taskGroup("lint:test", ["lint:test:unit", "lint:test:integration"]);

task("lint:test:unit", function () {
    return run("eslint ./test/unit");
});

// With ES6 Arrow functions you can do this
task("lint:test:integration", () => run("eslint ./test/integration"));

// And with babel (enabling async/await) you can also do this
task("lint:source", async () => {
    await run("eslint ./src");
    // Do something else here
});

Run:

nss-run create:component test
nss-run lint
nss-run lint:test
nss-run lint:test:unit

Tips:

  • ./node_modules/.bin/ is included into PATH when running commands by nss-run api method
  • Executing nss-run command without arguments displays list of all available tasks (+ description if available)
  • nss-run will automatic require babel-register if it can not find a nss-runfile.js but a nss-runfile.babel.js before including the runfile.

Why nss-run?

Is there really a need for a new build tool? We already have Grunt, Gulp, npm scripts, Makefile, runjs and many more.

Gulp and Grunt are very complex and require special plugins to run the tools that make our nodejs development environment.

Makefiles require you to install a tool outside of the nodejs ecosystem which makes getting started with a project harder then it needs to be.

npm scripts in my opinion are creating to much clutter within your package.json Your dependency file should not need to know how to build your project.

runjs is already going into the right direction (and this tool is heavily inspired by runjs). But some of the design decisions (it is to simple) makes it hard to be used for bigger projects where you just need a bit more flexibility in terms of how you wanna organize your tasks. In addition the design to make it all synchronize can cause a lot conflicts with existing nodejs libraries that might not support synchronized execution (e.g. some file parsers).

nss-run provides you with an very simple way to execute command line tools, npm installed tools as well as writing custom Javascript and using any npm library to create your own simple processing. No need to wait until a plugin makes your favorite tool available thru your build tool. I tried to combine my favorite part of gulp (the task definition system) and the simplicity of runjs to create a simpel (but not so simple ;)) build tool for any project size.

API

import { task, taskGroup, runTask, run } from "nss-run";

task(name, cb[, options])

Register a new task with the given name (do not use spaces in your name). If the task is going to be called the provided callback will be executed. A task might return a Promise to wait for async code to complete. Otherwise the task will be finished as soon as the callback returns.

Options:

{
    description: ..., // provide a description for this task for the task list output (String)
    hidden: ..., // Hide this task from the task list output (true/false) - default: false
}

Examples:

task("test", function () {
    // my task logic here
});
task("test", function () {
    // my task logic here
}, {
    description: "My test description"
});

taskGroup(name, tasksToExecute[, options])

Registers a new task (do not use spaces in your task name) that when called automatic calls all provided task names in a sequence (tasksToExecute has to be a string array). If you provide within the tasksToExecute array a array of strings the tasks in that sub array are going to be executed in parallel before proceeding with the next sequence item. The options are the same as the options for task.

Options:

{
    description: ..., // provide a description for this task for the task list output (String)
    hidden: ..., // Hide this task from the task list output (true/false) - default: false
}

Examples:

taskGroup("test", ["task1", "task2", "task3"]);
taskGroup("test", ["task1", "task2", "task3"], {
    description: "This task will call first task1, then task2 and last task3"
});
taskGroup("test", [["task1", "task2"], "task3"]);

runTask(name[, arg1[, ...]])

This will execute a registered task with the given name. All arguments you pass after the name will be directly passed thru to the tasks function callback. This method will always return a Promise that you should use to find out if the tasks has finished.

Examples:

runTask("lint");
runTask("lint", true, "my-second-argument");

run(cmd[, options])

Run given command as a child process and log the call in the output. It will always return a promise.

Options:

{
    cwd: ..., // current working directory (String)
    canFail: ..., // should promise be failed if program execution failed/returned error (true/false) - default: false
    stream: ..., // directly log the process output (true/false) - default: true
    env: ..., // environment variables to be passed down to the command (object)
    autoAnswer: ... // an array of auto answer objects to automatic answer interactive shell questions (array of Auto Answer Object's)
}

Auto Answer Object:

    search: ..., // the text to search for in the commands output (String)
    answer: ..., // the answer either a string or a function that either returns the answer string or a Promise (String|Function)
    hide: ..., // hide the answer in the terminal output if streaming is enabled (true/false) - default: false

Examples:

run("rm -rf ./lib");
run("http-server .").then((stdout) => {
    log(stdout);
}).catch((error) => {
    throw error;
});
run("http-server .", { stream: false }).then((stdout) => {
    log(stdout);
}).catch((error) => {
    throw error;
});