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

@ludekarts/task-runner

v0.4.2

Published

Small utility executing series of system tasks

Downloads

16

Readme

Task runner

Small utility for executing series of tasks with console reporting.

Usage

  1. Install with npm:

    npm install @ludekarts/task-runner --save-dev
  2. Create task.js file and import task-runner e.g.:

    echo 'const { TaskRunner, runCommand } = require("@ludekarts/task-runner");' > tasks.js
  3. Add your first tasks collection and add first task

    const tasksCollection = {};
    
    tasksCollection.checkNpmVersion = async function () {
      const npmVersion = await runCommand("npm -v", { resolveWithOutput: true, showOutput: true });
      if (!/^\d+\.\d+\.\d+/.test(npmVersion)) {
        throw new Error("No NPM! 😱");
      }
    };
    
    TaskRunner(tasksCollection, { showErrorReport: true });
  4. Execute tasks.js script thorugh system terminal

    > node tasks.js
  5. Expeceted result

    Running task: npmVersion
    npmVersion: completed ✔
    No errors occured!

How to run only some tasks?

  1. Create new toolbox.js file:

  2. Add following code to the file:

    const { TaskRunner, runCommand } = require("@ludekarts/task-runner");
    
    const selectiveList = process.argv.slice(2);
    
    const tasks = {
      async taskNameOne() {
        await runCommand("echo runing:taskNameOne");
      },
    
      async taskNameTwo() {
        await runCommand("echo runing:taskNameTwo");
      },
    }
    
    TaskRunner(tasks, { selectiveList, showErrorReport: true });
  3. Run only tasks you want like this:

    > node toolbox.js taskNameTwo

How to combine NPM scripts and taskRunner?

  1. Create new builder.js file:

  2. Add following code to the file:

    const { runCommand, message } = require("@ludekarts/task-runner");
    
    (async function builder(task, platform) {
      switch (task) {
    
        case "development":
          await runCommand(`cross-env NODE_PLATFORM=${platform} webpack serve --mode development`);
          break;
    
        default:
          message.error(`Unknown task: ${task}`);
          break;
    
      }
    }(...process.argv.slice(2)));
  3. Add new script to your package.json file e.g:

    "scripts": {
      "builder": "node ./builder.js"
    },
  4. Run npm script like this:

    npm run builder -- development desktop

API Reference

  • TaskRunner

    TaskRunner (
      tasksCollection: Object,
      {
        selectiveList: Array (undefined),
        showErrorReport: Boolean(false)
      }
    );

    Runs all tasks from given tasksCollection. Each task is called asynchronous. If showErrorReport flag set to TRUE at the end user will be presented with full Error Report. By passing to selectiveList array of tasks to run user can specify which task should run. Best way to utilize this feature is to connect it to precess.args e.g.:

    const selectiveList = process.argv.slice(2);
    TaskRunner(tasks, { selectiveList, showErrorReport: true });

    Thanks to this user can call script with names of tasks to run e.g.:

    > node tasks.js taskNameOne taskNameTwo
  • runCommand(

    runCommand(
      systemCommand: String,
      resolveWithData: Boolean(false)
    ): Promise;

    Allows user to run system commands. Returns promise that resolves by default with exit code or stringified buffer data if resolveWithData flag is set. If method resolves with data the output of the method will no be present in the console instead it will be returned as the promise result.

  • message (sync methods):

    • info( message: String ) - Output blue text to the console.
    • error( message: String ) - Output red text to the console.
    • success( message: String ) - Output green text to the console.
    • warning( message: String ) - Output orange text to the console.
    • input( message: String, defaultValue: String ) -> take userInput: String -> Promise() - Display Message and take user input.
  • file (sync methods):

    • save ( path: String, content: String, { override: Boolean(true), isAbsolute: Boolean(false) } ) - Save file under given path.
    • read ( path: String, isAbsolute: Boolean(false) ) -> content: String - Read file from given path.
    • saveJson( path: String, json: Object, { override: Boolean(true), isAbsolute: Boolean(false) } ) - Save JSON file under given path.
    • readJson( path: String, isAbsolute: Boolean(false) ) -> json: Object - Read JSON file from given path.
    • crawler( directory: String, processing: function ) -> Walk through given directory, and process each path with processing fn.

    ⚠️ NOTE: Use isAbsolute flag to mark path in file's methods as absoute in other case it will ge relative to the executed file.