Skip to content

Commit

Permalink
feat(output): Add outputs as a key entity
Browse files Browse the repository at this point in the history
sfpowerscripts will now add a folder called ouputs which will have various ouputs in text or markdown format.
This could be utilized by the callers to pass
comments to thec calling CI/CD function
  • Loading branch information
azlam-abdulsalam committed Aug 22, 2023
1 parent bb18d16 commit 1212814
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SfpPackage from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackage';
import SFPLogger, { LoggerLevel, ConsoleLogger, Logger } from '@dxatscale/sfp-logger';
import SfpPackageBuilder from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackageBuilder';
import Git from '@dxatscale/sfpowerscripts.core/lib/git/Git';
import FileOutputHandler from '../../outputs/FileOutputHandler';



Expand Down Expand Up @@ -140,6 +141,14 @@ export default class ChangelogImpl {
this.logger
);


if(this.isDryRun)
{
const outputHandler:FileOutputHandler = FileOutputHandler.getInstance();
outputHandler.writeOutput('release-changelog.md',marked(new ChangelogMarkdownGenerator(releaseChangelog, this.workItemUrl, 1, false).generate()));
}


fs.writeFileSync(
path.join(pathToChangelogDirectory, `releasechangelog.json`),
JSON.stringify(releaseChangelog, null, 4)
Expand Down
17 changes: 7 additions & 10 deletions packages/sfpowerscripts-cli/src/impl/deploy/DeployImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import convertBuildNumDotDelimToHyphen from '@dxatscale/sfpowerscripts.core/lib/
import ReleaseConfig from '../release/ReleaseConfig';
import fs from 'fs-extra';
import { Align, getMarkdownTable } from 'markdown-table-ts';
import FileOutputHandler from '../../outputs/FileOutputHandler';


const Table = require('cli-table');
Expand Down Expand Up @@ -510,10 +511,8 @@ export default class DeployImpl {
tableData.table.body.push(getRowForMarkdownTable(pkg));
}
const table = getMarkdownTable(tableData);
const pathToDeploymentBreakDownFile = `.sfpowerscripts/outputs/deployment-breakdown.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToDeploymentBreakDownFile);
fs.writeFileSync(pathToDeploymentBreakDownFile, table);
const outputHandler:FileOutputHandler = FileOutputHandler.getInstance();
outputHandler.writeOutput('deployment-breakdown.md',table) ;
}

function processColoursForAllPackages(pkg) {
Expand Down Expand Up @@ -616,12 +615,10 @@ export default class DeployImpl {
for (const pkg of queue) {
tableData.table.body.push(getRowForMarkdownTable(pkg));
}

const pathToDeploymentBreakDownFile = `.sfpowerscripts/outputs/deployment-breakdown.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.appendFileSync(pathToDeploymentBreakDownFile, `Please find the packages that will be deployed below`);
fs.createFileSync(pathToDeploymentBreakDownFile);
fs.appendFileSync(pathToDeploymentBreakDownFile, `\n\n${getMarkdownTable(tableData)}`);

const outputHandler:FileOutputHandler = FileOutputHandler.getInstance();
outputHandler.writeOutput('deployment-breakdown.md',`Please find the packages that will be deployed below`);
outputHandler.appendOutput('deployment-breakdown.md',`\n\n${getMarkdownTable(tableData)}`) ;
}

