Skip to content

Commit

Permalink
feat: add beforePublish and afterPublish hook (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Oct 4, 2019
1 parent e4f8cf9 commit 0de5d68
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/shipjs-lib/src/lib/config/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export default {
].join(', ')}]`;
},
buildCommand: ({ isYarn }) => (isYarn ? 'yarn build' : 'npm run build'),
beforePublish: undefined,
publishCommand: ({ isYarn, tag, defaultCommand, dir }) => defaultCommand,
afterPublish: undefined,
getTagName: ({ version }) => `v${version}`,
testCommandBeforeRelease: ({ isYarn }) =>
isYarn ? 'yarn test' : 'npm run test',
Expand Down
4 changes: 4 additions & 0 deletions packages/shipjs/src/flow/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import notifyReleaseStart from '../step/release/notifyReleaseStart';
import detectYarn from '../step/detectYarn';
import runTest from '../step/release/runTest';
import runBuild from '../step/release/runBuild';
import runBeforePublish from '../step/release/runBeforePublish';
import runPublish from '../step/release/runPublish';
import runAfterPublish from '../step/release/runAfterPublish';
import createGitTag from '../step/release/createGitTag';
import gitPush from '../step/release/gitPush';
import notifyReleaseSuccess from '../step/release/notifyReleaseSuccess';
Expand Down Expand Up @@ -42,7 +44,9 @@ async function release({ help = false, dir = '.', dryRun = false }) {
const isYarn = detectYarn({ dir });
runTest({ isYarn, config, dir, dryRun });
runBuild({ isYarn, config, dir, dryRun });
await runBeforePublish({ config });
runPublish({ isYarn, config, releaseTag, dir, dryRun });
await runAfterPublish({ config });
const { tagName } = createGitTag({ version, config, dir, dryRun });
gitPush({ tagName, config, dir, dryRun });
await notifyReleaseSuccess({
Expand Down
13 changes: 13 additions & 0 deletions packages/shipjs/src/step/release/runAfterPublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import runStep from '../runStep';

export default ({ config }) =>
runStep(
{
title: 'Running "afterPublish" callback.',
skipIf: () =>
!config.afterPublish || typeof config.afterPublish !== 'function',
},
async () => {
await config.afterPublish();
}
);
13 changes: 13 additions & 0 deletions packages/shipjs/src/step/release/runBeforePublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import runStep from '../runStep';

export default ({ config }) =>
runStep(
{
title: 'Running "beforePublish" callback.',
skipIf: () =>
!config.beforePublish || typeof config.beforePublish !== 'function',
},
async () => {
await config.beforePublish();
}
);
5 changes: 4 additions & 1 deletion packages/shipjs/src/step/runStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { info, warning, error, bold, underline, slateblue } from '../color';
const makeSpaces = num => ' '.repeat(num);
const indentPrint = indent => (...args) => print(makeSpaces(indent), ...args);

export default function runStep({ title }, stepFn) {
export default function runStep({ title, skipIf }, stepFn) {
if (title) {
print(bold(slateblue(`› ${title}`)));
}
if (skipIf && typeof skipIf === 'function' && skipIf() === true) {
return null;
}
return stepFn({
run: wrapRun({ exec, print, error }),
print: indentPrint(2),
Expand Down

0 comments on commit 0de5d68

Please sign in to comment.