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

@ygor/tasks

v5.4.1

Published

A promising task runner.

Downloads

146

Readme

@ygor/tasks

NPM version Downloads Build Status Coverage Status

A no-frills task runner. Built on promises to work wonderfully with async and await in Node.js 8 and above. Part of the Ygor toolkit.

Node is the CLI, npm is the plugin system. Go nuts.

Install

$ npm install --save-dev @ygor/tasks

Usage

Node is the CLI.

Usage: node <file> [task] [options]

  file   The filename of your script.
  task   The name of the task to run (default: 'default').

Options:

  -q, --quiet   Suppress logging (default: false).
      --run     Auto-run task (default: true).

Create a JavaScript file, write some functions, tell Ygor.

// make.js

const tasks = require('@ygor/tasks');

async function bundle() {
    // bundle something
}

async function instrument() {
    // instrument tests
}

async function test() {
    // test something
}

async function cover() {
    await instrument();
    await test();

    // report coverage
}

tasks
    .add('default', bundle)
    .add('test', test);
    .add('cover', cover);

To run a task, execute the file with Node.js (or with babel-node if that's how you roll) and indicate which task to perform.

$ node make
$ node make test
$ node make cover

Deferred Tasks

If you need to define tasks asynchronously, you may call tasks as a function at a later time.

ToolsApi
    .getTools()
    .then(tools => {
        return tasks()
            .add('foo', tools.foo)
            .add('bar', tools.bar);
    });

Subtasks

You may also call tasks() within a task callback to create subtasks.

function childA1() { console.log('hi from a1'); }
function childA2() { console.log('hi from a2'); }

function parentA() {
    // Subtasks
    return tasks()
        .add('1', childA1)
        .add('2', childA2);
}

function childB1() { console.log('hi from b1'); }
function childB2() { console.log('hi from b2'); }

function parentB() {
    // Subtasks
    return tasks()
        .add('1', childB1)
        .add('2', childB2);
}

tasks
    .add('a', parentA)
    .add('b', parentB);

Then execute subtasks by passing the parent task name as the first argument and the child task name as the second.

$ node make a 2
hi from a2

$ node make b 1
hi from b1

Bring Your Own Arguments

You can override the default cli parsing by providing your own arguments object.

function logCli(cli) {
    console.log(cli);
}

tasks({ foo: 'bar' })
    .add('log', logCli);
$ node make log
{ foo: 'bar' }

API

tasks.cli

Command-line arguments as parsed by minimist.

tasks.add(name, callback): tasks

  • name {String} Unique task identifier.
  • callback {Function(cli, tasks)} Function to run when the task is invoked.

Registers a task with Ygor. The callback provided will be executed with tasks.cli as the first argument and tasks as the second.

function foo(cli, tasks) {
    console.log(cli, tasks);
}

tasks.add('foo', foo);

tasks.run(name): Promise<>

  • name {String} Unique task identifier.

Tells Ygor to run a task. This is used internally and generally shouldn't be invoked directly. Ygor recommends that tasks be declared as standalone functions.

// Avoid

tasks.add('foo', function () {
    // do something
});

tasks.add('bar', function (cli, t) {
    t.run('foo');
});

// Recommended

function foo() {
    // do something
}

function bar() {
    foo();
}

tasks
    .add('foo', foo)
    .add('bar', bar);

tasks([cli]): tasks

  • options {Object} - The cli arguments. (default: minimist(process.argv.slice(2)))

Creates a subset of tasks, useful for providing your own cli arguments, lazy task definition, and creating subtasks.



MIT © Shannon Moeller