From af9e9b188ccfa10dd235b4179ebe8559834ce24f Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 11 Mar 2022 16:24:14 +1100 Subject: [PATCH 1/2] Added enhancement to allow users to specify scratch org pool alias --- resources/so_pool_config.schema.json | 4 ++++ src/impl/pool/scratchorg/poolCreateImpl.ts | 4 +++- src/utils/scratchOrgUtils.ts | 13 ++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/resources/so_pool_config.schema.json b/resources/so_pool_config.schema.json index 3b9bf4f8..f9c367ef 100644 --- a/resources/so_pool_config.schema.json +++ b/resources/so_pool_config.schema.json @@ -27,6 +27,10 @@ "description": "Relax all IP ranges", "type": "boolean" }, + "alias_prefix": { + "description": "Identifier for the pool of scratch orgs created", + "type": "string" + }, "relax_ip_ranges": { "type": "array", "items": [ diff --git a/src/impl/pool/scratchorg/poolCreateImpl.ts b/src/impl/pool/scratchorg/poolCreateImpl.ts index c30f0008..8616d11e 100644 --- a/src/impl/pool/scratchorg/poolCreateImpl.ts +++ b/src/impl/pool/scratchorg/poolCreateImpl.ts @@ -317,7 +317,8 @@ export default class PoolCreateImpl { poolUser.username, this.poolConfig.pool.config_file_path, poolUser.expiry ? poolUser.expiry : this.poolConfig.pool.expiry, - this.hubOrg + this.hubOrg, + this.poolConfig.pool.alias_prefix ); poolUser.scratchOrgs.push(scratchOrg); this.totalAllocated++; @@ -679,6 +680,7 @@ export interface Pool { relax_all_ip_ranges: boolean; relax_ip_ranges: IpRanges[]; max_allocation: number; + alias_prefix?: string; } export interface PoolUser { diff --git a/src/utils/scratchOrgUtils.ts b/src/utils/scratchOrgUtils.ts index 86902226..2abaf425 100644 --- a/src/utils/scratchOrgUtils.ts +++ b/src/utils/scratchOrgUtils.ts @@ -106,7 +106,8 @@ export default class ScratchOrgUtils { adminEmail: string, config_file_path: string, expiry: number, - hubOrg: Org + hubOrg: Org, + alias_prefix?: string, ): Promise { SFPowerkit.log( 'Parameters: ' + id + ' ' + adminEmail + ' ' + config_file_path + ' ' + expiry + ' ', @@ -114,19 +115,25 @@ export default class ScratchOrgUtils { ); let result; - let getSFDXCommand = `sfdx force:org:create -f ${config_file_path} -d ${expiry} -a SO${id} -w 10 -v ${hubOrg.getUsername()} --json`; + let getSFDXCommand = `sfdx force:org:create -f ${config_file_path} -d ${expiry} -w 10 -v ${hubOrg.getUsername()} --json`; if (adminEmail) { getSFDXCommand += ` adminEmail=${adminEmail}`; } + if (alias_prefix) { + getSFDXCommand += ` --setalias ${alias_prefix}${id}` + } else { + getSFDXCommand += ` --setalias SO${id}` + } + result = child_process.execSync(getSFDXCommand, { stdio: 'pipe' }); const resultObject = JSON.parse(result); SFPowerkit.log(JSON.stringify(result), LoggerLevel.TRACE); let scratchOrg: ScratchOrg = { - alias: `SO${id}`, + alias: resultObject.result.alias, orgId: resultObject.result.orgId, username: resultObject.result.username, signupEmail: adminEmail ? adminEmail : '', From 3a8e7b115bef96bd35c52a80211878345b2644ab Mon Sep 17 00:00:00 2001 From: henry88lay Date: Fri, 11 Mar 2022 05:26:04 +0000 Subject: [PATCH 2/2] chore(prettier): Apply formatting changes --- .../sfpowerkit/org/connectedapp/create.ts | 17 +++++++++-------- src/commands/sfpowerkit/org/destruct.ts | 17 +++++++++-------- .../sfpowerkit/org/duplicaterule/activate.ts | 17 +++++++++-------- .../sfpowerkit/org/duplicaterule/deactivate.ts | 17 +++++++++-------- .../sfpowerkit/org/matchingrule/activate.ts | 17 +++++++++-------- .../sfpowerkit/org/matchingrule/deactivate.ts | 17 +++++++++-------- src/commands/sfpowerkit/org/trigger/activate.ts | 17 +++++++++-------- .../sfpowerkit/org/trigger/deactivate.ts | 17 +++++++++-------- src/commands/sfpowerkit/package/applypatch.ts | 17 +++++++++-------- src/commands/sfpowerkit/package/valid.ts | 2 +- .../sfpowerkit/source/customlabel/create.ts | 17 +++++++++-------- src/impl/org/relaxIPRangeImpl.ts | 17 +++++++++-------- src/impl/pool/scratchorg/poolCreateImpl.ts | 10 ++++++---- src/impl/project/diff/diffUtil.ts | 4 +--- src/impl/source/profiles/profileActions.ts | 4 +--- src/utils/scratchOrgUtils.ts | 6 +++--- 16 files changed, 111 insertions(+), 102 deletions(-) diff --git a/src/commands/sfpowerkit/org/connectedapp/create.ts b/src/commands/sfpowerkit/org/connectedapp/create.ts index 0c3f858c..72b31204 100644 --- a/src/commands/sfpowerkit/org/connectedapp/create.ts +++ b/src/commands/sfpowerkit/org/connectedapp/create.ts @@ -136,15 +136,16 @@ export default class Create extends SFPowerkitCommand { let deployId: AsyncResult; const zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Connected App with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/org/destruct.ts b/src/commands/sfpowerkit/org/destruct.ts index dbab0552..9e9c422c 100644 --- a/src/commands/sfpowerkit/org/destruct.ts +++ b/src/commands/sfpowerkit/org/destruct.ts @@ -143,15 +143,16 @@ export default class Destruct extends SFPowerkitCommand { let deployId: AsyncResult; const zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - SFPowerkit.log(error.message, LoggerLevel.ERROR); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + SFPowerkit.log(error.message, LoggerLevel.ERROR); + } + deployId = result; } - deployId = result; - }); + ); SFPowerkit.log( `Deploying Destructive Changes with ID ${deployId.id} to ${this.org.getUsername()}`, diff --git a/src/commands/sfpowerkit/org/duplicaterule/activate.ts b/src/commands/sfpowerkit/org/duplicaterule/activate.ts index 9507d5aa..a3867fde 100644 --- a/src/commands/sfpowerkit/org/duplicaterule/activate.ts +++ b/src/commands/sfpowerkit/org/duplicaterule/activate.ts @@ -135,15 +135,16 @@ export default class Activate extends SFPowerkitCommand { let deployId: AsyncResult; const zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Activated Rule with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/org/duplicaterule/deactivate.ts b/src/commands/sfpowerkit/org/duplicaterule/deactivate.ts index 20d88659..fe74ca47 100644 --- a/src/commands/sfpowerkit/org/duplicaterule/deactivate.ts +++ b/src/commands/sfpowerkit/org/duplicaterule/deactivate.ts @@ -136,15 +136,16 @@ export default class Deactivate extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Deactivated Rule with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/org/matchingrule/activate.ts b/src/commands/sfpowerkit/org/matchingrule/activate.ts index 4dcdd66a..99545193 100644 --- a/src/commands/sfpowerkit/org/matchingrule/activate.ts +++ b/src/commands/sfpowerkit/org/matchingrule/activate.ts @@ -138,15 +138,16 @@ export default class Activate extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Activated Matching Rule with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/org/matchingrule/deactivate.ts b/src/commands/sfpowerkit/org/matchingrule/deactivate.ts index 6745a41e..c4de9822 100644 --- a/src/commands/sfpowerkit/org/matchingrule/deactivate.ts +++ b/src/commands/sfpowerkit/org/matchingrule/deactivate.ts @@ -143,15 +143,16 @@ export default class Deactivate extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Deactivated Matching Rule with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/org/trigger/activate.ts b/src/commands/sfpowerkit/org/trigger/activate.ts index e9ea5cd8..ad5ecb38 100644 --- a/src/commands/sfpowerkit/org/trigger/activate.ts +++ b/src/commands/sfpowerkit/org/trigger/activate.ts @@ -143,15 +143,16 @@ export default class Activate extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Activated ApexTrigger with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/org/trigger/deactivate.ts b/src/commands/sfpowerkit/org/trigger/deactivate.ts index 518776d0..ae10f86c 100644 --- a/src/commands/sfpowerkit/org/trigger/deactivate.ts +++ b/src/commands/sfpowerkit/org/trigger/deactivate.ts @@ -136,15 +136,16 @@ export default class Deactivate extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Deactivated ApexTrigger with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/commands/sfpowerkit/package/applypatch.ts b/src/commands/sfpowerkit/package/applypatch.ts index 9a7e6056..0246d808 100644 --- a/src/commands/sfpowerkit/package/applypatch.ts +++ b/src/commands/sfpowerkit/package/applypatch.ts @@ -106,15 +106,16 @@ export default class Applypatch extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFileName); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); SFPowerkit.log( `Deploying Patch with ID ${deployId.id} to ${this.org.getUsername()}`, diff --git a/src/commands/sfpowerkit/package/valid.ts b/src/commands/sfpowerkit/package/valid.ts index 47b173ce..7d0e652a 100644 --- a/src/commands/sfpowerkit/package/valid.ts +++ b/src/commands/sfpowerkit/package/valid.ts @@ -138,7 +138,7 @@ Elements supported included in your package testPackage if (element.valid == false) throw new SfdxError('Analysis Failed, Unsupported metadata present'); }); } - return ({ packages: result_store } as unknown) as AnyJson; + return { packages: result_store } as unknown as AnyJson; } public async validate(packageToBeScanned: AnyJson) { diff --git a/src/commands/sfpowerkit/source/customlabel/create.ts b/src/commands/sfpowerkit/source/customlabel/create.ts index b0638fe5..4a420735 100644 --- a/src/commands/sfpowerkit/source/customlabel/create.ts +++ b/src/commands/sfpowerkit/source/customlabel/create.ts @@ -159,15 +159,16 @@ export default class Create extends SFPowerkitCommand { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); this.ux.log(`Deploying Custom Label with ID ${deployId.id} to ${this.org.getUsername()}`); let metadata_deploy_result: DeployResult = await checkDeploymentStatus(conn, deployId.id); diff --git a/src/impl/org/relaxIPRangeImpl.ts b/src/impl/org/relaxIPRangeImpl.ts index de937ad4..23e77134 100644 --- a/src/impl/org/relaxIPRangeImpl.ts +++ b/src/impl/org/relaxIPRangeImpl.ts @@ -111,15 +111,16 @@ export default class RelaxIPRangeImpl { let deployId: AsyncResult; let zipStream = fs.createReadStream(zipFile); - await conn.metadata.deploy(zipStream, { rollbackOnError: true, singlePackage: true }, function ( - error, - result: AsyncResult - ) { - if (error) { - return console.error(error); + await conn.metadata.deploy( + zipStream, + { rollbackOnError: true, singlePackage: true }, + function (error, result: AsyncResult) { + if (error) { + return console.error(error); + } + deployId = result; } - deployId = result; - }); + ); SFPowerkit.log( `${removeall ? 'Removing all' : 'Setting'} Ip range with ID ${deployId.id} to ${conn.getUsername()}`, diff --git a/src/impl/pool/scratchorg/poolCreateImpl.ts b/src/impl/pool/scratchorg/poolCreateImpl.ts index 8616d11e..76aa8746 100644 --- a/src/impl/pool/scratchorg/poolCreateImpl.ts +++ b/src/impl/pool/scratchorg/poolCreateImpl.ts @@ -44,10 +44,12 @@ export default class PoolCreateImpl { public async poolScratchOrgs(): Promise { await ScratchOrgUtils.checkForNewVersionCompatible(this.hubOrg); let scriptExecPromises: Array> = new Array(); - let ipRangeExecPromises: Array> = new Array(); + let ipRangeExecPromises: Array< + Promise<{ + username: string; + success: boolean; + }> + > = new Array(); await this.hubOrg.refreshAuth(); this.hubConn = this.hubOrg.getConnection(); diff --git a/src/impl/project/diff/diffUtil.ts b/src/impl/project/diff/diffUtil.ts index c2a2662c..da7440d9 100644 --- a/src/impl/project/diff/diffUtil.ts +++ b/src/impl/project/diff/diffUtil.ts @@ -55,9 +55,7 @@ export default class DiffUtil { return DiffUtil.gitTreeRevisionTo; } - public static async getRelativeFiles( - filePath: string - ): Promise< + public static async getRelativeFiles(filePath: string): Promise< { revision: string; path: string; diff --git a/src/impl/source/profiles/profileActions.ts b/src/impl/source/profiles/profileActions.ts index 2e32409c..42f35a1d 100644 --- a/src/impl/source/profiles/profileActions.ts +++ b/src/impl/source/profiles/profileActions.ts @@ -20,9 +20,7 @@ export default abstract class ProfileActions { this.debugFlag = debugFlag; } - protected async getProfileFullNamesWithLocalStatus( - profileNames: string[] - ): Promise<{ + protected async getProfileFullNamesWithLocalStatus(profileNames: string[]): Promise<{ added: string[]; deleted: string[]; updated: string[]; diff --git a/src/utils/scratchOrgUtils.ts b/src/utils/scratchOrgUtils.ts index 2abaf425..c0980534 100644 --- a/src/utils/scratchOrgUtils.ts +++ b/src/utils/scratchOrgUtils.ts @@ -107,7 +107,7 @@ export default class ScratchOrgUtils { config_file_path: string, expiry: number, hubOrg: Org, - alias_prefix?: string, + alias_prefix?: string ): Promise { SFPowerkit.log( 'Parameters: ' + id + ' ' + adminEmail + ' ' + config_file_path + ' ' + expiry + ' ', @@ -122,9 +122,9 @@ export default class ScratchOrgUtils { } if (alias_prefix) { - getSFDXCommand += ` --setalias ${alias_prefix}${id}` + getSFDXCommand += ` --setalias ${alias_prefix}${id}`; } else { - getSFDXCommand += ` --setalias SO${id}` + getSFDXCommand += ` --setalias SO${id}`; } result = child_process.execSync(getSFDXCommand, { stdio: 'pipe' });