1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00

Add support for custom task labels

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"
    }
]
```
This commit is contained in:
Chauncey McAskill
2021-12-03 13:22:59 -05:00
parent 47007cddaf
commit 1e7e90c8aa
4 changed files with 42 additions and 32 deletions

View File

@@ -17,11 +17,14 @@ import { basename } from 'node:path';
export default async function concatFiles() {
loconfig.tasks.concats.forEach(async ({
includes,
outfile
outfile,
label = null
}) => {
const filename = basename(outfile || 'undefined');
if (!label) {
label = basename(outfile || 'undefined');
}
const timeLabel = `${filename} concatenated in`;
const timeLabel = `${label} concatenated in`;
console.time(timeLabel);
try {
@@ -33,16 +36,16 @@ export default async function concatFiles() {
await concat(files, outfile);
if (files.length) {
message(`${filename} concatenated`, 'success', timeLabel);
message(`${label} concatenated`, 'success', timeLabel);
} else {
message(`${filename} is empty`, 'notice', timeLabel);
message(`${label} is empty`, 'notice', timeLabel);
}
} catch (err) {
message(`Error concatenating ${filename}`, 'error');
message(`Error concatenating ${label}`, 'error');
message(err);
notification({
title: `${filename} concatenation failed 🚨`,
title: `${label} concatenation failed 🚨`,
message: `${err.name}: ${err.message}`
});
}