Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Run a set of similar npm scripts with a wildcard

    Elijah ManorElijah Manor

    In this lesson we will run a set of scripts that are grouped together with a wildcard using the npm-run-all node package. Using this technique can help you simplify and organize your scripts.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: Npm-run-all has a grouping feature that can be handy when you have scripts with a similar theme, like linting, for example. Let's rename the eslint script to lint:js. We'll also rename the stylelint script to lint:css.

    In our test script, instead of saying "eslint stylelint," we could just say "lint:." The : indicates that it will run any script that matches the pattern. In this case, it'll match lint:js and lint:css.

    We can save our code and open the terminal. When we run npm test, it'll run all of our linting and then all of our tests.

    Npm-run-all also supports the :** glob that'll match both subscripts and sub-subscripts. We could come down here and make a new script called lint:css:fix.

    We'll run the style-format command, recursively looking through our source directory, fixing any style issues that we might have violated. We can come up to our test script and change it from lint:* to lint:**, which will match lint:js, lint:css, and lint:css:fix.

    If we save our code and come back to the terminal, we'll need to npm install style-format and save it as a dev dependency. When we run our tests, it'll automatically lint both our JavaScript and our CSS and auto-fix both of them.

    One last thing that might be helpful is to create a plain lint script that will run all the linting subscripts. That way, we can easily run the lint script from the terminal.

    Now that we have that script, we can come up to our test script and change our npm-run-all to just lint and mocha. When we come to the terminal, we can just say, "npm run lint," which will kick off the linting for both the JavaScript and the styles and auto-fix both of them.