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

mtz-ui-scripts

v1.0.6

Published

automated script to drop in test and lint config

Downloads

4

Readme

mtz-ui-scripts

We've got ~50 repos we need to get testing and configuration set up inside, both short-term, and longer-term when we update or need to include security patches. So rather than do error-prone copy & pasting, we can automate most of the process to automatically pull in templates from a centralized source.

Later, I'd like to be able to automate this and generate pull requests with passing tests for us (ex: when we update from polymer 1 to polymer 2).

Generating a test

To use this package to generate a test:

// anywhere
npm i -g mtz-ui-scripts

// to add a new test
mtz-ui-scripts-add-test tag-name

This will create a file in: ./test/${tagName}_test.html prepopulated with some basic test logic.

Installing Test/Linting Config

To use this package:

// anywhere
npm i -g mtz-ui-scripts

// in the root directory of a component with a bower.json file, run
mtz-ui-scripts-install

// after
npm i

This will:

  • copy over a centralized .gitignore
  • copy over .eslintrc configuration
  • copy over polymer.json linting config
  • copy over wct.config.js
  • generate a new package from the existing bower.json file

Make sure to run npm install!

Git Hooks

Git hooks are commands that are executed when a certain git action happens. Git hooks live in .git/hooks. Check it out - each file is named something like pre-push or pre-commit, and contains a list of commands git should execute when that thing happens.

So, for example, we want to run our linters before we can complete a commit. So in pre-commit, we're going to want to run our eslint and polymer lint commands. The convention around commands like this are, if you run a command and it returns a 0, it was successful. If it returns anything other than 0, (usually 1), it failed.

So we add a set of commands inside the pre-commit git hook file that can look at that output and decide what to do. In plain english, "run the linters. if either of them aren't successful, cancel this commit."

Rather than manage all the git hooks manually (you can't put the .git directory itself inside version control), we rely on an npm package named husky to do so. Inside your package.json, you can have it automatically generate your git hooks for you in a much more readable/configurable fashion.

So in a package.json, you'll have some configuration that look like this:

  "husky": {
    "hooks": {
      "pre-commit": "npm lint && npm test"
    }
  },

These commands, npm lint, and npm test, are referring to some commands we set up elsewhere inside package.json as 'npm scripts'. It's good to have these things be scripts instead of just putting all the commands inside of husky so we can use the same command manually from our terminal if we wanted.

Those scripts, specifically, look like:

  "scripts": {
    "lint": "polymer lint && eslint *.html",
    "test": "wct"
  },

So this is just all a way of having the computer automatically run stuff for you instead of you having to do it.

TODO

This whole package is largely untested, so I'd like to manually run it across some environments and add in more safety features (ex: intelligent package.json generation instead of just overwriting).

Other known enhancements needed down the line:

  • Make sure local pre-commit only tests on headless firefox and chrome
  • CI integration
  • CI integration partner configuration (either crossbrowsertesting or sauce labs)