Added support for replacing a string in a file using a regular expression.
The routine uses Node's Readline and Stream modules.
The `outfile` will be renamed with a `~` suffix, then stream each line, writing to a new `outfile`.
On success, the backup file (with `~`) is deleted.
On error, any new file is deleted, then the backup file is renamed without a `~` suffix.
Usage:
```json
"versions": [
{
"format": "timestamp",
"key": "regexp:(?<=\bdefine\('ASSETS_VERSION', )[^\)]+(?=\);)",
"outfile": "src/bootstrap.php"
}
]
```
```php
<?php
define( 'ASSETS_VERSION', 1665071717350 );
```
Added:
- Support for writing multiple times to the same file.
- Support for random hexadecimal value instead of timestamp.
Usage:
```json
"versions": [
{
"format": "timestamp",
"key": "now",
"outfile": "./assets.json"
},
{
"format": "hex:8",
"key": "hex",
"outfile": "./assets.json"
}
]
```
```json
{
"now": 1665071717350,
"hex": "6ef54181c4ba"
}
```
A task to allow one to define zero or more JSON files and keys to create or update with the current timestamp.
By default, the boilerplate will maintain a './assets.json' file which should be imported by the Web framework and applied to compiled assets.
If a 'loconfig.local.json' file is present (ignored by git), its settings will be merged with those in 'loconfig.json'. Useful for customizing localhost development (see example below).
Added:
- Utility 'config.js' to prepare build settings.
- Function 'merge()' for recursively merging objects and concatenating arrays.
Example:
```json
{
"paths": {
"url": "yourlocal.dev"
},
"server": {
"open": true,
"https": {
"key": "~/.config/valet/Certificates/{% paths.url %}.key",
"cert": "~/.config/valet/Certificates/{% paths.url %}.crt"
}
}
}
```
Added:
- Function `resolve()` to process any template tags (in a string) in objects and arrays.
Changed:
- Renamed function `template()` to `resolveValue()`.
- Replaced default export `resolveValue()` with new function `resolve()`.
Added:
- Condition to process includes with glob if it's available.
Changed:
- Utility 'glob.js' to not throw an error if a glob function is unavailable.
Added:
- Argument `concatOptions` to `concatFiles()` function to customize concatenation.
- Option 'removeDuplicates' to `concatOptions` to remove duplicate paths from the array of globbed paths. Defaults to `true`.
The 'removeDuplicates' is useful for customizing the order of files to concatenate, in which globbing will usually sort paths alphabetically.
This option is convenient when the installed glob library does not support removing duplicates on their own (feature supported in 'fast-glob' and 'glob').
Example:
```
/assets/scripts/vendors/a.js
/assets/scripts/vendors/b.js
/assets/scripts/vendors/c.js
/assets/scripts/vendors/d.js
```
```json
"concats": [
{
"includes": [
"{% paths.scripts.src %}/vendors/c.js",
"{% paths.scripts.src %}/vendors/*.js"
],
"outfile": "{% paths.scripts.dest %}/vendors.js"
}
]
```
If ever the basename from the outfile or outdir is an insufficient description.
Example:
```json
"concats": [
{
"label": "third-parties",
"includes": [
"{% paths.scripts.src %}/vendors/*.js"
],
"outfile": "{% paths.scripts.dest %}/vendors.js"
}
]
```
Added routine to convert `paths.views` into an array.
Supports a single path as a string, a map of paths, or a list of paths:
```json
"views": "./views/boilerplate/template"
```
```json
"views": {
"src": "./views/boilerplate/template"
}
```
```json
"views": [
"./views/boilerplate/template"
]
```
Added support for customizing processors in `scripts.js` (esbuild), `styles.js` (node-sass, postcss, autoprefixer), and `svgs.js` (svg-mixer), via arguments for the exported task functions.
Added:
- Constants to decouple shared default options, options for development, and options for production.
- Constants to export default options for development and production as an array of arguments to pass to task functions.
Changed:
- watch.js to apply development args to tasks
Fixed:
- Expected file extension from `outfile` for variable `name`.
- Expected structure of `err` in main catch (`err.formatted` is only available when thrown by node-sass).
- Context of error messages when writing final CSS and source map to disk.
Changed:
- Renamed 'mconfig.json' to 'loconfig.json'.
- Renamed 'concat.js' to 'concats.js' to represent flexible functionality.
- loconfig.json: Base paths are nested under "paths".
- loconfig.json: Paths for tasks are nested under "tasks".
- Refactored each task to process corresponding entries under "tasks" in 'loconfig.json'.
- watch.js: Changed concats watch to use task's includes.
Added:
- tiny-glob v0.2.9
- Utility 'glob.js' to use dynamic imports to fetch an available glob function from node modules.
- Utility 'template.js' to provide a function to render template tags (`{% ... %}`) in tasks.
- concats.js: Support for concatenating groupes of files.
- scripts.js: Support for ESBuild's "outdir" option.
Changed:
- Replaced "fs" callback API with "fs/promises" promise API to centralize catching of errors and easier readability of file.
- Prefixed "fs/promises" with 'node:' URI scheme to target Node.js builtin modules.
- Promisified `sass.render`.
Changed:
- Replaced "fs" callback API with "fs/promises" promise API to centralize catching of errors and easier readability of file.
- Prefixed "fs/promises" with 'node:' URI scheme to target Node.js builtin modules.
Added:
- Types "notice" and "warning".
- Support for all but the "waiting" message type to stop a timer.
Changed:
- Improved colors of message types.
- Improved handling of PostCSS errors in styles.js.