Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Suppress stdout when publishing to NPM (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
aly76 authored May 5, 2021
1 parent da31daf commit 09bb61f
Showing 1 changed file with 85 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("-", "."),
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 09bb61f

Please sign in to comment.