Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wr/overwrite object file #1338

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/convert/transformers/decomposedMetadataTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { dirname, join } from 'node:path';
import fs from 'node:fs';
import { AnyJson, JsonMap, ensureString, isJsonMap } from '@salesforce/ts-types';
import { ensureArray } from '@salesforce/kit';
import { Messages } from '@salesforce/core';
Expand Down Expand Up @@ -84,7 +85,7 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer {

const writeInfoForParent = mergeWith
? getWriteInfosFromMerge(mergeWith)(stateSetter)(parentXmlObject)(component)
: [{ source: new JsToXml(parentXmlObject), output: getOutputFile(component) }];
: getWriteInfosWithoutMerge(this.defaultDirectory)(parentXmlObject)(component);

const childDestinations = new Set(writeInfosForChildren.map((w) => w.output));

Expand Down Expand Up @@ -200,6 +201,22 @@ const getWriteInfosFromMerge =
return [];
};

const getWriteInfosWithoutMerge =
(defaultDirectory: string | undefined) =>
(parentXmlObject: XmlObj) =>
(component: SourceComponent): WriteInfo[] => {
const output = join(defaultDirectory ?? '', getOutputFile(component));
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (
if ( // avoid overwriting existing files with empty XML objects

!objectHasSomeRealValues(component.type)(parentXmlObject) &&
fs.existsSync(output) &&
Object.values(component.type.children ?? {}).every((child) => !child.isAddressable)
) {
return [];
} else {
return [{ source: new JsToXml(parentXmlObject), output }];
}
};

/**
* Helper for setting the decomposed transaction state
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this one change?

<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>FooBar</members>
<members>FooBarTest</members>
<members>MyAppTest</members>
<members>MyTest</members>
<members>force</members>
<members>my</members>
<name>ApexClass</name>
</types>
<types>
<members>Account.asdf__c</members>
<members>Case.myfield__c</members>
<members>MyObj__c.MyField__c</members>
<name>CustomField</name>
</types>
<types>
<members>force_app_Label_1</members>
<members>force_app_Label_2</members>
<members>my_app_Label_1</members>
<name>CustomLabel</name>
</types>
<types>
<members>CustomLabels</members>
<name>CustomLabels</name>
</types>
<types>
<members>MyObj__c</members>
<name>CustomObject</name>
</types>
<types>
<members>MyObj__c</members>
<name>CustomTab</name>
</types>
<types>
<members>mycomponent</members>
<name>LightningComponentBundle</name>
</types>
<version>61.0</version>
</Package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
<excludeButtons>Submit</excludeButtons>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>true</detailHeading>
<editHeading>true</editHeading>
<label>Picture</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>Picture_IMG__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Picture__c</field>
</layoutItems>
</layoutColumns>
<style>OneColumn</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Information</label>
<layoutColumns>
<layoutItems>
<behavior>Required</behavior>
<field>Name</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Title__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Email__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>test__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>aab__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>a__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>b__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>tester__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>d__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>testing__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Mobile_Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>OwnerId</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>System Information</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>CreatedById</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>LastModifiedById</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Custom Links</label>
<layoutColumns/>
<layoutColumns/>
<layoutColumns/>
<style>CustomLinks</style>
</layoutSections>
<relatedLists>
<fields>NAME</fields>
<fields>Address__c</fields>
<fields>Price__c</fields>
<fields>Beds__c</fields>
<fields>Baths__c</fields>
<relatedList>Property__c.Broker__c</relatedList>
</relatedLists>
<showEmailCheckbox>false</showEmailCheckbox>
<showHighlightsPanel>false</showHighlightsPanel>
<showInteractionLogPanel>false</showInteractionLogPanel>
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
<summaryLayout>
<masterLabel>00hR0000001UMHM</masterLabel>
<sizeX>4</sizeX>
<sizeY>0</sizeY>
<summaryLayoutStyle>Default</summaryLayoutStyle>
</summaryLayout>
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>testing__c</fullName>
<externalId>false</externalId>
<label>testing</label>
<trackTrending>false</trackTrending>
<type>AutoNumber</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
<excludeButtons>Submit</excludeButtons>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>true</detailHeading>
<editHeading>true</editHeading>
<label>Picture</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>Picture_IMG__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Picture__c</field>
</layoutItems>
</layoutColumns>
<style>OneColumn</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Information</label>
<layoutColumns>
<layoutItems>
<behavior>Required</behavior>
<field>Name</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Title__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Email__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>test__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>aab__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>a__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>b__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>tester__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>d__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>testing__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Mobile_Phone__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>OwnerId</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>System Information</label>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>CreatedById</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Readonly</behavior>
<field>LastModifiedById</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>false</detailHeading>
<editHeading>true</editHeading>
<label>Custom Links</label>
<layoutColumns/>
<layoutColumns/>
<layoutColumns/>
<style>CustomLinks</style>
</layoutSections>
<relatedLists>
<fields>NAME</fields>
<fields>Address__c</fields>
<fields>Price__c</fields>
<fields>Beds__c</fields>
<fields>Baths__c</fields>
<relatedList>Property__c.Broker__c</relatedList>
</relatedLists>
<showEmailCheckbox>false</showEmailCheckbox>
<showHighlightsPanel>false</showHighlightsPanel>
<showInteractionLogPanel>false</showInteractionLogPanel>
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
<summaryLayout>
<masterLabel>00hR0000001UMHM</masterLabel>
<sizeX>4</sizeX>
<sizeY>0</sizeY>
<summaryLayoutStyle>Default</summaryLayoutStyle>
</summaryLayout>
</Layout>
Loading
Loading