# constomatic

> 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.

Latest version **1.0.1** (published 2019-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install constomatic
pnpm add constomatic
yarn add constomatic
bun add constomatic
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-01-16 |
| First published | 2019-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=9.10.1 |
| Dependencies | 2 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Scott Alguire |
| Maintainers | scottalguire |
| Keywords | gulp, const, php, constant, wordpress, node |

## Links

- npm: https://www.npmjs.com/package/constomatic
- Repository: https://github.com/scottalguire/constomatic
- Issues: https://github.com/scottalguire/constomatic/issues
- npm.io page: https://npm.io/package/constomatic

## Dependencies (2)

- [colors](https://npm.io/package/colors.md) ^1.3.3
- [check-types](https://npm.io/package/check-types.md) ^7.4.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-01-16
- 1.0.0 — 2019-01-16

## README

# constomatic

## Install

`$ npm install -D constomatic`

![constomatic screen capture](screencap.gif)

## Usage

Gulp not required, but recommended.

Create a gulp task. [_(See options reference below)_](#options)

**/gulpfile.js** _(Gulp v3 example)_

```javascript
var constomatic = require("constomatic");

gulp.task("bump-css", function() {
  constomatic({
    src: "functions.php",
    dest: "/",
    constNames: ["CSS_VERSION", "JS_VERSION"]
  });
});
```

**/gulpfile.js** _(Gulp v4 example)_

```javascript
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**

```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)**

```javascript
gulp.task("default", ["browser-sync"], function() {
  gulp.watch("library/scss/**/*.scss", ["styles", "bump-css"]);
  gulp.watch("*.php", ["bs-reload"]);
});
```

**or gulp@v4**

```javascript
const watchStyles = () => {
  watch("library/scss/**/*.scss", series(compileStyles, updateStylesVersion));
};
```

Check out your newly hashed values in your php file.

**/functions.php**

```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

---
_Source: https://npm.io/package/constomatic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
