From 26dcd68530a80760c51360f67d7fe804067a5c73 Mon Sep 17 00:00:00 2001 From: Alan Ly Date: Tue, 4 Aug 2020 08:08:54 +1000 Subject: [PATCH 1/3] Refactor Deploy Source task to utilize getMdapiPackage function --- packages/core/package-lock.json | 13 ++++ packages/core/package.json | 1 + .../src/sfdxwrappers/DeploySourceToOrgImpl.ts | 61 ++++++------------- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index f2bb7a2b3..0ee1e5d15 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -45,6 +45,19 @@ "traverse": ">=0.3.0 <0.4" } }, + "cli-table": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cli-table/-/cli-table-0.3.1.tgz", + "integrity": "sha1-9TsFJmqLGguTSz0IIebi3FkUriM=", + "requires": { + "colors": "1.0.3" + } + }, + "colors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/packages/core/package.json b/packages/core/package.json index c969a9d89..8b85e84a4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,6 +13,7 @@ "compile": "tsc -b tsconfig.json" }, "dependencies": { + "cli-table": "^0.3.1", "fs-extra": "^8.1.0", "ignore": "^5.1.6", "rimraf": "^3.0.2", diff --git a/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts b/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts index 0022c11ff..e54a04e9e 100644 --- a/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts +++ b/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts @@ -14,6 +14,8 @@ import { isNullOrUndefined } from "util"; import { onExit } from "../OnExit"; let path = require("path"); import ignore from "ignore"; +import getMDAPIPackageFromSourceDirectory from "../getMdapiPackage"; +const Table = require("cli-table"); export interface DeploySourceResult { deploy_id: string; @@ -22,7 +24,7 @@ export interface DeploySourceResult { } export default class DeploySourceToOrgImpl { - temp_folder: string; + private mdapiDir: string; public constructor( private target_org: string, @@ -30,17 +32,12 @@ export default class DeploySourceToOrgImpl { private source_directory: string, private deployment_options: any, private isToBreakBuildIfEmpty: boolean - ) { - this.temp_folder = `${this.makefolderid(5)}_mdapi`; - } + ) {} public async exec(): Promise { let commandExecStatus: boolean = false; let deploySourceResult = {} as DeploySourceResult; - //Clean mdapi directory - rimraf.sync(this.temp_folder); - //Check empty conditions let status = this.isToBreakBuildForEmptyDirectory(); if (status.result == "break") { @@ -54,7 +51,21 @@ export default class DeploySourceToOrgImpl { } console.log("Converting source to mdapi"); - await this.convertSourceToMDAPI(); + let mdapiPackage = await getMDAPIPackageFromSourceDirectory(this.project_directory, this.source_directory); + this.mdapiDir = mdapiPackage["mdapiDir"]; + + let table = new Table({ + head: ["Metadata Type", "API Name"], + }); + + for (let type of mdapiPackage["manifestAsJSON"]["Package"]["types"]) { + for (let member of type["members"]) { + let item = [type.name, member]; + table.push(item); + } + } + console.log("The following metadata will be deployed:"); + console.log(table.toString()); try { if (this.deployment_options["checkonly"]) @@ -227,7 +238,7 @@ export default class DeploySourceToOrgImpl { if (this.deployment_options["checkonly"]) command += ` -c`; //directory - command += ` -d ${this.temp_folder}`; + command += ` -d ${this.mdapiDir}`; //add json command += ` --json`; @@ -279,27 +290,6 @@ export default class DeploySourceToOrgImpl { } } - private async convertSourceToMDAPI(): Promise { - try { - if (!isNullOrUndefined(this.project_directory)) - console.log( - `Converting to Source Format ${this.source_directory} in project directory ${this.project_directory}` - ); - else - console.log( - `Converting to Source Format ${this.source_directory} in project directory` - ); - child_process.execSync( - `npx sfdx force:source:convert -r ${this.source_directory} -d ${this.temp_folder}`, - { cwd: this.project_directory, encoding: "utf8" } - ); - console.log("Converting to Source Format Completed"); - } catch (error) { - console.log("Unable to convert source, exiting" + error.code); - throw error; - } - } - private isEmptyFolder(source_directory): boolean { let files: string[] = readdirSync(source_directory); @@ -324,15 +314,4 @@ export default class DeploySourceToOrgImpl { if (files == null || files.length === 0) return true; else return false; } - - private makefolderid(length): string { - var result = ""; - var characters = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - var charactersLength = characters.length; - for (var i = 0; i < length; i++) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; - } } From 7196fdcbe6a010ac1a357088145ababc80b9576f Mon Sep 17 00:00:00 2001 From: Alan Ly Date: Wed, 5 Aug 2020 08:54:48 +1000 Subject: [PATCH 2/3] Fix table display for strings --- packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts b/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts index e54a04e9e..825640b95 100644 --- a/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts +++ b/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts @@ -59,8 +59,13 @@ export default class DeploySourceToOrgImpl { }); for (let type of mdapiPackage["manifestAsJSON"]["Package"]["types"]) { - for (let member of type["members"]) { - let item = [type.name, member]; + if (type["members"] instanceof Array) { + for (let member of type["members"]) { + let item = [type.name, member]; + table.push(item); + } + } else { + let item = [type.name, type.members]; table.push(item); } } From b8783e8a11052fe65688923b0d5f398b8adb0b8b Mon Sep 17 00:00:00 2001 From: Alan Ly Date: Wed, 5 Aug 2020 09:10:28 +1000 Subject: [PATCH 3/3] Move table to function --- .../src/sfdxwrappers/DeploySourceToOrgImpl.ts | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts b/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts index 825640b95..0d18c1afc 100644 --- a/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts +++ b/packages/core/src/sfdxwrappers/DeploySourceToOrgImpl.ts @@ -54,23 +54,7 @@ export default class DeploySourceToOrgImpl { let mdapiPackage = await getMDAPIPackageFromSourceDirectory(this.project_directory, this.source_directory); this.mdapiDir = mdapiPackage["mdapiDir"]; - let table = new Table({ - head: ["Metadata Type", "API Name"], - }); - - for (let type of mdapiPackage["manifestAsJSON"]["Package"]["types"]) { - if (type["members"] instanceof Array) { - for (let member of type["members"]) { - let item = [type.name, member]; - table.push(item); - } - } else { - let item = [type.name, type.members]; - table.push(item); - } - } - console.log("The following metadata will be deployed:"); - console.log(table.toString()); + this.printMetadataToDeploy(mdapiPackage["manifestAsJSON"]); try { if (this.deployment_options["checkonly"]) @@ -319,4 +303,24 @@ export default class DeploySourceToOrgImpl { if (files == null || files.length === 0) return true; else return false; } + + private printMetadataToDeploy(mdapiPackageManifest) { + let table = new Table({ + head: ["Metadata Type", "API Name"], + }); + + for (let type of mdapiPackageManifest["Package"]["types"]) { + if (type["members"] instanceof Array) { + for (let member of type["members"]) { + let item = [type.name, member]; + table.push(item); + } + } else { + let item = [type.name, type.members]; + table.push(item); + } + } + console.log("The following metadata will be deployed:"); + console.log(table.toString()); + } }