Skip to content

Commit fecb42d

Browse files
committed
fix: digitalExperiences create files to right folders @W-20967044@
1 parent 630463b commit fecb42d

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/convert/transformers/defaultMetadataTransformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ const getContentSourceDestination = (
9292
if (
9393
source.endsWith('content.json') ||
9494
source.endsWith('_meta.json') ||
95-
!(fs.existsSync(dir) && fs.statSync(dir).isDirectory())
95+
(!(fs.existsSync(dir) && fs.statSync(dir).isDirectory()) &&
96+
!source.endsWith('mobile.json') &&
97+
!source.endsWith('tablet.json'))
9698
) {
9799
return join(mergeWith.content, basename(source));
98100
} else {

test/convert/transformers/defaultMetadataTransformer.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { basename, join } from 'node:path';
1717
import { createSandbox } from 'sinon';
1818
import { assert, expect } from 'chai';
19-
import { bundle, document, matchingContentFile, nestedTypes, xmlInFolder } from '../../mock';
19+
import { bundle, digitalExperienceBundle, document, matchingContentFile, nestedTypes, xmlInFolder } from '../../mock';
2020
import { DefaultMetadataTransformer } from '../../../src/convert/transformers/defaultMetadataTransformer';
2121
import { registry, RegistryAccess, SourceComponent, VirtualTreeContainer, WriteInfo } from '../../../src';
2222
import { TestReadable } from '../../mock/convert/readables';
@@ -296,8 +296,25 @@ describe('DefaultMetadataTransformer', () => {
296296
expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos);
297297
});
298298

299+
it.only('should merge mobile.json into mobile/mobile.json', async () => {
300+
const component = SourceComponent.createVirtualComponent(digitalExperienceBundle.DE_COMPONENT_PROPERTIES, [
301+
{
302+
dirPath: digitalExperienceBundle.HOME_VIEW_PATH,
303+
children: [digitalExperienceBundle.HOME_VIEW_MOBILE_VARIANT_FILE],
304+
},
305+
]);
306+
const mergeWith = digitalExperienceBundle.DE_COMPONENT;
307+
308+
assert(typeof mergeWith.content === 'string');
309+
const transformed = await transformer.toSourceFormat({ component, mergeWith });
310+
const expected = {
311+
source: component.tree.stream(join(digitalExperienceBundle.DE_COMPONENT_PROPERTIES.content, 'mobile.json')),
312+
output: join(mergeWith.content, 'home', 'mobile.json'),
313+
};
314+
expect(transformed).to.deep.include(expected);
315+
});
316+
299317
it('should merge output with merge component when content is a directory', async () => {
300-
assert(typeof bundle.COMPONENT.name === 'string');
301318
const root = join('path', 'to', 'another', bundle.COMPONENT.type.directoryName, bundle.COMPONENT.name);
302319
const component = SourceComponent.createVirtualComponent(
303320
{

test/mock/type-constants/digitalExperienceBundleConstants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const BUNDLE_META_FILE = `foo.${DEB_TYPE.suffix}${META_XML_SUFFIX}`;
3535
export const HOME_VIEW_META_FILE = DE_METAFILE;
3636
export const HOME_VIEW_CONTENT_FILE = 'content.json';
3737
export const HOME_VIEW_FRENCH_VARIANT_FILE = 'fr.json';
38+
export const HOME_VIEW_MOBILE_VARIANT_FILE = 'mobile.json';
3839

3940
export const BASE_PATH = join('path', 'to', DEB_TYPE.directoryName);
4041
export const BUNDLE_PATH = join(BASE_PATH, 'site', 'foo');
@@ -74,3 +75,12 @@ export const DE_COMPONENT = SourceComponent.createVirtualComponent(
7475
},
7576
]
7677
);
78+
79+
export const DE_COMPONENT_PROPERTIES = {
80+
name: HOME_VIEW_NAME,
81+
type: DE_TYPE,
82+
content: HOME_VIEW_PATH,
83+
xml: HOME_VIEW_META_FILE_PATH,
84+
parent: DEB_COMPONENT,
85+
parentType: DEB_TYPE,
86+
};

0 commit comments

Comments
 (0)