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:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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('');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user