import PackageMetadata from "../../PackageMetadata" ; import SFPLogger , { LoggerLevel , Logger } from "../../logger/SFPLogger" ; import path from "path" ; import FileSystem from "../../utils/FileSystem" ; import { CreatePackage } from "./CreatePackage" ; const SFDMU_CONFIG = "export.json" ; const VLOCITY_CONFIG = "VlocityComponents.yaml" ; export default class CreateDataPackageImpl extends CreatePackage { public constructor ( projectDirectory , sfdx_package , packageArtifactMetadata , breakBuildIfEmpty = true , logger ? ) { super ( projectDirectory , sfdx_package , packageArtifactMetadata , breakBuildIfEmpty , logger ) ; } getTypeOfPackage ( ) { return "data" ; } isEmptyPackage ( packageDirectory ) { let files = FileSystem . readdirRecursive ( packageDirectory ) ; let hasExportJson = files . find ( ( file ) => path . basename ( file ) === "export.json" ) ; let hasCsvFile = files . find ( ( file ) => path . extname ( file ) === ".csv" ) ; if ( ! hasExportJson || ! hasCsvFile ) return true ; else return false ; } preCreatePackage ( packageDirectory , packageDescriptor ) { this . validateDataPackage ( packageDirectory ) ; } createPackage ( packageDirectory , packageDescriptor ) { } postCreatePackage ( packageDirectory , packageDescriptor ) { } printAdditionalPackageSpecificHeaders ( ) { } private validateDataPackage ( packageDirectory ) { const files = FileSystem . readdirRecursive ( packageDirectory ) ; let isSfdmu ; let isVlocity ; for ( const file of files ) { if ( path . basename ( file ) === SFDMU_CONFIG ) isSfdmu = true ; if ( path . basename ( file ) === VLOCITY_CONFIG ) isVlocity = true ; } if ( isSfdmu && isVlocity ) { throw new Error ( `Data package '${ this . sfdx_package }' contains both SFDMU & Vlocity configuration` ) ; } else if ( isSfdmu ) { SFPLogger . log ( `Found export.json in ${ packageDirectory }.. Utilizing it as data package and will be deployed using sfdmu` , LoggerLevel . INFO , this . logger ) ; } else if ( isVlocity ) { SFPLogger . log ( `Found VlocityComponents.yaml in ${ packageDirectory }.. Utilizing it as data package and will be deployed using vbt` , LoggerLevel . INFO , this . logger ) ; } else { throw new Error ( `Could not find export.json or VlocityComponents.yaml in ${ packageDirectory }. sfpowerscripts only support vlocity or sfdmu based data packages` ) ; } } }