From 9678746c0c3ae1e3e6b1303c3a6e8a1476b676ca Mon Sep 17 00:00:00 2001 From: Jordi Vives Date: Tue, 2 Jul 2024 23:09:07 +0200 Subject: [PATCH] feat: Add support for `release.branches` in package.json --- lib/shell/sh-is-release-branch-creation-allowed.js | 2 +- lib/shell/sh-update-package.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/shell/sh-is-release-branch-creation-allowed.js b/lib/shell/sh-is-release-branch-creation-allowed.js index d9d1f85..2d61323 100644 --- a/lib/shell/sh-is-release-branch-creation-allowed.js +++ b/lib/shell/sh-is-release-branch-creation-allowed.js @@ -16,7 +16,7 @@ module.exports = function (dep) { ---------------------------------------------- Workflow for a Bump PR / Create Release Branch ---------------------------------------------- - 1) Execute npx @livingdocsIO/create-bump-pr (see example and option description) + 1) Execute npx github:livingdocsIO/create-bump-pr (see example and option description) - the script automatically updates the README.md with an empty line to indicate a change - the script create a PR to incite a new minor version 2) Go to github and merge the PR diff --git a/lib/shell/sh-update-package.js b/lib/shell/sh-update-package.js index da85625..8167c6d 100644 --- a/lib/shell/sh-update-package.js +++ b/lib/shell/sh-update-package.js @@ -7,13 +7,21 @@ module.exports = function (dep) { const { exec, logBgYellow, logYellow } = dep return function (argv) { + let propertyName logBgYellow('Update package.json with semantic-release information') // const releaseTag = exec(`echo release-$(echo ${argv.baseTag} | cut -d '.' -f1 -f2).x`) + // eslint-disable-next-line no-extra-boolean-cast + const result = exec(`jq '.release.branches != null' package.json`) + if (result.stdout) { + propertyName = 'release.branch' + } else { + propertyName = 'release.branches[0].name' + } exec(`cat package.json \ - | jq ".release.branch=\\"${argv.releaseBranchName}\\" \ + | jq ".${propertyName}=\\"${argv.releaseBranchName}\\" \ | .publishConfig.tag=\\"${argv.releaseBranchName}\\"" \ | cat > package.json.tmp && mv package.json.tmp package.json` ) - logYellow('package.json updated') + logYellow(`Updated ${propertyName} in package.json`) } }