Skip to content

Commit

Permalink
Merge pull request #752 from Accenture/bugfix/748-asset-template-can-…
Browse files Browse the repository at this point in the history
…have-code-in-fields-that-are-not-extracted-yet

Bugfix/748 asset template can have code in fields that are not extracted yet
  • Loading branch information
JoernBerkefeld authored Feb 17, 2023
2 parents 5951876 + 43edec6 commit 7513f98
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 18 deletions.
1 change: 1 addition & 0 deletions boilerplate/files/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"*-meta.ssjs": "${capture}-meta.json",
"*.asset-asset-meta.html": "${dirname}.asset-asset-meta.json",
"*.asset-message-meta.html": "${dirname}.asset-message-meta.json",
"*.asset-template-meta.html": "${dirname}.asset-template-meta.json",
"*.css": "${capture}.asset-code-meta.json",
"*.docx": "${capture}.asset-document-meta.json",
"*.eps": "${capture}.asset-image-meta.json",
Expand Down
4 changes: 4 additions & 0 deletions boilerplate/forcedUpdates.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"version": "4.3.4",
"files": [".vscode/settings.json"]
},
{
"version": "4.1.12",
"files": [".vscode/settings.json"]
Expand Down
112 changes: 94 additions & 18 deletions lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,16 +818,17 @@ class Asset extends MetadataType {

// metadata.views.html.content (mandatory)
// the main content can be empty (=not set up yet) hence check if we did extract sth or else readFile() will print error msgs
const fileName = 'views.html.content' + subtypeExtension;
if (
(await File.pathExists(
File.normalizePath([...readDirArr, `index${subtypeExtension}.html`])
File.normalizePath([...readDirArr, `${fileName}.html`])
)) &&
metadata.views.html
) {
if (!fileListOnly) {
metadata.views.html.content = await File.readFilteredFilename(
readDirArr,
'index' + subtypeExtension,
fileName,
'html'
);
}
Expand All @@ -836,7 +837,7 @@ class Asset extends MetadataType {
// to use this method in templating, store a copy of the info in fileList
fileList.push({
subFolder: [...subDirArr, customerKey],
fileName: 'index' + subtypeExtension,
fileName: fileName,
fileExt: 'html',
content: metadata.views.html.content,
});
Expand All @@ -859,6 +860,59 @@ class Asset extends MetadataType {
}
break;
}
case 'template': {
// template-template
// this complex type always creates its own subdir per asset
subDirArr = [this.definition.type, subType];
readDirArr = [deployDir, ...subDirArr, templateName || customerKey];
const fileName = 'content' + subtypeExtension;

const fileExtArr = ['html']; // eslint-disable-line no-case-declarations
for (const ext of fileExtArr) {
if (
await File.pathExists(
File.normalizePath([...readDirArr, `${fileName}.${ext}`])
)
) {
// the main content can be empty (=not set up yet) hence check if we did extract sth or else readFile() will print error msgs
if (!fileListOnly) {
metadata.content = await File.readFilteredFilename(
readDirArr,
fileName,
ext
);
}
if (templateName) {
// to use this method in templating, store a copy of the info in fileList
fileList.push({
subFolder: subDirArr,
fileName: fileName,
fileExt: ext,
content: metadata.content,
});
}
// break loop when found
break;
}
}

// metadata.slots.<>.blocks.<>.content (optional)
if (metadata?.slots) {
await this._mergeCode_slots(
'slots',
metadata.slots,
readDirArr,
subtypeExtension,
subDirArr,
fileList,
customerKey,
templateName,
fileListOnly
);
}

break;
}
case 'textonlyemail': {
// message
// metadata.views.text.content
Expand Down Expand Up @@ -970,7 +1024,6 @@ class Asset extends MetadataType {

break;
}
case 'template': // template-template
case 'buttonblock': // block - Button Block
case 'freeformblock': // block
case 'htmlblock': // block
Expand Down Expand Up @@ -1117,14 +1170,14 @@ class Asset extends MetadataType {
// unfortunately, asset's key can contain spaces at beginning/end which can break the file system when folders are created with it
const customerKey = metadata.customerKey.trim();
switch (metadata.assetType.name) {
case 'templatebasedemail': // message
case 'templatebasedemail': // message-templatebasedemail
case 'htmlemail': {
// message
// message-htmlemail
// metadata.views.html.content (mandatory)
if (metadata.views?.html?.content?.length) {
codeArr.push({
subFolder: null,
fileName: 'index',
fileName: 'views.html.content',
fileExt: 'html',
content: metadata.views.html.content,
});
Expand All @@ -1142,8 +1195,32 @@ class Asset extends MetadataType {
subFolder: [customerKey],
};
}
case 'template': {
// template-template
// metadata.content
const fileExt = 'html'; // eslint-disable-line no-case-declarations
if (metadata?.content?.length) {
codeArr.push({
subFolder: null,
fileName: 'content',
fileExt: fileExt,
content: metadata.content,
});
delete metadata.content;
}
// metadata.slots.<>.blocks.<>.content (optional)
if (metadata.slots) {
this._extractCode_slots('slots', metadata.slots, codeArr);
}

return {
json: metadata,
codeArr: codeArr,
subFolder: [customerKey],
};
}
case 'textonlyemail': {
// message
// message-textonlyemail
// metadata.views.text.content
if (metadata.views?.text?.content?.length) {
codeArr.push({
Expand All @@ -1157,7 +1234,7 @@ class Asset extends MetadataType {
return { json: metadata, codeArr: codeArr, subFolder: null };
}
case 'webpage': {
// asset
// asset-webpage
// metadata.views.html.content (pre & post 20222)
if (metadata.views?.html?.content?.length) {
codeArr.push({
Expand Down Expand Up @@ -1192,16 +1269,15 @@ class Asset extends MetadataType {
subFolder: [customerKey],
};
}
case 'template': // template-template
case 'buttonblock': // block - Button Block
case 'freeformblock': // block
case 'htmlblock': // block
case 'icemailformblock': // block - Interactive Content Email Form
case 'imageblock': // block - Image Block
case 'textblock': // block
case 'smartcaptureblock': // other
case 'buttonblock': // block-buttonblock
case 'freeformblock': // block-freeformblock
case 'htmlblock': // block-htmlblock
case 'icemailformblock': // block-icemailformblock - Interactive Content Email Form
case 'imageblock': // block-imageblock - Image Block
case 'textblock': // block-textblock
case 'smartcaptureblock': // other-smartcaptureblock
case 'codesnippetblock': {
// other
// other-codesnippetblock
// metadata.content
let fileExt = 'html'; // eslint-disable-line no-case-declarations
if (
Expand Down

0 comments on commit 7513f98

Please sign in to comment.