Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: color empty stores #2312

Merged
merged 3 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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