Skip to content

Commit

Permalink
feat: color empty stores (#2312)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
c4dx committed Apr 9, 2021
1 parent c2c8531 commit bbfa808
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -59,7 +59,7 @@
"twilio": "^3.59.0",
"twitch": "^4.5.2",
"twitch-auth": "^4.5.2",
"twitch-chat-client": "^4.5.2",
"twitch-chat-client": "^4.5.4",
"twitter": "^1.7.1",
"winston": "^3.3.3"
},
Expand Down
41 changes: 33 additions & 8 deletions src/store/model/index.ts
Expand Up @@ -146,6 +146,7 @@ import {Wipoid} from './wipoid';
import {Xbox} from './xbox';
import {Zotac} from './zotac';
import {logger} from '../../logger';
import chalk from 'chalk';

export const storeList = new Map([
[AComPC.name, AComPC],
Expand Down Expand Up @@ -323,14 +324,6 @@ function filterBrandsSeriesModels() {
}

function printConfig() {
if (config.store.stores.length > 0) {
logger.info(
`ℹ selected stores: ${config.store.stores
.map(store => store.name)
.join(', ')}`
);
}

if (config.store.showOnlyBrands.length > 0) {
logger.info(`ℹ selected brands: ${config.store.showOnlyBrands.join(', ')}`);
}
Expand All @@ -350,6 +343,38 @@ function printConfig() {
if (config.store.showOnlySeries.length > 0) {
logger.info(`ℹ selected series: ${config.store.showOnlySeries.join(', ')}`);
}

if (config.store.stores.length > 0) {
const stores = darkenEmptyStores();
logger.info(`ℹ selected stores: ${stores.names.join(', ')}`);

if (stores.anyExcluded) {
logger.warn(
'ℹ some of the selected stores (grayed out) dont have what you are looking for'
);
}
}
}

function darkenEmptyStores(): {names: string[]; anyExcluded: boolean} {
let anyExcluded = false;
const selectedStores = config.store.stores.map(store => store.name);

const names = selectedStores.map(selected => {
const storeConfig = storeList.get(selected);
const hasAny =
storeConfig?.links.some(
l =>
(config.store.showOnlySeries?.includes(l.series) ?? false) ||
config.store.showOnlyBrands?.includes(l.brand ?? false) ||
(config.store.showOnlyModels?.map(m => m.name).includes(l.model) ??
false)
) ?? false;

anyExcluded = anyExcluded || !hasAny;
return hasAny ? selected : chalk.gray(selected);
});
return {names, anyExcluded};
}

function warnIfStoreDeprecated(store: Store) {
Expand Down

0 comments on commit bbfa808

Please sign in to comment.