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

@ronilaukkarinen/printer-for-errors-of-gulp-plugins

v1.0.1

Published

Parse and print PluginError objects of gulpjs, beautifully.

Downloads

10

Readme

Wulechuan's Printer For Errors of Glup Plugins

NPM Page

@wulechuan/printer-for-errors-of-gulp-plugins

Introduction

This package is renamed from @wulechuan/javascript-gulp-plugin-error-printer, as the old name is not so good.

This is a message logging tool for gulp. It parses gulp's PluginError instance, and is expected to print a more beautiful log for the error instance, as long as a parser is provided for that specific type of PluginError.

Almost all colors in the logs are configurable.

Supported Plugins So Far

Even for those errors that are not supported, a beautified property list is logged.

Usage

An Example

See the examples/gulpfile.js included by this repository as an example.

Below are the key snippet from the said gulpfile.js.

const printGulpPluginErrorBeautifully = require('@wulechuan/printer-for-errors-of-gulp-plugins');

const exampleSourceFileBasePath = '.';

const errorOfGlupPluginsPrintingConfigurations = {

    // This simply helps the logger print shorter paths
    // so that file paths looks better in narrow console windows.
    basePathToShortenPrintedFilePaths: exampleSourceFileBasePath,

    colorTheme: {
        heading: {
            lineColor: 'magenta',
        },
    },
};


function buildCSSStylus (cb) {
    return gulpRead(sourceGlobsOfCSSStylus)
        .pipe(compileStylus())
        .on('error', theError => {
            printGulpPluginErrorBeautifully(theError, errorOfGlupPluginsPrintingConfigurations);
            cb();
        });
}

An Example with gulp-pipe

The tasks in the new gulp (gulp 4), will throw as early as possible. So we have to handle the errors of each and every gulp-plugin like this.

At least that's the approach I know so far.

const printGulpPluginErrorBeautifully = require('@wulechuan/printer-for-errors-of-gulp-plugins');
const gulpPipeFromArray = require('gulp-pipe');



function aGulpTask() {
    const pipeSegments = [ gulp.src(sourceGlobs) ]


    // ---------------------------------------------------------------

    if (shouldEnableStylus) {
        const pipeInstance = stylus()

        // handle the error specific to "stylus".
        pipeInstance.on('error', theError => {
            printGulpPluginErrorBeautifully(theError, {
                basePathToShortenPrintedFilePaths: '../',
            })

            // Don't forget to end this pipe if an error occurs.
            // Otherwise, when used with gulp watcher,
            // the watcher gets hung for ever if this error occurs.
            pipeInstance.end()
        })

        pipeSegments.push(pipeInstance)
    }

    // ---------------------------------------------------------------


    if (shouldEnableAnotherPlugin) {
        const pipeInstance = anotherPlugin()

        // handle the error specific to this "anotherPlugin".
        pipeInstance.on('error', theError => {
            printGulpPluginErrorBeautifully(theError, {
                basePathToShortenPrintedFilePaths: '../',
            })

            // Don't forget to end this pipe if an error occurs.
            // Otherwise, when used with gulp watcher,
            // the watcher gets hung for ever if this error occurs.
            pipeInstance.end()
        })

        pipeSegments.push(pipeInstance)
    }


    pipeSegments.push(gulp.dest('./dist/css/'))



    return gulpPipeFromArray(pipeSegements)
}

Try It out, See It in Action

There is a dummy project included within this repository, so that people can try this logger without difficulty.

The said dummy project locates here:

<this repository root folder>/examples

Before You Try

Before you can start trying, you first need to install all dependencies for this npm project.

This is a one time action, you don't need to do it every time before you run the tryout script.

Open a console/terminal and run:

npm install

or even simpler:

npm i

Run the Tryout Script

Open a console/terminal and run:

npm start

or even simpler:

gulp

That's it.

Some Snapshots of Mine

Below are some snapshots of my console, hosted within Microsoft Visual Studio Code.

By the way, the used color theme of my Visual Studio Code, shown in the illustrates below, is the "Panda Theme".

A Stylus compilation error. A Stylus compilation error

A LESSCSS compilation error. A LESSCSS compilation error

A Sass compilation error. A Sass compilation error

An UglifyJS parsing error. An UglifyJS parsing error

Configurations

Currently only colors are configurable. So you may call it "color theme configurations" if you prefer.

See configurations.md.

Known Issues

When utilizing the on('error') method of a gulp's pipeline, the error will propagate outside the event handler, and will finally get printed the traditional way. Since this logger also prints the error, the error is printed twice.

I'll learn how to swallow the error inside this logger in the future.

API

Sorry. I don't have too much spare time at present. I have my boy to take care of.

Consult my ugly source codes if you'd like to. :p