- Use function abstractions (such as map, reduce, filter etc.) over for-of loops to gain benefits of having less side effects and easier readability. - Enable `downLevelIterations` for writing modern code with lazy evaluation. - Refactor for of loops to named abstractions to clearly express their intentions without needing to analyse the loop itself. - Add missing cases for changes that had no tests.
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { CollectionData } from 'js-yaml-loader!@/*';
|
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
|
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
|
import { CategoryCollection } from '@/domain/CategoryCollection';
|
|
import { IProjectInformation } from '@/domain/IProjectInformation';
|
|
import { createEnumParser } from '../Common/Enum';
|
|
import { parseCategory } from './CategoryParser';
|
|
import { CategoryCollectionParseContext } from './Script/CategoryCollectionParseContext';
|
|
import { ScriptingDefinitionParser } from './ScriptingDefinition/ScriptingDefinitionParser';
|
|
|
|
export function parseCategoryCollection(
|
|
content: CollectionData,
|
|
info: IProjectInformation,
|
|
osParser = createEnumParser(OperatingSystem),
|
|
): ICategoryCollection {
|
|
validate(content);
|
|
const scripting = new ScriptingDefinitionParser()
|
|
.parse(content.scripting, info);
|
|
const context = new CategoryCollectionParseContext(content.functions, scripting);
|
|
const categories = content.actions.map((action) => parseCategory(action, context));
|
|
const os = osParser.parseEnum(content.os, 'os');
|
|
const collection = new CategoryCollection(
|
|
os,
|
|
categories,
|
|
scripting,
|
|
);
|
|
return collection;
|
|
}
|
|
|
|
function validate(content: CollectionData): void {
|
|
if (!content) {
|
|
throw new Error('content is null or undefined');
|
|
}
|
|
if (!content.actions || content.actions.length <= 0) {
|
|
throw new Error('content does not define any action');
|
|
}
|
|
}
|