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:
@@ -17,11 +17,14 @@ import { basename } from 'node:path';
|
|||||||
export default async function concatFiles() {
|
export default async function concatFiles() {
|
||||||
loconfig.tasks.concats.forEach(async ({
|
loconfig.tasks.concats.forEach(async ({
|
||||||
includes,
|
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);
|
console.time(timeLabel);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -33,16 +36,16 @@ export default async function concatFiles() {
|
|||||||
await concat(files, outfile);
|
await concat(files, outfile);
|
||||||
|
|
||||||
if (files.length) {
|
if (files.length) {
|
||||||
message(`${filename} concatenated`, 'success', timeLabel);
|
message(`${label} concatenated`, 'success', timeLabel);
|
||||||
} else {
|
} else {
|
||||||
message(`${filename} is empty`, 'notice', timeLabel);
|
message(`${label} is empty`, 'notice', timeLabel);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message(`Error concatenating ${filename}`, 'error');
|
message(`Error concatenating ${label}`, 'error');
|
||||||
message(err);
|
message(err);
|
||||||
|
|
||||||
notification({
|
notification({
|
||||||
title: `${filename} concatenation failed 🚨`,
|
title: `${label} concatenation failed 🚨`,
|
||||||
message: `${err.name}: ${err.message}`
|
message: `${err.name}: ${err.message}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,14 @@ export default async function compileScripts(esBuildOptions = null) {
|
|||||||
loconfig.tasks.scripts.forEach(async ({
|
loconfig.tasks.scripts.forEach(async ({
|
||||||
includes,
|
includes,
|
||||||
outdir = '',
|
outdir = '',
|
||||||
outfile = ''
|
outfile = '',
|
||||||
|
label = null
|
||||||
}) => {
|
}) => {
|
||||||
const filename = basename(outdir || outfile || 'undefined');
|
if (!label) {
|
||||||
|
label = basename(outdir || outfile || 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
const timeLabel = `${filename} compiled in`;
|
const timeLabel = `${label} compiled in`;
|
||||||
console.time(timeLabel);
|
console.time(timeLabel);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -82,11 +85,11 @@ export default async function compileScripts(esBuildOptions = null) {
|
|||||||
outfile,
|
outfile,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
message(`${filename} compiled`, 'success', timeLabel);
|
message(`${label} compiled`, 'success', timeLabel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// errors managments (already done in esbuild)
|
// errors managments (already done in esbuild)
|
||||||
notification({
|
notification({
|
||||||
title: `${filename} compilation failed 🚨`,
|
title: `${label} compilation failed 🚨`,
|
||||||
message: `${err.errors[0].text} in ${err.errors[0].location.file} line ${err.errors[0].location.line}`
|
message: `${err.errors[0].text} in ${err.errors[0].location.file} line ${err.errors[0].location.line}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,11 +97,12 @@ export default async function compileStyles(sassOptions = null, postcssOptions =
|
|||||||
|
|
||||||
loconfig.tasks.styles.forEach(async ({
|
loconfig.tasks.styles.forEach(async ({
|
||||||
infile,
|
infile,
|
||||||
outfile
|
outfile,
|
||||||
|
label = null
|
||||||
}) => {
|
}) => {
|
||||||
const name = basename((outfile || 'undefined'), '.css');
|
const filestem = basename((outfile || 'undefined'), '.css');
|
||||||
|
|
||||||
const timeLabel = `${name}.css compiled in`;
|
const timeLabel = `${label || `${filestem}.css`} compiled in`;
|
||||||
console.time(timeLabel);
|
console.time(timeLabel);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -132,7 +133,7 @@ export default async function compileStyles(sassOptions = null, postcssOptions =
|
|||||||
if (result.warnings) {
|
if (result.warnings) {
|
||||||
const warnings = result.warnings();
|
const warnings = result.warnings();
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
message(`Error processing ${name}.css`, 'warning');
|
message(`Error processing ${label || `${filestem}.css`}`, 'warning');
|
||||||
warnings.forEach((warn) => {
|
warnings.forEach((warn) => {
|
||||||
message(warn.toString());
|
message(warn.toString());
|
||||||
});
|
});
|
||||||
@@ -144,17 +145,17 @@ export default async function compileStyles(sassOptions = null, postcssOptions =
|
|||||||
await writeFile(outfile, result.css);
|
await writeFile(outfile, result.css);
|
||||||
|
|
||||||
if (result.css) {
|
if (result.css) {
|
||||||
message(`${name}.css compiled`, 'success', timeLabel);
|
message(`${label || `${filestem}.css`} compiled`, 'success', timeLabel);
|
||||||
} else {
|
} else {
|
||||||
message(`${name}.css is empty`, 'notice', timeLabel);
|
message(`${label || `${filestem}.css`} is empty`, 'notice', timeLabel);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message(`Error compiling ${name}.css`, 'error');
|
message(`Error compiling ${label || `${filestem}.css`}`, 'error');
|
||||||
message(err);
|
message(err);
|
||||||
|
|
||||||
notification({
|
notification({
|
||||||
title: `${name}.css save failed 🚨`,
|
title: `${label || `${filestem}.css`} save failed 🚨`,
|
||||||
message: `Could not save stylesheet to ${name}.css`
|
message: `Could not save stylesheet to ${label || `${filestem}.css`}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,21 +163,21 @@ export default async function compileStyles(sassOptions = null, postcssOptions =
|
|||||||
try {
|
try {
|
||||||
await writeFile(outfile + '.map', result.map.toString());
|
await writeFile(outfile + '.map', result.map.toString());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message(`Error compiling ${name}.css.map`, 'error');
|
message(`Error compiling ${label || `${filestem}.css.map`}`, 'error');
|
||||||
message(err);
|
message(err);
|
||||||
|
|
||||||
notification({
|
notification({
|
||||||
title: `${name}.css.map save failed 🚨`,
|
title: `${label || `${filestem}.css.map`} save failed 🚨`,
|
||||||
message: `Could not save sourcemap to ${name}.css.map`
|
message: `Could not save sourcemap to ${label || `${filestem}.css.map`}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message(`Error compiling ${name}.scss`, 'error');
|
message(`Error compiling ${label || `${filestem}.scss`}`, 'error');
|
||||||
message(err.formatted || err);
|
message(err.formatted || err);
|
||||||
|
|
||||||
notification({
|
notification({
|
||||||
title: `${name}.scss compilation failed 🚨`,
|
title: `${label || `${filestem}.scss`} compilation failed 🚨`,
|
||||||
message: (err.formatted || `${err.name}: ${err.message}`)
|
message: (err.formatted || `${err.name}: ${err.message}`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,14 @@ export default async function compileSVGs(mixerOptions = null) {
|
|||||||
|
|
||||||
loconfig.tasks.svgs.forEach(async ({
|
loconfig.tasks.svgs.forEach(async ({
|
||||||
includes,
|
includes,
|
||||||
outfile
|
outfile,
|
||||||
|
label = null
|
||||||
}) => {
|
}) => {
|
||||||
const filename = basename(outfile || 'undefined');
|
if (!label) {
|
||||||
|
label = basename(outfile || 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
const timeLabel = `${filename} compiled in`;
|
const timeLabel = `${label} compiled in`;
|
||||||
console.time(timeLabel);
|
console.time(timeLabel);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -64,13 +67,13 @@ export default async function compileSVGs(mixerOptions = null) {
|
|||||||
|
|
||||||
await result.write(outfile);
|
await result.write(outfile);
|
||||||
|
|
||||||
message(`${filename} compiled`, 'success', timeLabel);
|
message(`${label} compiled`, 'success', timeLabel);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message(`Error compiling ${filename}`, 'error');
|
message(`Error compiling ${label}`, 'error');
|
||||||
message(err);
|
message(err);
|
||||||
|
|
||||||
notification({
|
notification({
|
||||||
title: `${filename} compilation failed 🚨`,
|
title: `${label} compilation failed 🚨`,
|
||||||
message: `${err.name}: ${err.message}`
|
message: `${err.name}: ${err.message}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user