Skip to content

Commit

Permalink
Add hooks to execute commands: beforeStartCommand, beforeStageCommand…
Browse files Browse the repository at this point in the history
… (src/dist), afterReleaseCommand (src/dist) (resolves #37)
  • Loading branch information
webpro committed Sep 24, 2015
1 parent 7411111 commit ba6a05c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ Options:
"changelogCommand": "git log --pretty=format:'* %s (%h)' [REV_RANGE]",
"requireCleanWorkingDir": false,
"src": {
"pushRepo": null
"pushRepo": null,
"beforeStartCommand": false,
"beforeStageCommand": false,
"afterReleaseCommand": false
},
"dist": {
"repo": false,
"stageDir": ".stage",
"baseDir": "dist",
"files": ["**/*"],
"pkgFiles": null
"pkgFiles": null,
"beforeStageCommand": false,
"afterReleaseCommand": false
},
"npm": {
"publish": false,
Expand All @@ -137,6 +142,7 @@ Notes:

* If `src.pushRepo` has a falsey value, just `git push` is used. Otherwise, it's the url or name of a remote in `git push <src.pushRepo>`.
* If `dist.pkgFiles` has a falsey value, it will take the value of `pkgFiles`.
* The `after*/before*` commands are executed from the root/working directory of the source or distribution repository. The `beforeStageCommand` is executed before files are staged for commit, and after a version bump.

### Distribution Repository

Expand Down
9 changes: 7 additions & 2 deletions conf/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
"changelogCommand": "git log --pretty=format:'* %s (%h)' [REV_RANGE]",
"requireCleanWorkingDir": false,
"src": {
"pushRepo": null
"pushRepo": null,
"beforeStartCommand": false,
"beforeStageCommand": false,
"afterReleaseCommand": false
},
"dist": {
"repo": false,
"stageDir": ".stage",
"baseDir": "dist",
"files": ["**/*"],
"pkgFiles": null
"pkgFiles": null,
"beforeStageCommand": false,
"afterReleaseCommand": false
},
"npm": {
"publish": false,
Expand Down
16 changes: 14 additions & 2 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ function releaseSourceRepo(options) {
var repo = getSrcRepoTasks(options);

var executeTasks = [
repo.beforeStartCommand,
repo.isRepo,
repo.checkClean,
repo.bump,
repo.mkCleanDir,
repo.beforeStageCommand,
repo.buildCommand,
repo.stage,
repo.stageDir,
Expand All @@ -86,6 +88,7 @@ function releaseSourceRepo(options) {
executeTasks.push(distRepoTasks.copy);
executeTasks.push(distRepoTasks.pushd);
executeTasks.push(distRepoTasks.bump);
executeTasks.push(distRepoTasks.beforeStageCommand);
executeTasks.push(distRepoTasks.stageDir);
executeTasks.push(distRepoTasks.hasChanges);
executeTasks.push(distRepoTasks.popd);
Expand All @@ -108,6 +111,8 @@ function releaseSourceRepo(options) {

}

executeTasks.push(repo.afterReleaseCommand);

return sequence(executeTasks);

}
Expand Down Expand Up @@ -143,6 +148,8 @@ function releaseDistRepo(options) {

}

executeTasks.push(repo.afterReleaseCommand);

executeTasks.push(repo.popd);

return sequence(executeTasks);
Expand Down Expand Up @@ -171,15 +178,18 @@ function getSrcRepoTasks(options) {
return _.extend({}, getGenericTasks(options), {
mkCleanDir: isMakeBaseDir ? shell.mkCleanDir.bind(null, options.dist.baseDir) : noop,
buildCommand: shell.build.bind(null, options.buildCommand),
beforeStartCommand: options.src.beforeStartCommand ? shell.run.bind(null, options.src.beforeStartCommand) : noop,
checkClean: git.isWorkingDirClean.bind(null, options.requireCleanWorkingDir),
bump: shell.bump.bind(null, options.pkgFiles, options.version),
beforeStageCommand: options.src.beforeStageCommand ? shell.run.bind(null, options.src.beforeStageCommand) : noop,
stage: git.stage.bind(null, options.pkgFiles),
stageDir: isStageBuildDir ? git.stageDir.bind(null, options.dist.baseDir) : noop,
hasChanges: git.hasChanges.bind(null, 'src'),
push: git.push.bind(null, options.remoteUrl, options.src.pushRepo),
pushTags: git.pushTags.bind(null, options.src.pushRepo),
release: options.github.release ? git.release.bind(null, options, options.remoteUrl) : noop,
publish: isPublish ? shell.npmPublish.bind(null, options.npm.publishPath, options.npm.tag) : noop
publish: isPublish ? shell.npmPublish.bind(null, options.npm.publishPath, options.npm.tag) : noop,
afterReleaseCommand: options.src.afterReleaseCommand ? shell.run.bind(null, options.src.afterReleaseCommand) : noop
});
}

Expand All @@ -190,12 +200,14 @@ function getDistRepoTasks(options) {

return _.extend({}, getGenericTasks(options), {
bump: shell.bump.bind(null, distPkgFiles, options.version),
beforeStageCommand: options.dist.beforeStageCommand ? shell.run.bind(null, options.dist.beforeStageCommand) : noop,
hasChanges: git.hasChanges.bind(null, 'dist'),
clone: git.clone.bind(null, options.dist.repo, options.dist.stageDir),
copy: shell.copy.bind(null, options.dist.files, {cwd: options.dist.baseDir}, options.dist.stageDir),
pushd: shell.pushd.bind(null, options.dist.stageDir),
release: options.github.release ? git.release.bind(null, options, options.dist.repo) : noop,
publish: isPublish ? shell.npmPublish.bind(null, options.npm.publishPath, options.npm.tag) : noop
publish: isPublish ? shell.npmPublish.bind(null, options.npm.publishPath, options.npm.tag) : noop,
afterReleaseCommand: options.dist.afterReleaseCommand ? shell.run.bind(null, options.dist.afterReleaseCommand) : noop
});
}

Expand Down

0 comments on commit ba6a05c

Please sign in to comment.