Skip to content

Commit

Permalink
fix: get correct file paths for a DigitalExperience component (#925)
Browse files Browse the repository at this point in the history
* fix: assign json metafile path to xml property for digitalexperience

* docs: deprecate metaFilePath function on Source Component
  • Loading branch information
skesanthosh authored Apr 5, 2023
1 parent a778992 commit 6ba8b87
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
}
const output = new Set<string>();
componentMap.forEach((component) => {
[...component.walkContent(), component.content, component.metaFilePath]
[...component.walkContent(), component.content, component.xml]
.filter(Boolean)
.map((filename) => output.add(filename));
});
Expand Down
3 changes: 2 additions & 1 deletion src/resolve/adapters/digitalExperienceSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
if (this.isBundleType()) {
return this.getBundleMetadataXmlPath(trigger);
}
// metaFileName = metaFileSuffix for DigitalExperience.
// metafile name = metaFileSuffix for DigitalExperience.
return join(dirname(trigger), this.type.metaFileSuffix);
}

Expand Down Expand Up @@ -82,6 +82,7 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
name: calculateNameFromPath(source.content),
type: this.type,
content: source.content,
xml: source.xml,
parent,
parentType,
},
Expand Down
1 change: 1 addition & 0 deletions src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class SourceComponent implements MetadataComponent {
* Gets the metafile path of this component. Not all the types have an XML metafile,
* e.g., DigitalExperience has a JSON metafile (_meta.json).
*
* @deprecated This function should not be used, use "xml" property instead.
* @returns The metafile path
*/
public get metaFilePath(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/filePathGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const filePathsFromMetadataComponent = (
if (type.strategies?.adapter === 'digitalExperience') {
// child MD Type, the metafile is a JSON, not an XML
if (type.id === 'digitalexperience') {
// metaFileName = metaFileSuffix for DigitalExperience.
// metafile name = metaFileSuffix for DigitalExperience.
return [
join(
packageDirWithTypeDir,
Expand Down
6 changes: 2 additions & 4 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1263,17 +1263,15 @@ describe('ComponentSet', () => {
});

it('should correctly return DE (DigitalExperience) component file paths', () => {
const set = new ComponentSet(
[digitalExperienceBundle.DE_CONTENT_COMPONENT, digitalExperienceBundle.DE_FR_VARIENT_COMPONENT],
registryAccess
);
const set = new ComponentSet([digitalExperienceBundle.DE_COMPONENT], registryAccess);

const de: MetadataMember = {
fullName: digitalExperienceBundle.HOME_VIEW_FULL_NAME,
type: digitalExperienceBundle.DE_TYPE.id,
};

expect(set.getComponentFilenamesByNameAndType(de)).to.have.members([
digitalExperienceBundle.HOME_VIEW_PATH,
join(digitalExperienceBundle.HOME_VIEW_PATH, 'content.json'),
join(digitalExperienceBundle.HOME_VIEW_PATH, 'fr.json'),
join(digitalExperienceBundle.HOME_VIEW_PATH, '_meta.json'),
Expand Down
29 changes: 6 additions & 23 deletions test/mock/type-constants/digitalExperienceBundleConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { META_XML_SUFFIX } from '../../../src/common';
export const DEB_TYPE = registry.types.digitalexperiencebundle;
export const DE_TYPE = DEB_TYPE.children.types.digitalexperience;

// metaFileName = metaFileSuffix for DigitalExperience.
// metafile name = metaFileSuffix for DigitalExperience.
export const DE_METAFILE = DE_TYPE.metaFileSuffix;

export const BUNDLE_NAME = 'site/foo';
Expand All @@ -28,8 +28,7 @@ export const BASE_PATH = join('path', 'to', DEB_TYPE.directoryName);
export const BUNDLE_PATH = join(BASE_PATH, 'site', 'foo');
export const BUNDLE_META_FILE_PATH = join(BUNDLE_PATH, BUNDLE_META_FILE);
export const HOME_VIEW_PATH = join(BUNDLE_PATH, 'sfdc_cms__view', 'home');
export const HOME_VIEW_CONTENT_FILE_PATH = join(HOME_VIEW_PATH, HOME_VIEW_CONTENT_FILE);
export const HOME_VIEW_FRENCH_VARIANT_FILE_PATH = join(HOME_VIEW_PATH, HOME_VIEW_FRENCH_VARIANT_FILE);
export const HOME_VIEW_META_FILE_PATH = join(HOME_VIEW_PATH, DE_METAFILE);

// DigitalExperienceBundle component
export const DEB_COMPONENT = SourceComponent.createVirtualComponent(
Expand All @@ -46,29 +45,13 @@ export const DEB_COMPONENT = SourceComponent.createVirtualComponent(
]
);

// DigitalExperience component for content (content.json)
export const DE_CONTENT_COMPONENT = SourceComponent.createVirtualComponent(
// DigitalExperience component
export const DE_COMPONENT = SourceComponent.createVirtualComponent(
{
name: HOME_VIEW_NAME,
type: DE_TYPE,
content: HOME_VIEW_CONTENT_FILE_PATH,
parent: DEB_COMPONENT,
parentType: DEB_TYPE,
},
[
{
dirPath: HOME_VIEW_PATH,
children: [HOME_VIEW_CONTENT_FILE, HOME_VIEW_FRENCH_VARIANT_FILE, HOME_VIEW_META_FILE],
},
]
);

// DigitalExperience component for content variant (fr.json)
export const DE_FR_VARIENT_COMPONENT = SourceComponent.createVirtualComponent(
{
name: HOME_VIEW_NAME,
type: DE_TYPE,
content: HOME_VIEW_FRENCH_VARIANT_FILE_PATH,
content: HOME_VIEW_PATH,
xml: HOME_VIEW_META_FILE_PATH,
parent: DEB_COMPONENT,
parentType: DEB_TYPE,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('DigitalExperienceSourceAdapter', () => {
name: HOME_VIEW_NAME,
type: registry.types.digitalexperiencebundle.children.types.digitalexperience,
content: HOME_VIEW_PATH,
xml: HOME_VIEW_META_FILE,
parent: new SourceComponent(
{
name: BUNDLE_NAME,
Expand Down
1 change: 1 addition & 0 deletions test/resolve/metadataResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ describe('MetadataResolver', () => {
name: 'sfdc_cms__view/home',
type: registry.types.digitalexperiencebundle.children.types.digitalexperience,
content: dirname(path),
xml: path,
parent: parentComponent,
parentType: registry.types.digitalexperiencebundle,
},
Expand Down
1 change: 1 addition & 0 deletions test/utils/filePathGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const testData = {
{
name: 'sfdc_cms__view/home', // as defined in digitalExperienceSourceAdapter.calculateNameFromPath()
type: registryAccess.getTypeByName('DigitalExperience'),
xml: getFilePath('digitalExperiences/site/foo/sfdc_cms__view/home/_meta.json'),
},
],
},
Expand Down

0 comments on commit 6ba8b87

Please sign in to comment.