UNPKG

@aurahelper/package-generator

Version:

Aura Helper Package Generator Module to create Salesforce XML Package, to deploy, retrieve or delete elements on your Org. Support to create package from JSON File, Git Diffs or Mergin other packages.

222 lines (221 loc) 15.3 kB
import { MetadataType, PackageGeneratorResult } from "@aurahelper/core"; /** * Class to create and merge package files to deploy, retrieve or delete metadata from your Salesforce's projects. * * Can merge several package xml files (including destructiveChanges.xml and destructiveChangesPost.xml files) to combine into one file of each type, * combine all packages in one file and all detructives in another file or merge all files into one package or destructive file. * * The file names must contains at least the "package" word to identify the package XML files * and destructiveChanges or destrutiveChangesPost to the destructive files. * For example: package1.xml, destructiveChanges_uat.xml, destructiveChangesPost-v34... * * You can choose a custom API Version to create the packages, * if not specified API version, the package generator get the higher API version * from each file types, that is, for package XML files, * get the higher API of the Package XML files passed, and the same with other file types. * * The setters methods are defined like a builder pattern to make it more usefull */ export declare class PackageGenerator { apiVersion?: string | number; mergePackageFiles: boolean; mergeDestructives: boolean; isDestructive: boolean; beforeDeploy: boolean; explicit: boolean; ignoreFile?: string; destructiveIgnoreFile?: string; typesToIgnore?: string[]; /** * Constructor to instance a new PackageGenerator object * @param {string | number} [apiVersion] Api version to create the package. If not provided use the latest api version of the provided files */ constructor(apiVersion?: string | number); /** * Method to Set the api version to create the packages * @param {string | number} apiVersion Api version to create the package. If not provided use the latest api version of the provided files * * @returns {PackageGenerator} Return the package generator instance */ setApiVersion(apiVersion: string | number): PackageGenerator; /** * Method to set if merge package files * @param {boolean} [mergePackageFiles] true if want to merge the provided package files. If undefiend ot not has param, also set to true * * @returns {PackageGenerator} Return the package generator instance */ setMergePackagesFiles(mergePackageFiles?: boolean): PackageGenerator; /** * Method to set if merge destructive files * @param {boolean} [mergeDestructives] true if want to merge the provided destructive files into one single file. If undefiend ot not has param, also set to true * * @returns {PackageGenerator} Return the package generator instance */ setMergeDestructives(mergeDestructives?: boolean): PackageGenerator; /** * Method to set if merge all package and XML destructive files into one destructive file * @param {boolean} [isDestructive] true if you want to merge all files into one destructive file (valid option to merge packages full). If undefiend ot not has param, also set to true * * @returns {PackageGenerator} Return the package generator instance */ setIsDestructive(isDestructive?: boolean): PackageGenerator; /** * Method to set if the destructive file to create is before deploy, in otherwise create destructive files after deploy * @param {boolean} [beforeDeploy] true if want to merge destructive files into before deploy destructive file when select mergeDestructives. If undefiend ot not has param, also set to true * * @returns {PackageGenerator} Return the package generator instance */ setBeforeDeploy(beforeDeploy?: boolean): PackageGenerator; /** * Method to set if put all elements explicit on the package XML or use wildcards when apply * @param {boolean} [explicit] true if you want to put all metadata types explicit into the file, false to use wildcards when are all checked * * @returns {PackageGenerator} Return the package generator instance */ setExplicit(explicit?: boolean): PackageGenerator; /** * Method to set the path to the ignore file * @param {string} ignoreFile path to the ignore file to ignore some metadata types from the packages * * @returns {PackageGenerator} Return the package generator instance */ setIgnoreFile(ignoreFile: string): PackageGenerator; /** * Method to set the path to the ignore file to destructive package * @param {string} destructiveIgnoreFile path to the ignore file to ignore some metadata types from the packages * * @returns {PackageGenerator} Return the package generator instance */ setDestructiveIgnoreFile(destructiveIgnoreFile: string): PackageGenerator; /** * Method to set the Metadata Types to ignore from package (Also must be exists on ignore file) * @param {string | string[]} 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. * * @returns {PackageGenerator} Return the package generator instance */ setTypesToIgnore(typesToIgnore: string | string[]): PackageGenerator; /** * Method to merge several package xml files (including destructiveChanges.xml and destructiveChangesPost.xml files) to combine into one file of each type, combine all packages in one file and all detructives in another file. * @param {string | string[]} packageOrDestructiveFiles File or list of files to merge (including package and destructive files in the same list) * @param {string} outputFolder Folder to save the created files * * @returns {PackageGeneratorResult} Object with the merge result including the paths of the merged files * * @throws {WrongDatatypeException} If api version is not a string or number (can be undefined) * @throws {DataNotFoundException} If not package or destructive files provided * @throws {WrongFilePathException} If the package or destructive files path is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the package or destructive files path not exists or not have access to it * @throws {InvalidFilePathException} If the package or destructive files path is not a file * @throws {WrongDirectoryPathException} If the output Folder is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory */ mergePackages(packageOrDestructiveFiles: string | string[], outputFolder: string): PackageGeneratorResult; /** * Method to merge all provided files into only one file. You can choose if merge all into a package.xml, destructiveChanges.xml or destructiveChangesPost.xml * @param {string | string[]} packageOrDestructiveFiles file or list of files to merge (including package and destructive files in the same list) * @param {string} outputFolder Folder to save the created files. If not provided use the default options calling options() method * * @returns {PackageGeneratorResult} Object with the merge result including the paths of the merged files * * @throws {WrongDatatypeException} If api version is not a string or number (can be undefined) * @throws {DataNotFoundException} If not package or destructive files provided * @throws {WrongFilePathException} If the package or destructive files path is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the package or destructive files path not exists or not have access to it * @throws {InvalidFilePathException} If the package or destructive files path is not a file * @throws {WrongDirectoryPathException} If the output Folder is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory */ mergePackagesFull(packageOrDestructiveFiles: string | string[], outputFolder: string): PackageGeneratorResult; /** * Method to get the Package XML format content as string to the selected Metadata JSON file or Metadata JSON Object * @param {string | { [key: string]: MetadataType }} metadataOrPath Metadata JSON file or Metadata JSON object to get the package or destructive XML content. If not provided use the default options calling options() method * @param {boolean} [useIgnoreDestructive] True to use the ignore destructive file to ignore the package content * * @returns {string} Returns an string with the XML content * * @throws {WrongDatatypeException} If api version is not a string or number. Can't be empty or undefined * @throws {WrongFilePathException} If the package or destructive file path is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the package or destructive file path not exists or not have access to it * @throws {InvalidFilePathException} If the package or destructive file path is not a file * @throws {WrongFormatException} If file is not a JSON file or not have the correct Metadata JSON format * @throws {WrongDirectoryPathException} If the output Folder is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory */ getPackageContent(metadataOrPath: string | { [key: string]: MetadataType; }, useIgnoreDestructive?: boolean): string; /** * Method to create a package XML file with the selected Metadata JSON file or Metadata JSON Object * @param {string | { [key: string]: MetadataType }} metadataOrPath Metadata JSON file or Metadata JSON object to create the package file * @param {string} outputFolder Folder to save the created file. If not provided use the default options calling options() method * * @returns {string} Returns the path to the created file * * @throws {WrongDatatypeException} If api version is not a string or number. Can't be empty or undefined * @throws {WrongFilePathException} If the package or destructive file path is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the package or destructive file path not exists or not have access to it * @throws {InvalidFilePathException} If the package or destructive file path is not a file * @throws {WrongDirectoryPathException} If the output Folder is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory * @throws {WrongFormatException} If file is not a JSON file or not have the correct Metadata JSON format */ createPackage(metadataOrPath: string | { [key: string]: MetadataType; }, outputFolder: string): string; /** * Method to create a before deploy destructive file with the selected Metadata JSON file or Metadata JSON Object * @param {string | { [key: string]: MetadataType }} metadataOrPath Metadata JSON file or Metadata JSON object to create the destructive file * @param {string} outputFolder Folder to save the created file. If not provided use the default options calling options() method * * @returns {string} Returns the path to the created file * * @throws {WrongDatatypeException} If api version is not a string or number. Can't be empty or undefined * @throws {WrongFilePathException} If the package or destructive file path is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the package or destructive file path not exists or not have access to it * @throws {InvalidFilePathException} If the package or destructive file path is not a file * @throws {WrongFormatException} If file is not a JSON file or not have the correct Metadata JSON format * @throws {WrongDirectoryPathException} If the output Folder is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory */ createBeforeDeployDestructive(metadataOrPath: string | { [key: string]: MetadataType; }, outputFolder: string): string; /** * Method to create an after deploy destructive file with the selected Metadata JSON file or Metadata JSON Object * @param {string | { [key: string]: MetadataType }} metadataOrPath Metadata JSON file or Metadata JSON object to create the destructive file * @param {string} outputFolder Folder to save the created file. If not provided use the default options calling options() method * * @returns {string} Returns the path to the created file * * @throws {WrongDatatypeException} If api version is not a string or number. Can't be empty or undefined * @throws {WrongFilePathException} If the package or destructive file path is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the package or destructive file path not exists or not have access to it * @throws {InvalidFilePathException} If the package or destructive file path is not a file * @throws {WrongFormatException} If file is not a JSON file or not have the correct Metadata JSON format * @throws {WrongDirectoryPathException} If the output Folder is not a string or cant convert to absolute path * @throws {DirectoryNotFoundException} If the directory not exists or not have access to it * @throws {InvalidDirectoryPathException} If the path is not a directory */ createAfterDeployDestructive(metadataOrPath: string | { [key: string]: MetadataType; }, outputFolder: string): string; /** * Method to validate a Metadata JSON file or Metadata JSON Object format. If is not valid, throw several exceptions. * @param {string | any} metadataOrPath Metadata JSON file or Metadata JSON object to validate * * @throws {WrongFilePathException} If the filePath is not a string or cant convert to absolute path * @throws {FileNotFoundException} If the file not exists or not have access to it * @throws {InvalidFilePathException} If the path is not a file * @throws {WrongFormatException} If file is not a JSON file or not have the correct Metadata JSON format * * @returns {{ [key: string]: MetadataType }} Returns the Metadata Object Content validated */ static validateJSON(metadataOrPath: string | any): { [key: string]: MetadataType; }; }