Improve message.js

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.
This commit is contained in:
Chauncey McAskill
2021-09-16 16:51:21 -04:00
parent 454ae64d07
commit ffece71aac
2 changed files with 34 additions and 11 deletions

View File

@@ -48,10 +48,13 @@ export async function compileStyles() {
sourcesContent: true
}
}).then((result) => {
result.warnings().forEach((warn) => {
message(`Error prefixing ${name}.css`, 'error');
message(warn.toString());
});
const warnings = result.warnings();
if (warnings.length) {
message(`Error processing ${name}.css`, 'warning');
warnings.forEach((warn) => {
message(warn.toString());
});
}
saveStylesheet(result, outfile, name, timeLabel);
});

View File

@@ -1,24 +1,40 @@
/**
* @file Provides a decorator for console messages.
*/
import kleur from 'kleur';
/**
* Outputs a message to the console.
*
* @param {string} text - The message to output.
* @param {string} [type] - The type of message.
* @param {string} [timerID] - The console time label to output.
*/
export default function message(text, type, timerID) {
switch (type) {
case 'success':
console.log(kleur.bgGreen().black(`${text}`));
console.log('✅ ', kleur.bgGreen().black(text));
break;
if (timerID !== undefined) {
console.timeEnd(timerID);
}
case 'notice':
console.log(' ', kleur.bgBlue().black(text));
break;
case 'error':
console.log(kleur.red().underline(`${text}`));
console.log('❌ ', kleur.bgRed().black(text));
break;
case 'warning':
console.log('⚠️ ', kleur.bgYellow().black(text));
break;
case 'waiting':
console.log(kleur.blue().italic(`${text}`));
console.log('⏱ ', kleur.blue().italic(text));
if (timerID !== undefined) {
if (timerID != null) {
console.timeLog(timerID);
timerID = null;
}
break;
@@ -27,5 +43,9 @@ export default function message(text, type, timerID) {
break;
}
if (timerID != null) {
console.timeEnd(timerID);
}
console.log('');
};