Skip to content

Commit

Permalink
refactor(logs): refactor header from each class to a utlity function …
Browse files Browse the repository at this point in the history
…in sfplogger
  • Loading branch information
azlam-abdulsalam committed Aug 7, 2023
1 parent 0dbef96 commit 60b4e9d
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 228 deletions.
25 changes: 4 additions & 21 deletions packages/sfpowerscripts-cli/src/BuildBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ export default abstract class BuildBase extends SfpowerscriptsCommand {
SFPLogger.log(COLOR_HEADER(`Config File Path: ${flags.configfilepath}`));
}
SFPLogger.log(COLOR_HEADER(`Artifact Directory: ${flags.artifactdir}`));
SFPLogger.log(
COLOR_HEADER(
`-------------------------------------------------------------------------------------------`
)
);

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
let executionStartTime = Date.now();


Expand All @@ -151,11 +146,7 @@ export default abstract class BuildBase extends SfpowerscriptsCommand {
) {
SFPLogger.log(`${EOL}${EOL}`);
SFPLogger.log(COLOR_INFO('No packages found to be built.. Exiting.. '));
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
throw new Error('No packages to be found to be built');
}

Expand Down Expand Up @@ -185,11 +176,7 @@ export default abstract class BuildBase extends SfpowerscriptsCommand {
process.exitCode = 1;
} finally {
if (buildExecResult?.generatedPackages?.length > 0 || buildExecResult?.failedPackages?.length > 0) {
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(
COLOR_SUCCESS(
`${buildExecResult.generatedPackages.length} packages created in ${COLOR_TIME(
Expand All @@ -204,11 +191,7 @@ export default abstract class BuildBase extends SfpowerscriptsCommand {
if (artifactCreationErrors.length > 0)
SFPLogger.log(COLOR_ERROR(`Failed To Create Artifacts`, artifactCreationErrors));

SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

const buildResult: BuildResult = {
packages: [],
Expand Down
12 changes: 2 additions & 10 deletions packages/sfpowerscripts-cli/src/SfpowerscriptsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,14 @@ export default abstract class SfpowerscriptsCommand extends Command {


if (!this.jsonEnabled()) {
SFPLogger.log(
COLOR_HEADER(
`-------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(
COLOR_HEADER(
`sfpowerscripts -- The DX@Scale CI/CD Orchestrator -Version:${this.config.version} -Release:${this.config.pjson.release}`
)
);

SFPLogger.log(
COLOR_HEADER(
`-------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
}
else
{
Expand Down
16 changes: 7 additions & 9 deletions packages/sfpowerscripts-cli/src/commands/artifacts/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import SfpowerscriptsCommand from '../../SfpowerscriptsCommand';
import { Messages } from '@salesforce/core';
import { LoggerLevel, Messages } from '@salesforce/core';
import FetchImpl, { ArtifactVersion } from '../../impl/artifacts/FetchImpl';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
import FetchArtifactsError from '../../impl/artifacts/FetchArtifactsError';
import { ConsoleLogger } from '@dxatscale/sfp-logger';
import { Flags } from '@oclif/core';
import { loglevel } from '../../flags/sfdxflags';
import SFPLogger from '@dxatscale/sfp-logger';
import { COLOR_HEADER } from '@dxatscale/sfp-logger';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@dxatscale/sfpowerscripts', 'fetch');
Expand Down Expand Up @@ -92,17 +94,13 @@ export default class Fetch extends SfpowerscriptsCommand {
result: { success: ArtifactVersion[]; failed:ArtifactVersion[] },
totalElapsedTime: number
) {
console.log(
`----------------------------------------------------------------------------------------------------`
);
console.log(`Fetched ${result.success.length} artifacts`);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(`Fetched ${result.success.length} artifacts`);

if (result.failed.length > 0) console.log(`Failed to fetch ${result.failed.length} artifacts`);

console.log(`Elapsed Time: ${new Date(totalElapsedTime).toISOString().substr(11, 8)}`);
console.log(
`----------------------------------------------------------------------------------------------------`
);
SFPLogger.log(`Elapsed Time: ${new Date(totalElapsedTime).toISOString().substr(11, 8)}`);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
}

protected validateFlags() {
Expand Down
17 changes: 4 additions & 13 deletions packages/sfpowerscripts-cli/src/commands/orchestrator/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { COLOR_TIME } from '@dxatscale/sfp-logger';
import getFormattedTime from '@dxatscale/sfpowerscripts.core/lib/utils/GetFormattedTime';
import { Flags } from '@oclif/core';
import { arrayFlagSfdxStyle, loglevel, logsgroupsymbol, requiredUserNameFlag } from '../../flags/sfdxflags';
import { LoggerLevel } from '@dxatscale/sfp-logger';

// Initialize Messages with the current plugin directory
Messages.importMessagesDirectory(__dirname);
Expand Down Expand Up @@ -85,9 +86,7 @@ export default class Deploy extends SfpowerscriptsCommand {
SFPLogger.log(COLOR_HEADER(`Target Environment: ${this.flags.targetorg}`));
if(this.flags.releaseconfig) SFPLogger.log(COLOR_HEADER(`Filter according to: ${this.flags.releaseconfig}`));
if (this.flags.baselineorg) SFPLogger.log(COLOR_HEADER(`Baselined Against Org: ${this.flags.baselineorg}`));
SFPLogger.log(
COLOR_HEADER(`-------------------------------------------------------------------------------------------`)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

let deploymentResult: DeploymentResult;

Expand Down Expand Up @@ -129,11 +128,7 @@ export default class Deploy extends SfpowerscriptsCommand {
let totalElapsedTime: number = Date.now() - executionStartTime;


SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(
COLOR_SUCCESS(
`${deploymentResult.deployed.length} packages deployed in ${COLOR_TIME(
Expand All @@ -150,11 +145,7 @@ export default class Deploy extends SfpowerscriptsCommand {
)
);
}
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);


SFPStatsSender.logCount('deploy.scheduled', tags);
Expand Down
28 changes: 5 additions & 23 deletions packages/sfpowerscripts-cli/src/commands/orchestrator/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ export default class Prepare extends SfpowerscriptsCommand {
let results = await prepareImpl.exec();
if (results.isOk()) {
let totalElapsedTime = Date.now() - executionStartTime;
SFPLogger.log(
COLOR_HEADER(
`-----------------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(
COLOR_SUCCESS(
`Provisioned {${results.value.scratchOrgs.length}} scratchorgs out of ${
Expand All @@ -110,29 +106,17 @@ export default class Prepare extends SfpowerscriptsCommand {
)} `
)
);
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

await this.getCurrentRemainingNumberOfOrgsInPoolAndReport(poolConfig);

SFPStatsSender.logGauge('prepare.succeededorgs', results.value.scratchOrgs.length, tags);
if (results.value.scratchOrgs.length > 0)
SFPStatsSender.logGauge('prepare.duration', Date.now() - executionStartTime, tags);
} else if (results.isErr()) {
SFPLogger.log(
COLOR_HEADER(
`-----------------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(COLOR_ERROR(results.error.message), LoggerLevel.ERROR);
SFPLogger.log(
COLOR_HEADER(
`-----------------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

switch (results.error.errorCode) {
case PoolErrorCodes.Max_Capacity:
Expand Down Expand Up @@ -190,9 +174,7 @@ export default class Prepare extends SfpowerscriptsCommand {
}
}

SFPLogger.log(
COLOR_HEADER(`-------------------------------------------------------------------------------------------`)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
}

private async getCurrentRemainingNumberOfOrgsInPoolAndReport(poolConfig: PoolConfig) {
Expand Down
10 changes: 6 additions & 4 deletions packages/sfpowerscripts-cli/src/commands/orchestrator/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import SfpPackageBuilder from '@dxatscale/sfpowerscripts.core/lib/package/SfpPac
import { PackageType } from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackage';
import { Flags, ux } from '@oclif/core';
import { loglevel, targetdevhubusername } from '../../flags/sfdxflags';
import { LoggerLevel } from '@dxatscale/sfp-logger';
import { COLOR_HEADER } from '@dxatscale/sfp-logger';
import SFPLogger from '@dxatscale/sfp-logger';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@dxatscale/sfpowerscripts', 'promote');
Expand Down Expand Up @@ -39,10 +42,9 @@ export default class Promote extends SfpowerscriptsCommand {
};

public async execute() {
console.log('-----------sfpowerscripts orchestrator ------------------');
console.log('command: promote');
console.log(`Artifact Directory: ${this.flags.artifactdir}`);
console.log('---------------------------------------------------------');
SFPLogger.log(COLOR_HEADER('command: promote'));
SFPLogger.log(COLOR_HEADER(`Artifact Directory: ${this.flags.artifactdir}`));
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

//Refresh HubOrg Authentication
await this.hubOrg.refreshAuth();
Expand Down
19 changes: 3 additions & 16 deletions packages/sfpowerscripts-cli/src/commands/orchestrator/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ export default class Promote extends SfpowerscriptsCommand {
SFPLogger.log(
COLOR_HEADER(`Publish promoted artifacts only: ${this.flags.publishpromotedonly ? true : false}`)
);
SFPLogger.log(
COLOR_HEADER(
`-------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
let packageVersionList: any;
if (this.flags.publishpromotedonly) {
let hubOrg = await SFPOrg.create({ aliasOrUsername: this.flags.devhubalias });
Expand Down Expand Up @@ -229,11 +225,7 @@ export default class Promote extends SfpowerscriptsCommand {

let totalElapsedTime: number = Date.now() - executionStartTime;

SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.log(
COLOR_SUCCESS(
`${nPublishedArtifacts} artifacts published in ${COLOR_TIME(
Expand All @@ -245,12 +237,7 @@ export default class Promote extends SfpowerscriptsCommand {
if (failedArtifacts.length > 0) {
SFPLogger.log(COLOR_ERROR(`Packages Failed to Publish`, failedArtifacts));
}
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
let tags = {
publish_promoted_only: this.flags.publishpromotedonly ? 'true' : 'false',
};
Expand Down
20 changes: 5 additions & 15 deletions packages/sfpowerscripts-cli/src/commands/orchestrator/release.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SfpowerscriptsCommand from '../../SfpowerscriptsCommand';
import { Messages } from '@salesforce/core';
import { LoggerLevel, Messages } from '@salesforce/core';
import SFPStatsSender from '@dxatscale/sfpowerscripts.core/lib/stats/SFPStatsSender';
import ReleaseImpl, { ReleaseProps, ReleaseResult } from '../../impl/release/ReleaseImpl';
import ReleaseDefinition from '../../impl/release/ReleaseDefinition';
Expand Down Expand Up @@ -116,9 +116,7 @@ export default class Release extends SfpowerscriptsCommand {
SFPLogger.log(COLOR_HEADER(`Release Definitions: ${this.flags.releasedefinition}`));
SFPLogger.log(COLOR_HEADER(`Artifact Directory: ${path.resolve('artifacts')}`));

SFPLogger.log(
COLOR_HEADER(`-------------------------------------------------------------------------------------------`)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

let releaseDefinitions: ReleaseDefinitionSchema[] = [];
for (const pathToReleaseDefintion of this.flags.releasedefinition) {
Expand Down Expand Up @@ -216,12 +214,8 @@ export default class Release extends SfpowerscriptsCommand {
private printReleaseSummary(releaseResult: ReleaseResult, totalElapsedTime: number): void {
if (this.flags.logsgroupsymbol?.[0])
SFPLogger.log(COLOR_HEADER(this.flags.logsgroupsymbol[0], 'Release Summary'));

SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
if (releaseResult.installDependenciesResult) {
SFPLogger.log(COLOR_HEADER(`\nPackage Dependencies`));
SFPLogger.log(COLOR_SUCCESS(` ${releaseResult.installDependenciesResult.success.length} succeeded`));
Expand All @@ -247,11 +241,7 @@ export default class Release extends SfpowerscriptsCommand {
}

SFPLogger.log(COLOR_TIME(`\nElapsed Time: ${new Date(totalElapsedTime).toISOString().substr(11, 8)}`));
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
}

protected validateFlags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ValidateResult from '../../impl/validate/ValidateResult';
import * as fs from 'fs-extra';
import { arrayFlagSfdxStyle, loglevel, logsgroupsymbol, targetdevhubusername } from '../../flags/sfdxflags';
import { Flags } from '@oclif/core';
import { LoggerLevel } from '@dxatscale/sfp-logger';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@dxatscale/sfpowerscripts', 'validate');
Expand Down Expand Up @@ -130,9 +131,7 @@ export default class Validate extends SfpowerscriptsCommand {
);


SFPLogger.log(
COLOR_HEADER(`-------------------------------------------------------------------------------------------`)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

let validateResult: ValidateResult;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Messages, Org } from '@salesforce/core';
import { LoggerLevel, Messages, Org } from '@salesforce/core';
import SfpowerscriptsCommand from '../../SfpowerscriptsCommand';
import ValidateImpl, { ValidateAgainst, ValidateProps, ValidationMode } from '../../impl/validate/ValidateImpl';
import SFPStatsSender from '@dxatscale/sfpowerscripts.core/lib/stats/SFPStatsSender';
Expand Down Expand Up @@ -95,10 +95,7 @@ export default class ValidateAgainstOrg extends SfpowerscriptsCommand {
}


SFPLogger.log(
COLOR_HEADER(`-------------------------------------------------------------------------------------------`)
);

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);


let validateResult: ValidateResult;
Expand Down
12 changes: 2 additions & 10 deletions packages/sfpowerscripts-cli/src/commands/pool/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ export default class Fetch extends SfpowerscriptsCommand {
}

private printFetchSummary(isSourceTrackingEnabled: boolean, totalElapsedTime: number): void {
SFPLogger.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
if (!isSourceTrackingEnabled) {
SFPLogger.log(
COLOR_SUCCESS(`Succesfully fetched a scratch org in ${COLOR_TIME(getFormattedTime(totalElapsedTime))}`)
Expand All @@ -164,10 +160,6 @@ export default class Fetch extends SfpowerscriptsCommand {
)
);
}
console.log(
COLOR_HEADER(
`----------------------------------------------------------------------------------------------------`
)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
}
}
4 changes: 1 addition & 3 deletions packages/sfpowerscripts-cli/src/commands/repo/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ export default class Patch extends SfpowerscriptsCommand {
LoggerLevel.INFO,
logger
);
SFPLogger.log(
COLOR_HEADER(`-------------------------------------------------------------------------------------------`)
);
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

//Load release definition
let releaseDefinitions = await this.loadReleaseDefintions(this.flags.releasedefinitions);
Expand Down
Loading

0 comments on commit 60b4e9d

Please sign in to comment.