From 61eb8525a6ef65b5244c3b761441f6629ca0e144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Thu, 16 May 2024 11:26:00 +0200 Subject: [PATCH] #1324: fix buildDefinition for types with their own subfolder per item --- lib/metadataTypes/Asset.js | 3 +++ lib/metadataTypes/MetadataType.js | 7 ++++--- lib/metadataTypes/Query.js | 13 +------------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/metadataTypes/Asset.js b/lib/metadataTypes/Asset.js index cc599a110..8464b6a1d 100644 --- a/lib/metadataTypes/Asset.js +++ b/lib/metadataTypes/Asset.js @@ -922,6 +922,9 @@ class Asset extends MetadataType { }: ${extractedFile.fileName}.${extractedFile.fileExt}.` ); } + extractedFile.subFolder = extractedFile.subFolder + .map((el) => (el === templateName ? metadata[this.definition.keyField] : el)) + .map((el) => this.applyTemplateValues(el, templateVariables)); } // #2 binary extracts diff --git a/lib/metadataTypes/MetadataType.js b/lib/metadataTypes/MetadataType.js index ea0584364..c7e41916e 100644 --- a/lib/metadataTypes/MetadataType.js +++ b/lib/metadataTypes/MetadataType.js @@ -1974,8 +1974,10 @@ class MetadataType { let metadata; try { // update all initial variables & create metadata object - metadata = JSON.parse(Mustache.render(metadataStr, variables, {}, ['{{{', '}}}'])); - typeDirArr = typeDirArr.map((el) => Mustache.render(el, variables, {}, ['{{{', '}}}'])); + metadata = JSON.parse(this.applyTemplateValues(metadataStr, variables)); + typeDirArr = typeDirArr + .map((el) => (el === templateName ? metadata[this.definition.keyField] : el)) + .map((el) => this.applyTemplateValues(el, variables)); } catch { throw new Error( `${this.definition.type}:: Error applying template variables on ${ @@ -1998,7 +2000,6 @@ class MetadataType { try { // write to file const targetDirArr = Array.isArray(targetDir) ? targetDir : [targetDir]; - for (const targetDir of targetDirArr) { await File.writeJSONToFile( [targetDir, ...typeDirArr], diff --git a/lib/metadataTypes/Query.js b/lib/metadataTypes/Query.js index 801c28e29..c88d2224c 100644 --- a/lib/metadataTypes/Query.js +++ b/lib/metadataTypes/Query.js @@ -4,7 +4,6 @@ import { Util } from '../util/util.js'; import MetadataType from './MetadataType.js'; import File from '../util/file.js'; import cache from '../util/cache.js'; -import Mustache from 'mustache'; /** * @typedef {import('../../types/mcdev.d.js').BuObject} BuObject @@ -24,16 +23,6 @@ import Mustache from 'mustache'; * @typedef {import('../../types/mcdev.d.js').QueryMap} QueryMap */ -/** - * ensure that Mustache does not escape any characters - * - * @param {string} text - - * @returns {string} text - */ -Mustache.escape = function (text) { - return text; -}; - /** * Query MetadataType * @@ -292,7 +281,7 @@ class Query extends MetadataType { .join('}}}'); // replace template variables with their values - return Mustache.render(code, templateVariables, {}, ['{{{', '}}}']); + return super.applyTemplateValues(code, templateVariables); } /** * helper for {@link MetadataType.buildDefinition}