From 181d8c6c17e28257e7697dbac056b0590f90c243 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Wed, 17 Apr 2024 17:22:48 +0200 Subject: [PATCH] fix: metadata type detection on file extension (#835) Co-authored-by: gavignon --- .github/linters/.cspell.json | 54 +++++++------- .../metadata/MetadataRepositoryImpl.test.ts | 70 ++++++++++++++++--- src/constant/metadataConstants.ts | 3 + src/metadata/MetadataRepositoryImpl.ts | 6 ++ 4 files changed, 99 insertions(+), 34 deletions(-) diff --git a/.github/linters/.cspell.json b/.github/linters/.cspell.json index 2a34dfa6..d884c493 100644 --- a/.github/linters/.cspell.json +++ b/.github/linters/.cspell.json @@ -14,7 +14,7 @@ "version": "0.2", "words": [ "\u00c0gain", - "Afile", + "afile", "amannn", "anotherignore", "apexskier", @@ -25,15 +25,15 @@ "behaviour", "benchmarkjs", "brqh", - "Cherfaoui", + "cherfaoui", "codeclimate", "codecov", - "CODECOV", - "CODEOWNERS", - "Colladon", + "codecov", + "codeowners", + "colladon", "commandsstop", "commitlint", - "Commitlint", + "commitlint", "contentassets", "customindex", "datacategorygroup", @@ -43,30 +43,31 @@ "destructiveignore", "destructiveinclude", "emailservices", - "EMAILSERVICESFUNCTION", + "emailservicesfunction", "eslintcache", + "experiencebundle", "firstsha", - "Flexi", + "flexi", "flexipage", "flexipages", "flowtest", "flowtests", "flowtype", "forceignore", - "FORCEIGNORE", + "forceignore", + "forceinclude", "forceinclude", - "FORCEINCLUDE", "friendlyname", - "FULLNAME", + "fullname", "geodata", "gitdir", "hardlinks", "iframe", - "Iframe", + "iframe", "ignorewarnings", "iife", "indx", - "Infile", + "infile", "knip", "lcov", "linebreak", @@ -75,10 +76,10 @@ "lwcc", "mdapi", "megalinter", - "Mehdi", + "mehdi", "mehdisfdc", "metafile", - "METAFILE", + "metafile", "mjyhjbm", "mkdirs", "mocharc", @@ -87,7 +88,7 @@ "mutingpermissionset", "mutingpermissionsets", "myexperiencebundle", - "Nimn", + "nimn", "nonblock", "notblank", "notexist", @@ -99,10 +100,10 @@ "oauthcustomscopes", "oclif", "omni", - "Omni", + "omni", "omnistudio", "oxsecurity", - "Parens", + "parens", "pastsha", "permissionset", "permissionsetgroup", @@ -121,17 +122,18 @@ "samlssoconfig", "samlssoconfigs", "scolladon", - "Scontrol", + "scontrol", "scontrols", - "Sebastien", + "sebastien", + "sfdx", + "sfdx", "sfdx", - "Sfdx", - "SFDX", "sgdignore", "sgdinclude", "sgdincludedestructive", "shellcheck", - "STATICRESOURCE", + "sitedotcom", + "staticresource", "staticresources", "stefanzweifel", "struc", @@ -140,17 +142,17 @@ "testkit", "testlevel", "testtest", - "Translationline", + "translationline", "trivyignore", "tsbuildinfo", "unmanaged", "unmocked", "unpackaged", - "Unpackaged", + "unpackaged", "venv", "wagoid", "wapp", - "Wavehandler", + "wavehandler", "wcomp", "wdash", "wdpr", diff --git a/__tests__/unit/lib/metadata/MetadataRepositoryImpl.test.ts b/__tests__/unit/lib/metadata/MetadataRepositoryImpl.test.ts index 9b25833f..e0e273a4 100644 --- a/__tests__/unit/lib/metadata/MetadataRepositoryImpl.test.ts +++ b/__tests__/unit/lib/metadata/MetadataRepositoryImpl.test.ts @@ -104,6 +104,27 @@ describe('MetadataRepositoryImpl', () => { suffix: 'xml', xmlName: 'EmailServicesFunction', }, + { + directoryName: 'sites', + inFolder: false, + metaFile: false, + suffix: 'site', + xmlName: 'CustomSite', + }, + { + directoryName: 'siteDotComSites', + inFolder: false, + metaFile: true, + suffix: 'site', + xmlName: 'SiteDotCom', + }, + { + directoryName: 'experiences', + inFolder: false, + metaFile: true, + suffix: 'site', + xmlName: 'ExperienceBundle', + }, ]) }) describe('has', () => { @@ -206,14 +227,47 @@ describe('MetadataRepositoryImpl', () => { ) }) - it('matches `xml` files inside `emailservices` folder', () => { - // Act - const result = sut.get('force-app/emailservices/testService.xml') - - // Assert - expect(result).toStrictEqual( - expect.objectContaining({ directoryName: 'emailservices' }) - ) + describe('special cases where it should only match on folder', () => { + it('matches `xml` files inside `emailservices` folder', () => { + // Act + const result = sut.get('force-app/emailservices/testService.xml') + + // Assert + expect(result).toStrictEqual( + expect.objectContaining({ directoryName: 'emailservices' }) + ) + }) + it('should match `Site`', () => { + // Act + const result = sut.get('Z force-app/main/default/sites/aSite.site') + + // Assert + expect(result).toStrictEqual( + expect.objectContaining({ directoryName: 'sites' }) + ) + }) + it('should match `SiteDotCom`', () => { + // Act + const result = sut.get( + 'Z force-app/main/default/siteDotComSites/aSitedotcom.site' + ) + + // Assert + expect(result).toStrictEqual( + expect.objectContaining({ directoryName: 'siteDotComSites' }) + ) + }) + it('should match `ExperienceBundle`', () => { + // Act + const result = sut.get( + 'Z force-app/main/default/experiences/aCommunity.site' + ) + + // Assert + expect(result).toStrictEqual( + expect.objectContaining({ directoryName: 'experiences' }) + ) + }) }) }) diff --git a/src/constant/metadataConstants.ts b/src/constant/metadataConstants.ts index 86298d3b..1e956e2a 100644 --- a/src/constant/metadataConstants.ts +++ b/src/constant/metadataConstants.ts @@ -2,6 +2,7 @@ export const CUSTOM_APPLICATION_TYPE = 'applications' export const EMAILSERVICESFUNCTION_SUFFIX = 'emailservices' +export const EXPERIENCEBUNDLE_FOLDER = 'experiences' export const FIELD_DIRECTORY_NAME = 'fields' export const FLOW_XML_NAME = 'Flow' export const INFOLDER_SUFFIX = `Folder` @@ -16,6 +17,8 @@ export const OBJECT_TRANSLATION_META_XML_SUFFIX = `objectTranslation${METAFILE_S export const OBJECT_TYPE = 'objects' export const OBJECT_XML_NAME = 'CustomObject' export const RESTRICTION_RULE_TYPE = 'restrictionRules' +export const SITE_FOLDER = 'sites' +export const SITEDOTCOM_FOLDER = 'siteDotComSites' export const SUB_OBJECT_TYPES = [ 'businessProcesses', 'compactLayouts', diff --git a/src/metadata/MetadataRepositoryImpl.ts b/src/metadata/MetadataRepositoryImpl.ts index e6a0108d..5169bedb 100644 --- a/src/metadata/MetadataRepositoryImpl.ts +++ b/src/metadata/MetadataRepositoryImpl.ts @@ -6,10 +6,13 @@ import { DOT, PATH_SEP } from '../constant/fsConstants' import { CUSTOM_APPLICATION_TYPE, EMAILSERVICESFUNCTION_SUFFIX, + EXPERIENCEBUNDLE_FOLDER, METAFILE_SUFFIX, OBJECT_TRANSLATION_TYPE, OBJECT_TYPE, RESTRICTION_RULE_TYPE, + SITEDOTCOM_FOLDER, + SITE_FOLDER, SUB_OBJECT_TYPES, TERRITORY_MODEL_TYPE, } from '../constant/metadataConstants' @@ -103,6 +106,9 @@ export class MetadataRepositoryImpl implements MetadataRepository { CUSTOM_APPLICATION_TYPE, RESTRICTION_RULE_TYPE, EMAILSERVICESFUNCTION_SUFFIX, + SITE_FOLDER, + SITEDOTCOM_FOLDER, + EXPERIENCEBUNDLE_FOLDER, ] private static COMPOSED_TYPES = [