import { Logger } from '@cirrusct/logging'; import { createError, MrPackage } from '@cirrusct/mr-core'; import { shellExec, ShellExecError } from '@cirrusct/shell-exec'; export const shellPublishPackage = async ( pkg: MrPackage, version: string, logger: Logger, isDryRun: boolean = false ) => { const oldCwd = process.cwd(); try { process.chdir(pkg.path); const cmdLine = `yarn publish --access public --new-version ${version}`; logger.info({ package: pkg.name, version, cmdLine, isDryRun }, 'Shelling to yarn publish'); if (!isDryRun) { const result = await shellExec(cmdLine); return result.exitCode; } else { return 0; } } catch (e) { const shellExecErr: ShellExecError = e; const errorWrapperMsg = 'Publish command failed to execute shell command'; logger.error({ exitCode: shellExecErr.exitCode, message: shellExecErr.message, shellCommand: shellExecErr.command, }, errorWrapperMsg); throw createError(errorWrapperMsg, e); } finally { process.chdir(oldCwd); } };