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

constomatic

v1.0.1

Published

Injects a random alphanumeric string as a value in a specified set of PHP constants. Designed for use in a watch task as a means of automated cachebusting for a WordPress script/style enqueue.

Downloads

3

Readme

constomatic

Install

$ npm install -D constomatic

constomatic screen capture

Usage

Gulp not required, but recommended.

Create a gulp task. (See options reference below)

/gulpfile.js (Gulp v3 example)

var constomatic = require("constomatic");

gulp.task("bump-css", function() {
  constomatic({
    src: "functions.php",
    dest: "/",
    constNames: ["CSS_VERSION", "JS_VERSION"]
  });
});

/gulpfile.js (Gulp v4 example)

const constomatic = require("constomatic");

const updateStylesVersion = cb => {
  constomatic({
    src: "functions.php",
    dest: "/",
    constNames: ["CSS_VERSION"],
    hashLength: 7
  });
  cb();
};

Create at least one const (define style) definition in your src php file and set any alphanumeric string as the value.

/functions.php

define('CSS_VERSION', 'abc123');
define('JS_VERSION', 'abc123');

Run the task in terminal, or set it as a part of your watch setup.

Add to a watch task (gulp@v3)

gulp.task("default", ["browser-sync"], function() {
  gulp.watch("library/scss/**/*.scss", ["styles", "bump-css"]);
  gulp.watch("*.php", ["bs-reload"]);
});

or gulp@v4

const watchStyles = () => {
  watch("library/scss/**/*.scss", series(compileStyles, updateStylesVersion));
};

Check out your newly hashed values in your php file.

/functions.php

define('CSS_VERSION', 'gbkPNaG');
define('JS_VERSION', 'iO75jf5');

Now you can echo the const values into any corresponding wp_register_style/script statements

Options

src

Type: String
Default: "/build/functions.php"

Path to the source file. Usually set to "functions.php"

dest

Type: String
Default: "/"

Path to the folder where file with the hashed consts will be output.

constName

Type: Array

Accepts an array of php constant names to be hashed

hashLength

Type: Number
Default: 6

Specifies the number of characters to be used in the hashed value provided to each constant


semVer - Experimental Only! This feature is in development

Type: Boolean
Default: false

"Semantic-ish" versioning. Turning this on will increment a 0-9 counter using a format matching define('CONST_NAME', '1.0.0');

LICENSE

MIT