From f84943f58ae8a023f2c6bb403013546880280de7 Mon Sep 17 00:00:00 2001 From: shipjs Date: Wed, 22 Jan 2020 14:04:39 +0100 Subject: [PATCH] fix: pass releaseTag to afterPublish hook --- packages/shipjs-lib/src/lib/config/defaultConfig.js | 2 +- packages/shipjs/src/flow/release.js | 2 +- .../src/step/release/__tests__/runAfterPublish.spec.js | 2 ++ packages/shipjs/src/step/release/runAfterPublish.js | 9 +++++++-- website/reference/all-config.md | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/shipjs-lib/src/lib/config/defaultConfig.js b/packages/shipjs-lib/src/lib/config/defaultConfig.js index c6306e14..cc6c7c99 100644 --- a/packages/shipjs-lib/src/lib/config/defaultConfig.js +++ b/packages/shipjs-lib/src/lib/config/defaultConfig.js @@ -108,7 +108,7 @@ export default { buildCommand: ({ isYarn }) => (isYarn ? 'yarn build' : 'npm run build'), beforePublish: undefined, // ({ exec, dir }) => {} publishCommand: ({ isYarn, tag, defaultCommand, dir }) => defaultCommand, - afterPublish: undefined, // ({ exec, dir }) => {} + afterPublish: undefined, // ({ exec, dir, version, releaseTag }) => {} getTagName: ({ version }) => `v${version}`, testCommandBeforeRelease: ({ isYarn }) => isYarn ? 'yarn test' : 'npm run test', diff --git a/packages/shipjs/src/flow/release.js b/packages/shipjs/src/flow/release.js index 7b1816ad..9ec325d9 100644 --- a/packages/shipjs/src/flow/release.js +++ b/packages/shipjs/src/flow/release.js @@ -49,7 +49,7 @@ async function release({ help = false, dir = '.', dryRun = false }) { runBuild({ isYarn, config, dir, dryRun }); await runBeforePublish({ config, dir, dryRun }); runPublish({ isYarn, config, releaseTag, dir, dryRun }); - await runAfterPublish({ version, config, dir, dryRun }); + await runAfterPublish({ version, releaseTag, config, dir, dryRun }); const { tagName } = createGitTag({ version, config, dir, dryRun }); gitPush({ tagName, config, dir, dryRun }); await createGitHubRelease({ version, config, dir, dryRun }); diff --git a/packages/shipjs/src/step/release/__tests__/runAfterPublish.spec.js b/packages/shipjs/src/step/release/__tests__/runAfterPublish.spec.js index 69820d81..81d08fe4 100644 --- a/packages/shipjs/src/step/release/__tests__/runAfterPublish.spec.js +++ b/packages/shipjs/src/step/release/__tests__/runAfterPublish.spec.js @@ -7,6 +7,7 @@ describe('runAfterPublish', () => { const afterPublish = jest.fn(); await runAfterPublish({ version: '1.2.3', + releaseTag: 'latest', config: { afterPublish, }, @@ -18,6 +19,7 @@ describe('runAfterPublish', () => { Object { "dir": ".", "exec": undefined, + "releaseTag": "latest", "version": "1.2.3", } `); diff --git a/packages/shipjs/src/step/release/runAfterPublish.js b/packages/shipjs/src/step/release/runAfterPublish.js index f5ff9562..16389b72 100644 --- a/packages/shipjs/src/step/release/runAfterPublish.js +++ b/packages/shipjs/src/step/release/runAfterPublish.js @@ -2,7 +2,7 @@ import runStep from '../runStep'; import { wrapExecWithDir, print } from '../../util'; import { info } from '../../color'; -export default ({ version, config, dir, dryRun }) => +export default ({ version, releaseTag, config, dir, dryRun }) => runStep( { title: 'Running "afterPublish" callback.', @@ -14,6 +14,11 @@ export default ({ version, config, dir, dryRun }) => print(`-> execute ${info('afterPublish()')} callback.`); return; } - await config.afterPublish({ exec: wrapExecWithDir(dir), dir, version }); + await config.afterPublish({ + exec: wrapExecWithDir(dir), + dir, + version, + releaseTag, + }); } ); diff --git a/website/reference/all-config.md b/website/reference/all-config.md index cad2fa9b..cd91ba6b 100644 --- a/website/reference/all-config.md +++ b/website/reference/all-config.md @@ -191,7 +191,7 @@ publishCommand: ({ isYarn, tag, defaultCommand, dir }) => { ```js // example -afterPublish: ({ exec, dir }) => { /* do something */ } +afterPublish: ({ exec, dir, version, releaseTag }) => { /* do something */ } ``` ## `testCommandBeforeRelease`