Skip to content

Commit

Permalink
feat: validating cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSS committed Jun 30, 2022
1 parent c39c7e8 commit 40a918b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/conductor/get-group-order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defaultConfig } from '../defaultConfig';
import { Config } from '../types';

export function getGroupOrder(config: Partial<Config>) {
const groups = new Set(config?.groupOrder || []);
const uniqueGroups = Array.from(groups);
return !isValidGroupArgument(uniqueGroups) ? defaultConfig.groupOrder : uniqueGroups;
}

function isValidGroupArgument(groups: string[]): boolean {
return groups.length === defaultConfig.groupOrder.length && groups.every((group) => defaultConfig.groupOrder.includes(group));
}
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sync } from 'glob';

import { getGroupOrder } from './conductor/get-group-order';
import { getThirdParty } from './conductor/get-third-party';
import { defaultConfig } from './defaultConfig';
import { CliConfig, Config } from './types';
Expand All @@ -17,6 +18,7 @@ export function resolveConfig(cliConfig: Partial<CliConfig>): Config {
...defaultConfig,
...normalized,
thirdPartyDependencies: getThirdParty(),
groupOrder: getGroupOrder(normalized),
};
if (merged.ignore.length > 0) {
merged.ignore = merged.ignore.map((pattern) => (pattern.includes('*') ? sync(pattern) : pattern)).flat();
Expand Down

0 comments on commit 40a918b

Please sign in to comment.