Skip to content

Commit

Permalink
✨ Explicit tag name with --tag-name (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush authored and omrilotan committed Jan 1, 2019
1 parent 333799f commit 12cf0b1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ npx published
| on-publish | Execute shell command after a publish event | `npx published --on-publish bash\ ./do-more.sh`
| on-<tag> | Execute shell command after a publish event with this tag (executes after on-publish) | `npx published --on-latest 'echo "Published!"'`
| latest-branch | Branch that is considered latest (default is 'master') | `npx published --latest-branch stable`
| tag-name | Tag name to be used regardless of config. If performed from a branch other than `master`, needs to be used in conjunction with `latest-branch` option | `npx published --tag-name next --latest-branch next`

## TL;DR
| Branch type | action |
Expand Down
4 changes: 3 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const publish = require('./publish');
* @param {Boolean} [options.quiet]
* @param {Boolean} [options.shouldGitTag]
* @param {Boolean} [options.testing]
* @param {String} [options.tagName]
* @return {void}
*/
module.exports = async function({slack = {}, quiet, shouldGitTag, testing, latestBranch} = {}) {
module.exports = async function({slack = {}, quiet, shouldGitTag, testing, latestBranch, tagName} = {}) {
const narrate = testing || (quiet !== true);
let result = null;

Expand All @@ -25,6 +26,7 @@ module.exports = async function({slack = {}, quiet, shouldGitTag, testing, lates
testing,
shouldGitTag,
latestBranch,
tagName,
});

const {
Expand Down
5 changes: 3 additions & 2 deletions app/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const {
* @param {Boolean} [options.testing]
* @param {Boolean} [options.shouldGitTag]
* @param {String} [options.latestBranch]
* @param {String} [options.tagName]
* @return {Object} details of the publishing event
*/
module.exports = async function({testing, shouldGitTag, latestBranch}) {
module.exports = async function({testing, shouldGitTag, latestBranch, tagName}) {
testing && console.log('Testing only, will not publish');

const [
Expand Down Expand Up @@ -61,7 +62,7 @@ module.exports = async function({testing, shouldGitTag, latestBranch}) {

const suffix = onLatestBranch ? '' : `-${short}`;
const fullVersion = `${version}${suffix}`;
const tag = getTag(branch, publishConfig.tag);
const tag = tagName || getTag(branch, publishConfig.tag);
const exist = await exists(name, fullVersion);
let action = publish;
let cliMsg = `Published version ${fullVersion}`;
Expand Down
10 changes: 10 additions & 0 deletions app/publish/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ describe('publish', async() => {
expect(result.message.toLowerCase()).to.contain('set tag');
});

it('Should change tag if tagName specified', async() => {
NPM_FUNCTIONS.exists = () => true;
NPM_FUNCTIONS.publish = () => {};
NPM_FUNCTIONS.setTag = (pkg, version, tag) => expect(tag).to.equal('next');

const publish = require('.');
const result = await publish({...OPTIONS, tagName: 'next'});
expect(result.details.tag).to.equal('next');
});

it('Should change tag if publishConfig tag does not point to it', async() => {
GIT_DETAILS.branch = 'master';
PKG_DETAILS.version = '1.0.0';
Expand Down
1 change: 1 addition & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (!slack.webhook && process.env.SLACK_WEBHOOK) {
testing: truthy(argv.testing) || _.includes('testing'),
shouldGitTag: truthy(argv.gitTag),
latestBranch: argv.latestBranch,
tagName: argv.tagName,
});
const {published, tag} = details;
const {onPublish} = argv;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "published",
"version": "1.5.3",
"version": "1.6.0",
"description": "Opinionated NPM publish program",
"keywords": [
"npm",
Expand Down

0 comments on commit 12cf0b1

Please # to comment.