diff --git a/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts b/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts index 28af5925c..9fe548bc3 100644 --- a/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts +++ b/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts @@ -144,63 +144,22 @@ export default class Promote extends SfpowerscriptsCommand { try { console.log(`Publishing ${packageName} Version ${packageVersionNumber}...`); - let cmd: string; - let childProcessCwd: string; - if (this.flags.npm) { - let artifactRootDirectory = path.dirname(sourceDirectory); - childProcessCwd = artifactRootDirectory; - - // NPM does not accept packages with uppercase characters - let name: string = packageName.toLowerCase() + "_sfpowerscripts_artifact" - - if (this.flags.scope) name = `@${this.flags.scope}/` + name; - - let packageJson = { - name: name, - version: packageVersionNumber, - repository: packageMetadata.repository_url - }; - - fs.writeFileSync( - path.join(artifactRootDirectory, "package.json"), - JSON.stringify(packageJson, null, 4) + this.publishUsingNpm( + sourceDirectory, + packageName, + packageVersionNumber, + packageMetadata, + npmrcFilesToCleanup ); - - if (this.flags.npmrcpath) { - fs.copyFileSync( - this.flags.npmrcpath, - path.join(artifactRootDirectory, ".npmrc") - ); - - npmrcFilesToCleanup.push( - path.join(artifactRootDirectory, ".npmrc") - ); - } - - cmd = `npm publish`; - - if (this.flags.npmtag) cmd += ` --tag ${this.flags.npmtag}`; - } else { - childProcessCwd = process.cwd(); - - if (process.platform !== 'win32') { - cmd = `bash -e ${this.flags.scriptpath} ${packageName} ${packageVersionNumber} ${artifact} ${this.flags.publishpromotedonly}`; - } else { - cmd = `cmd.exe /c ${this.flags.scriptpath} ${packageName} ${packageVersionNumber} ${artifact} ${this.flags.publishpromotedonly}`; - } + this.publishUsingScript( + packageName, + packageVersionNumber, + artifact + ); } - child_process.execSync( - cmd, - { - cwd: childProcessCwd, - stdio: ['ignore', 'ignore', 'inherit'] - } - ); - - succesfullyPublishedPackageNamesForTagging.push({ name:packageName, version:packageVersionNumber.replace("-", "."), @@ -285,6 +244,80 @@ export default class Promote extends SfpowerscriptsCommand { } } + private publishUsingNpm( + sourceDirectory: string, + packageName: string, + packageVersionNumber: string, + packageMetadata: PackageMetadata, + npmrcFilesToCleanup: string[] + ) { + let artifactRootDirectory = path.dirname(sourceDirectory); + + // NPM does not accept packages with uppercase characters + let name: string = packageName.toLowerCase() + "_sfpowerscripts_artifact"; + + if (this.flags.scope) + name = `@${this.flags.scope}/` + name; + + let packageJson = { + name: name, + version: packageVersionNumber, + repository: packageMetadata.repository_url + }; + + fs.writeFileSync( + path.join(artifactRootDirectory, "package.json"), + JSON.stringify(packageJson, null, 4) + ); + + if (this.flags.npmrcpath) { + fs.copyFileSync( + this.flags.npmrcpath, + path.join(artifactRootDirectory, ".npmrc") + ); + + npmrcFilesToCleanup.push( + path.join(artifactRootDirectory, ".npmrc") + ); + } + + let cmd = `npm publish`; + + if (this.flags.npmtag) + cmd += ` --tag ${this.flags.npmtag}`; + + + child_process.execSync( + cmd, + { + cwd: artifactRootDirectory, + stdio: "pipe" + } + ); + } + + private publishUsingScript( + packageName: string, + packageVersionNumber: string, + artifact: string + ) { + let cmd: string; + if (process.platform !== 'win32') { + cmd = `bash -e ${this.flags.scriptpath} ${packageName} ${packageVersionNumber} ${artifact} ${this.flags.publishpromotedonly}`; + } else { + cmd = `cmd.exe /c ${this.flags.scriptpath} ${packageName} ${packageVersionNumber} ${artifact} ${this.flags.publishpromotedonly}`; + } + + + child_process.execSync( + cmd, + { + cwd: process.cwd(), + stdio: ['ignore', 'inherit', 'inherit'] + } + ); + } + protected validateFlags() { if (this.flags.scriptpath === undefined && this.flags.npm === undefined) throw new Error("Either --scriptpath or --npm flag must be provided");