hardis
mergexml
Description
Command Behavior
Merges multiple Salesforce package.xml files into a single, consolidated package.xml file.
This command is useful for combining metadata definitions from various sources (e.g., different feature branches, separate development efforts) into one comprehensive package.xml, which can then be used for deployments or retrievals.
Key functionalities:
- Flexible Input: You can specify the
package.xmlfiles to merge either by:- Providing a comma-separated list of file paths using the
--packagexmlsflag. - Specifying a folder and a glob pattern using
--folderand--patternto automatically discoverpackage.xmlfiles. - If no input is provided, an interactive menu will prompt you to select files from the
manifestfolder.
- Providing a comma-separated list of file paths using the
- Customizable Output: You can define the name and path of the resulting merged
package.xmlfile using the--resultflag.
Technical explanations
The command's technical implementation involves:
- File Discovery: It uses
globto findpackage.xmlfiles based on the provided folder and pattern, or it directly uses the list of files from the--packagexmlsflag. - Interactive Prompts: If no
package.xmlfiles are specified, it uses thepromptslibrary to allow the user to interactively select files to merge. appendPackageXmlFilesContentUtility: The core merging logic is handled by theappendPackageXmlFilesContentutility function. This function reads the content of each inputpackage.xmlfile, combines their metadata types and members, and writes the consolidated content to the specified result file.- XML Manipulation: Internally,
appendPackageXmlFilesContentparses the XML of eachpackage.xml, merges the<types>and<members>elements, and then rebuilds the XML structure for the output file. - File System Operations: It uses
fs-extrato ensure the output directory exists and to write the mergedpackage.xmlfile. - WebSocket Communication: It uses
WebSocketClient.requestOpenFileto open the generated mergedpackage.xmlfile in VS Code for immediate review.
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| debug | boolean | debug | |||
| flags-dir | option | undefined | |||
| folder -f |
option | Root folder | manifest | ||
| json | boolean | Format output as json. | |||
| packagexmls -p |
option | Comma separated list of package.xml files to merge. Will be prompted to user if not provided | |||
| pattern -x |
option | Name criteria to list package.xml files | //package.xml | ||
| result -r |
option | Result package.xml file name | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:package:mergexml
$ sf hardis:package:mergexml --folder packages --pattern /**/*.xml --result myMergedPackage.xml
$ sf hardis:package:mergexml --packagexmls "config/mypackage1.xml,config/mypackage2.xml,config/mypackage3.xml" --result myMergedPackage.xml