function getRowForMarkdownTable(pkg:SfpPackage) {
Expand Down
30 changes: 30 additions & 0 deletions packages/sfpowerscripts-cli/src/outputs/FileOutputHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as fs from 'fs-extra';
import path from 'path';

export default class FileOutputHandler {
static instance: FileOutputHandler;

public static getInstance() {
if (!FileOutputHandler.instance)
FileOutputHandler.instance = new FileOutputHandler('.sfpowerscripts/outputs');

return FileOutputHandler.instance;
}


private constructor(private containerFolder: string) {
fs.mkdirpSync(this.containerFolder);
}

public writeOutput(fileName: string, output: string ) {
fs.writeFileSync(path.join(this.containerFolder, fileName), output);
};

public appendOutput(fileName: string,output: string) {
if (!fs.existsSync(path.join(this.containerFolder, fileName))) {
fs.createFileSync(path.join(this.containerFolder, fileName));
}
fs.appendFileSync(path.join(this.containerFolder, fileName), output);
}

}
55 changes: 27 additions & 28 deletions packages/sfpowerscripts-cli/src/ui/OrgInfoDisplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { COLON_MIDDLE_BORDER_TABLE } from "./TableConstants";
import ScratchOrg from "@dxatscale/sfpowerscripts.core/lib/scratchorg/ScratchOrg";
import { Align, getMarkdownTable } from "markdown-table-ts";
import fs from "fs-extra";
import FileOutputHandler from "../outputs/FileOutputHandler";

export default class OrgInfoDisplayer {

Expand Down Expand Up @@ -70,33 +71,32 @@ export default class OrgInfoDisplayer {
}

public static writeScratchOrgInfoToMarkDown(scratchOrg: ScratchOrg): void {
const pathToMarkDownFile = `.sfpowerscripts/outputs/org-info.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToMarkDownFile);
fs.appendFileSync(pathToMarkDownFile, `Please find the validation org details below`);
const pathToMarkDownFile = `org-info.md`;
const fileOutputHandler = FileOutputHandler.getInstance();
fileOutputHandler.writeOutput(pathToMarkDownFile, `Please find the validation org details below`);
let tableData = {
table: {
head: [
'Org Info',
'',
],
body: []
head: [
'Org Info',
'',
],
body: []
},
alignment: [Align.Left, Align.Left, Align.Left,Align.Right],
};
tableData.table.body.push([`Org Id`,scratchOrg.orgId]);
tableData.table.body.push([`Instance URL`,scratchOrg.instanceURL]);
tableData.table.body.push([`Username`,scratchOrg.username]);
tableData.table.body.push([`Password`,scratchOrg.password]);
tableData.table.body.push([`Auth URL`,scratchOrg.sfdxAuthUrl]);
tableData.table.body.push([`Expiry`,scratchOrg.expiryDate]);
fs.appendFileSync(pathToMarkDownFile, `\n\n${getMarkdownTable(tableData)}`);

fs.appendFileSync(pathToMarkDownFile,
alignment: [Align.Left, Align.Left, Align.Left, Align.Right],
};
tableData.table.body.push([`Org Id`, scratchOrg.orgId]);
tableData.table.body.push([`Instance URL`, scratchOrg.instanceURL]);
tableData.table.body.push([`Username`, scratchOrg.username]);
tableData.table.body.push([`Password`, scratchOrg.password]);
tableData.table.body.push([`Auth URL`, scratchOrg.sfdxAuthUrl]);
tableData.table.body.push([`Expiry`, scratchOrg.expiryDate]);
fileOutputHandler.appendOutput(pathToMarkDownFile, `\n\n${getMarkdownTable(tableData)}`);

fileOutputHandler.appendOutput(pathToMarkDownFile,
`You may use the following commands to authenticate to the org`,);
fs.appendFileSync(pathToMarkDownFile,`cat ${scratchOrg.sfdxAuthUrl} > ./authfile`);
fs.appendFileSync(pathToMarkDownFile,`sfdx auth sfdxurl store --sfdxurlfile authfile`);
fs.appendFileSync(pathToMarkDownFile,`sfdx force org open --u ${scratchOrg.username}`);
fileOutputHandler.appendOutput(pathToMarkDownFile, `cat ${scratchOrg.sfdxAuthUrl} > ./authfile`);
fileOutputHandler.appendOutput(pathToMarkDownFile, `sfdx auth sfdxurl store --sfdxurlfile authfile`);
fileOutputHandler.appendOutput(pathToMarkDownFile, `sfdx force org open --u ${scratchOrg.username}`);

}

Expand Down Expand Up @@ -132,10 +132,9 @@ export default class OrgInfoDisplayer {
}

public static writeOrgInfoToMarkDown(org: SFPOrg): void {
const pathToMarkDownFile = `.sfpowerscripts/outputs/org-info.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToMarkDownFile);
fs.appendFileSync(pathToMarkDownFile, `Please find the validation org details below`);
const pathToMarkDownFile = `org-info.md`;
const fileOutputHandler = FileOutputHandler.getInstance();
fileOutputHandler.appendOutput(pathToMarkDownFile, `Please find the validation org details below`);
let tableData = {
table: {
head: [
Expand All @@ -149,7 +148,7 @@ export default class OrgInfoDisplayer {
tableData.table.body.push([`Org Id`,org.getOrgId()]);
tableData.table.body.push([`Username`,org.getUsername()]);
tableData.table.body.push([`Login to the org`, `[Click Here](${org.getConnection().getAuthInfo().getOrgFrontDoorUrl()})`]);
fs.appendFileSync(pathToMarkDownFile, `\n\n${getMarkdownTable(tableData)}`);
fileOutputHandler.appendOutput(pathToMarkDownFile, `\n\n${getMarkdownTable(tableData)}`);

}

Expand Down

0 comments on commit 1212814

Please sign in to comment.