add support for different recommendation levels: strict and standard
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Script } from '@/domain/Script';
|
||||
import { YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
import { parseDocUrls } from './DocumentationParser';
|
||||
import { RecommendationLevelNames, RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
|
||||
export function parseScript(yamlScript: YamlScript): Script {
|
||||
if (!yamlScript) {
|
||||
@@ -11,6 +12,21 @@ export function parseScript(yamlScript: YamlScript): Script {
|
||||
/* code */ yamlScript.code,
|
||||
/* revertCode */ yamlScript.revertCode,
|
||||
/* docs */ parseDocUrls(yamlScript),
|
||||
/* isRecommended */ yamlScript.recommend);
|
||||
/* level */ getLevel(yamlScript.recommend));
|
||||
return script;
|
||||
}
|
||||
|
||||
function getLevel(level: string): RecommendationLevel | undefined {
|
||||
if (!level) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof level !== 'string') {
|
||||
throw new Error(`level must be a string but it was ${typeof level}`);
|
||||
}
|
||||
const typedLevel = RecommendationLevelNames
|
||||
.find((l) => l.toLowerCase() === level.toLowerCase());
|
||||
if (!typedLevel) {
|
||||
throw new Error(`unknown level: \"${level}\"`);
|
||||
}
|
||||
return RecommendationLevel[typedLevel as keyof typeof RecommendationLevel];
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
2
src/application/application.yaml.d.ts
vendored
2
src/application/application.yaml.d.ts
vendored
@@ -10,7 +10,7 @@ declare module 'js-yaml-loader!*' {
|
||||
name: string;
|
||||
code: string;
|
||||
revertCode: string;
|
||||
recommend: boolean;
|
||||
recommend: string | undefined;
|
||||
}
|
||||
|
||||
export interface YamlCategory extends YamlDocumentable {
|
||||
|
||||
Reference in New Issue
Block a user