Skip to content

Commit bbfa808

Browse files
authored
feat: color empty stores (#2312)
Grays out stores that have none of the selected brands/series/models. Additionally, if described event occurs, it logs a warning describing that some of the selected stores don't have what the user is looking for.
1 parent c2c8531 commit bbfa808

File tree

3 files changed

+69
-44
lines changed

3 files changed

+69
-44
lines changed

package-lock.json

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"twilio": "^3.59.0",
6060
"twitch": "^4.5.2",
6161
"twitch-auth": "^4.5.2",
62-
"twitch-chat-client": "^4.5.2",
62+
"twitch-chat-client": "^4.5.4",
6363
"twitter": "^1.7.1",
6464
"winston": "^3.3.3"
6565
},

src/store/model/index.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ import {Wipoid} from './wipoid';
146146
import {Xbox} from './xbox';
147147
import {Zotac} from './zotac';
148148
import {logger} from '../../logger';
149+
import chalk from 'chalk';
149150

150151
export const storeList = new Map([
151152
[AComPC.name, AComPC],
@@ -323,14 +324,6 @@ function filterBrandsSeriesModels() {
323324
}
324325

325326
function printConfig() {
326-
if (config.store.stores.length > 0) {
327-
logger.info(
328-
`ℹ selected stores: ${config.store.stores
329-
.map(store => store.name)
330-
.join(', ')}`
331-
);
332-
}
333-
334327
if (config.store.showOnlyBrands.length > 0) {
335328
logger.info(`ℹ selected brands: ${config.store.showOnlyBrands.join(', ')}`);
336329
}
@@ -350,6 +343,38 @@ function printConfig() {
350343
if (config.store.showOnlySeries.length > 0) {
351344
logger.info(`ℹ selected series: ${config.store.showOnlySeries.join(', ')}`);
352345
}
346+
347+
if (config.store.stores.length > 0) {
348+
const stores = darkenEmptyStores();
349+
logger.info(`ℹ selected stores: ${stores.names.join(', ')}`);
350+
351+
if (stores.anyExcluded) {
352+
logger.warn(
353+
'ℹ some of the selected stores (grayed out) dont have what you are looking for'
354+
);
355+
}
356+
}
357+
}
358+
359+
function darkenEmptyStores(): {names: string[]; anyExcluded: boolean} {
360+
let anyExcluded = false;
361+
const selectedStores = config.store.stores.map(store => store.name);
362+
363+
const names = selectedStores.map(selected => {
364+
const storeConfig = storeList.get(selected);
365+
const hasAny =
366+
storeConfig?.links.some(
367+
l =>
368+
(config.store.showOnlySeries?.includes(l.series) ?? false) ||
369+
config.store.showOnlyBrands?.includes(l.brand ?? false) ||
370+
(config.store.showOnlyModels?.map(m => m.name).includes(l.model) ??
371+
false)
372+
) ?? false;
373+
374+
anyExcluded = anyExcluded || !hasAny;
375+
return hasAny ? selected : chalk.gray(selected);
376+
});
377+
return {names, anyExcluded};
353378
}
354379

355380
function warnIfStoreDeprecated(store: Store) {

0 commit comments

Comments
 (0)