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

@fal-works/s-l-t-r

v0.5.0

Published

Something like a task runner.

Downloads

4

Readme

s-l-t-r

Something Like a Task Runner.

  • Run multiple commands in sequence or in parallel.
  • Simple. Lightweight. No dependencies.
  • Might be an alternative to NPM scripts (node_modules/.bin is automatically addded to PATH).
  • Write your own script in JS and construct any tree structure for defining the execution order.
  • Create a router so that you can run different commands according to arguments.
  • Check summary of execution results and see where it took time or where it failed.

GitHub: https://github.com/fal-works/s-l-t-r

Install

npm install -D @fal-works/s-l-t-r

How to Use

Define Commands

Here we will write a script and make a tree structure consisting of Command elements.

  • Use cmd() for defining a Command with a single command line.
  • Use seq() or par() for defining a grouping Command that runs multiple child Commands.
    seq() for sequence, par() for parallel. They can be nested as well.

For example, a script for building the library s-l-t-r itself (say build.js) would look like this:

// build.js

/** import */
const s_l_t_r = require("@fal-works/s-l-t-r");
const { cmd, seq, par } = s_l_t_r; // functions for creating command elements
const { cleandir } = s_l_t_r.builtin; // built-in functions for specific purposes

/** prepare commands used frequently */
const lint = (files) => cmd("eslint", "--fix", files);

/** clean-up files in parallel */
const clean = par(cleandir("lib"), cleandir("types")).rename("clean");

/** emit files into lib/types */
const emit = cmd("tsc", "--skipLibCheck");

/** format files in parallel */
const format = par(lint("lib/**/*.js"), lint("types/**/*.ts")).rename("format");

/** do all of the above in sequence */
const build = seq(clean, emit, format).rename("build");

Something more:

  • seq() and par() accept also any command line string values.
  • Use cmdEx() for creating a Command from any async function.
  • Use ignoreFailure() method if you want to run subsequent commands whether the command in question succeeds or not.

Run

Use run() to start executing any Command:

// build.js

/* ...(see above)... */

s_l_t_r.run(build);

Now you can simply run the script with Node.js:

# on the CLI or NPM script
node build.js

Routing

As an alternative to the top-level run() function,
create a router so you can receive any key and run different Commands:

// build.js

/* ...(see above)... */

/**
 * This router accepts the keys: "clean", "emit", "format" or "build",
 * otherwise it prints the registered mapping between keys and commands.
 */
const router = s_l_t_r.tools.createRouter({ clean, emit, format, build });

const CLI_ARGUMENT = process.argv[2];
router.run(CLI_ARGUMENT);

Now you can run the script passing any key that specifies the Command to be executed:

# on the CLI or NPM script
node build.js clean

Result Summary

When run() completes, it outputs a summary of the execution results.

It looks like this:

--         | [seq] build
--         |   [par] clean
ok   0.01s |     cleandir lib
ok   0.01s |     cleandir types
ok   1.30s |   tsc
--         |   [par] format
ok   1.49s |     eslint --fix lib/**/*.js
ok   1.24s |     eslint --fix types/**/*.ts

...or can also be flattend by changing the config:

sltr.config.setResultSummaryType("list"); // default: "tree"

which looks like this:

ok   0.01s | cleandir lib
ok   0.01s | cleandir types
ok   1.32s | tsc
ok   1.49s | eslint --fix lib/**/*.js
ok   1.23s | eslint --fix types/**/*.ts

You can also change the display in the summary for each Command individually:

  • Use rename() method for changing the display name.
  • Use hide() method to just hide it.
  • Use collapse() method to collapse a grouping command (seq() or par()) and hide its children.

Other

The quiet mode suppresses log messages and only the final result (1 line, whether completed or not) is printed.

sltr.config.setQuiet();