Aura Helper Ignore Module
Module to ignore metadata from your salesforce projects or from a JSON metadata object. This module will be specially util in some use cases, like Custom Label values unique for every environment (like ids...), or to avoid deploy some user permissions, or when you creating autogenerated package (from git for example) and like to excludo some metadata automatically. To understund the .ahignore.json file, see Ignore File section.
This module is used to @ah/package-generator for ignore metadata types when created the package or detructive XML files. Also use @aurahelper/xml-compressor to compress the XML Files.
Table of Contents
Class to ignore metadata from your salesforce projects or from a JSON metadata object. This class will be specially util in some use cases, like Custom Label values unique for every environment (like ids...), or to avoid deploy some user permissions, or when you creating autogenerated package (from git for example) and like to excludo some metadata automatically
The setters methods are defined like a builder pattern to make it more usefull
Class Members
The fields that start with _ are for internal use only (Does not modify this fields to a correct Ignore work). To the rest of fields, setter methods are recommended instead modify fields.
Path to the ignore file
List with the Metadata Type API Names to ignore. This parameter is used to ignore only the specified metadata (also must be in ignore file) and avoid ignore all metadata types specified on the file.
string
| { [key:string]: MetadataType }
True to remove ignored elements from the result object, false only for unselect elements
True to compress the XML Files, false in otherwise
Sort order to order the XML elements. Values: simpleFirst, complexFirst, alphabetAsc or alphabetDesc. (alphabetDesc by default)
Constructor to instance a new Ignore object. All parameters are optional and you can use the setters methods to set the values when you want.
Parameters:
- ignorefile: Path to the ignore file
Method to set the callback function to handle the event Start Process Metadata Type to handle the ignore progress
Parameters:
- callback: callback function to handle the Start Process Metadata Type Event
Return:
Return the ignore object instance
Examples:
Handle progress with on Start Process Type Event
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.onStartProcessType((metadataTypeAPIName) => {
console.log(metadataTypeAPIName);
});
Method to set the callback function to handle the event End Process Metadata Type to handle the ignore progress
Parameters:
- callback: callback function to handle the End Process Metadata Type Event
Return:
Return the ignore object instance
Examples:
Handle progress with on End Process Type Event
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.onEndProcessType((metadataTypeAPIName) => {
console.log(metadataTypeAPIName);
});
Method to set the ignore file to ignore the metadata types
Parameters:
- ignorefile: Path to the ignore file
Return:
Return the ignore object instance
Examples:
Set the ignore file
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setIgnoreFile('path/to/the/ignore/file.json');
Method to set the Metadata Name or Names to ignore
Parameters:
- typesToIgnore: List with the Metadata Type API Names to ignore. This parameter is used to ignore only the specified metadata (also must be in ignore file) and avoid ignore all metadata types specified on the file.
Return:
Return the ignore object instance
Examples:
Set the types to ignore
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setTypesToIgnore(['CustomObject', 'CustomField', 'CustomTab']);
Method to set if remove metadata from Metadata Object or only unselect it
Parameters:
- remove: True to remove ignored elements from the result object, false only for unselect elements. If undefined or not pass parameter, also set to true
Return:
Return the ignore object instance
Examples:
Set remove data from Metadata Object result
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.removeData(true);
True to compress the XML Files, false in otherwise. If undefined or not pass parameter, also set to true.
Parameters:
- compress: True to compress the XML Files, false in otherwise
Return:
Return the ignore object instance
Examples:
Set compress affected XML Files
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setCompress(true);
Method to set the sort order value to sort the XML Elements when compress
Parameters:
- sortOrder: Sort order to order the XML elements. Values: simpleFirst, complexFirst, alphabetAsc or alphabetDesc. (alphabetDesc by default).
Return:
Return the ignore object instance
Examples:
Set Sort order to order XML Elements
import { XMLCompressor } from '@aurahelper/xml-compressor';
import { Ignore } from '@aurahelper/ignore';
const sortOrder = XMLCompressor.getSortOrderValues();
const ignore = new Ignore();
ignore.setSortOrder(sortOrder.SIMPLE_FIRST);
Method to set Simple XML Elements first as sort order (simpleFirst)
Return:
Return the ignore object instance
Examples:
Set Simple first sort order to order XML Elements
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setIgnoreFile('path/to/the/ignore/file.json').sortSimpleFirst();
Method to set Complex XML Elements first as sort order (complexFirst)
Return:
Return the ignore object instance
Examples:
Set Complex first sort order to order XML Elements
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setIgnoreFile('path/to/the/ignore/file.json').sortComplexFirst();
Method to set Alphabet Asc as sort order (alphabetAsc)
Return:
Return the ignore object instance
Examples:
Set Alphabet asc sort order to order XML Elements
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setIgnoreFile('path/to/the/ignore/file.json').sortAlphabetAsc();
Method to set Alphabet Desc as sort order (alphabetDesc)
Return:
Return the ignore object instance
Examples:
Set Alphabet desc sort order to order XML Elements
import { Ignore } from '@aurahelper/ignore';
const ignore = new Ignore();
ignore.setIgnoreFile('path/to/the/ignore/file.json').sortAlphabetDesc();
Method to ignore Metadata types from a Metadata JSON Object or Metadata JSON file. You can choose to uncheck elements or remove it from Metadata JSON. See Metadata JSON Format section to understand the JSON Metadata Format
Parameters:
- metadataOrPath: Metadata JSON Object or Metadata JSON file path
string
| { [key: string]: MetadataType }
Return:
Return a Metadata JSON Object with the ignored metadata unselected or removed
{ [key: string]: MetadataType }
Throws:
This method can throw the next exceptions:
WrongFilePathException
: If the metadata file path or ignore file path is not a String or can't convert to absolute pathFileNotFoundException
: If the metadata file path or ignore file not exists or not have access to itInvalidFilePathException
: If the metadata file path or ignore file is not a fileWrongFormatException
: If metadata file path or ignore file is not a JSON file or Metadata Object are wrong
Examples:
Ignore Metadata from Metadata JSON Object
import { Ignore } from '@aurahelper/ignore';
const metadataObjects = {
CustomObject: {
name: 'CustomObject',
childs: {
Account: {
name: 'Account',
checked: true,
childs: {}
}
},
checked: true,
},
CustomField: {
name: 'CustomField',
childs: {
Account: {
name: 'Account',
checked: true,
childs: {
Name: {
name: 'Name',
checked: true
}
}
}
},
checked: true,
},
{
...
}
}
const ignoreFile = './path/to/ignore/file';
const ignore = new Ignore(ignoreFile);
const metadataTypes = ignore.ignoreMetadata(metadataObjects);
console.log(metadataTypes);
Ignore Specified Metadata from Metadata JSON File
import { Ignore } from '@aurahelper/ignore';
const typesForIgnore = ['CustomObject'];
const metadataPath = 'path/to/json/file';
const ignoreFile = './path/to/ignore/file';
const ignore = new Ignore(ignoreFile).setTypesToIgnore(typesForIgnore);
const metadataTypes = Ignore.ignoreMetadata(metadataPath);
console.log(metadataTypes);
Ignore Metadata and Remove from Metadata JSON File
import { Ignore } from '@aurahelper/ignore';
const remove = true;
const metadataPath = 'path/to/json/file';
const ignoreFile = './path/to/ignore/file';
const ignore = new Ignore(ignoreFile);
ignore.removeData(remove);
const metadataTypes = Ignore.ignoreMetadata(metadataPath);
console.log(metadataTypes);
Method to ignore Metadata types from your local project. This method can delete some data from XML Files or entire XML files or folders according the ignore file data
Parameters:
- projectPath: Salesforce Project root path
- metadataDetails: Metadata details list
Throws:
This method can throw the next exceptions:
WrongFilePathException
: If the ignore file path is not a String or can't convert to absolute pathFileNotFoundException
: If the ignore file not exists or not have access to itInvalidFilePathException
: If the ignore file is not a fileWrongFormatException
: If ignore file is not a JSON fileWrongDirectoryPathException
: If the project path is not a String or can't convert to absolute pathDirectoryNotFoundException
: If the project path directory not exists or not have access to itInvalidDirectoryPathException
: If the project path is not a directory
Examples:
Ignore Metadata from Project
This option can remove entire file or folders from your project, or remove some metadata into your files like some custom labels from the custom labels file, or workflow alerts from your Account workflow file for example. For this operation, also need a Metadata Details from your salesforce project. You can get it with @ah/connector from your org using the listMetadataTypes() method. Also allow to you to compress files with the @aurahelper/xml-compressor
import { Ignore } from '@aurahelper/ignore';
import { XMLCompressor, SORT_ORDER } from '@aurahelper/xml-compressor';
import { Connection } from '@aurahelper/connector';
const connection = new Connection('MyOrg', '50');
connection.setUsernameOrAlias('MyOrg');
connection.setSingleThread();
connection.listMetadataTypes().then((metadataDetails) => {
const ignore = new Ignore('./path/to/ignore/file');
ignore.ignoreProjectMetadata('path/to/your/project', metadataDetails);
ignore.setTypesToIgnore(['CustomObject', 'CustomField', 'ApexClass']);
Ignore.ignoreProjectMetadata('path/to/your/project', metadataDetails);
ignore.setCompress().sortSimpleFirst().setTypesToIgnore(['CustomObject', 'CustomField', 'ApexClass']);
ignore.ignoreProjectMetadata('path/to/your/project', metadataDetails);
}).catch((error) => {
});
The Metadata JSON Format used by Aura Helper Framework and modules have the next structure. Some fields are required and the datatypes checked to ensure the correct file structure.
{
"MetadataAPIName": {
"name": "MetadataAPIName",
"checked": false,
"path": "path/to/the/metadata/folder",
"suffix": "fileSuffix",
"childs": {
"MetadataObjectName":{
"name": "MetadataObjectName",
"checked": false,
"path": "path/to/the/metadata/file/or/folder",
"childs": {
"MetadataItemName": {
"name": "MetadataItemName",
"checked": false,
"path": "path/to/the/metadata/file"
},
"MetadataItemName2": {
...
},
...,
...,
...
}
}
"MetadataObjectName2":{
...
},
...,
...,
...
}
}
}
Example:
{
"CustomObject": {
"name": "CustomObject",
"checked": false,
"path": "path/to/root/project/force-app/main/default/objects",
"suffix": "object",
"childs": {
"Account": {
"name": "Account",
"checked": true,
"path": "path/to/root/project/force-app/main/default/objects/Account/Account.object-meta.xml",
"childs": {}
},
"Case": {
"name": "Case",
"checked": true,
"path": "path/to/root/project/force-app/main/default/objects/Case/Case.object-meta.xml",
"childs": {}
},
...,
...,
...
}
},
"CustomField": {
"name": "CustomField",
"checked": false,
"path": "path/to/root/project/force-app/main/default/objects",
"suffix": "field",
"childs": {
"Account": {
"name": "Account",
"checked": false,
"path": "path/to/root/project/force-app/main/default/objects/Account/fields",
"childs": {
"customField__c": {
"name": "customField__c",
"checked": true,
"path": "path/to/root/project/force-app/main/default/objects/Account/fields/customField__c.field-meta.xml",
},
...,
...,
...
}
},
"Case": {
"name": "Case",
"checked": false,
"path": "path/to/root/project/force-app/main/default/objects/Case/fields",
"childs": {
"CaseNumber": {
"name": "CaseNumber",
"checked": true,
"path": "path/to/root/project/force-app/main/default/objects/Account/fields/CaseNumber.field-meta.xml",
},
...,
...,
...
}
},
...,
...,
...
}
}
}
The ignore file is a JSON file used on ignore, create package or repair dependencies modules. On this file you can specify metadata types, objects and elements for ignore or delete from your local project or package files. You can have a main ignore file on your root project (like gitignore) named .ahignore.json for use automatically, or have different ignore files and specify it on the commands when you need tou use.
The ignore file have the next structure
{
"MetadataTypeAPIName": {
"MetadataObject1",
"MetadataObject2"
}
"MetadataTypeAPIName": {
"MetadataObject1:MetadataItem1",
"MetadataObject1:MetadataItem2",
"MetadataObject2:*",
"*",
"*:*"
}
"MetadataTypeAPIName": {
"UserPermission:MetadataObject1:PermissionName",
"UserPermission:MetadataObject2:*",
"UserPermission:*:PermissionName"
}
}
Example:
{
"CustomLabels": {
"labelName1",
"labelName2",
"*"
},
"AssignmentRules":{
"Case:Assign1",
"Lead:*",
"*"
},
"CustomObject": {
"Account",
"Case:*",
"*",
"*:*",
},
"Report": {
"ReportFolder",
"ReportFolder1:ReportName2",
"*",
},
"Workflow": {
"Account",
"*"
},
"WorkflowRule": {
"Case:*",
"Account:Rule1",
"*"
},
"Profile": {
"UserPermission:*:Permission1",
"UserPermission:TestProfile:*",
"UserPermission:Admin:Perm1",
"TestProfile2",
"*"
}
}
IMPORTANT
Some Metadata Types have singular and plural name like CustomLabels, MatchingRules, EscalationRules... For ignore or remove this types you must use the plural name, if use the singular name the ignore process not take effect with this types.