From 12dc9bc8f55a8fc515abba7f80c4622e391236fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miles=20St=C3=B6tzner?= Date: Sat, 21 Sep 2024 12:43:18 +0200 Subject: [PATCH] latex header --- .../variable-service-template.yaml | 7 ---- src/controller/utils/rules.ts | 4 ++- src/utils/files.ts | 33 ++++++++++--------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/examples/unfurl-technology---industry/variable-service-template.yaml b/examples/unfurl-technology---industry/variable-service-template.yaml index dc0c156954..3737188465 100644 --- a/examples/unfurl-technology---industry/variable-service-template.yaml +++ b/examples/unfurl-technology---industry/variable-service-template.yaml @@ -136,13 +136,6 @@ topology_template: is_customer: {equal: [{variability_input: env}, CUSTOMER]} is_development: {equal: [{variability_input: env}, DEVELOPMENT]} - # TODO: remove these - options: - #technology_constraint: false - #required_technology_check: false - #required_artifact_constraint: false - #expected_artifact_check: true - inputs: env: type: string diff --git a/src/controller/utils/rules.ts b/src/controller/utils/rules.ts index 498550267a..1acf68185a 100644 --- a/src/controller/utils/rules.ts +++ b/src/controller/utils/rules.ts @@ -7,5 +7,7 @@ export type RuleOptions = { export default async function (options: RuleOptions) { options.format = options.format ?? 'yaml' - return files.toFormat(Registry.rules, options.format) + return files.toFormat(Registry.rules, options.format, { + latex: {headers: ['component', 'artifact', 'hosting', 'technology', 'weight']}, + }) } diff --git a/src/utils/files.ts b/src/utils/files.ts index 46e571847d..682b174179 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -163,35 +163,36 @@ export async function loadXML(file: string) { return (await xml2js.parseStringPromise(loadFile(file) /*, options */)) as T } -export function toFormat(obj: any, format: string) { +export function toFormat(obj: any, format: string, options: {latex?: LatexOptions} = {}) { if (format === 'yaml') return toYAML(obj) if (format === 'json') return toJSON(obj) if (format === 'ini') return toINI(obj) if (format === 'env') return toENV(obj) if (format === 'xml') return toXML(obj) - if (format === 'latex') return toLatex(obj) + if (format === 'latex') return toLatex(obj, options.latex) throw new Error(`Format "${format}" not supported`) } -export function toLatex(obj: any) { +export type LatexOptions = { + headers?: string[] +} + +export function toLatex(obj: any, options: LatexOptions = {}) { assert.isArray(obj) // TODO: this is dirty const list = obj as {[key: string]: any}[] - /** - * Collect all possible keys - const keys = new Set() - list.forEach(item => { - Object.keys(item).forEach(key => keys.add(key)) - }) - - // TODO: remove this - keys.delete('details') - keys.delete('reason') - */ + // Collect all possible keys + const defaultKeys = () => { + const dk: string[] = [] + list.forEach(item => { + Object.keys(item).forEach(key => keys.push(key)) + }) + return dk + } - const keys = ['component', 'artifact', 'hosting', 'technology', 'weight'] + const keys = options.headers ?? defaultKeys() const data = [] @@ -210,7 +211,7 @@ export function toLatex(obj: any) { for (const key of keys) { const raw = item[key] // TODO: not latex safe - const string = JSON.stringify(raw) + const value = JSON.stringify(raw) tmp.push(raw) } data.push(tmp.join(' & ') + '\\\\')