Skip to content

Commit

Permalink
Show GitHub and npm urls (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
nidkil authored and webpro committed Dec 19, 2018
1 parent 914044e commit cef3566
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/npm.js
Expand Up @@ -4,6 +4,10 @@ const { run } = require('./shell');
const { warn } = require('./log');
const { config } = require('./config');

const getPackageUrl = packageName => {
return 'https://www.npmjs.com/package/' + packageName;
}

const getTag = () => {
const tag = _.get(config, 'cliArguments.npm.tag');
if (tag) return tag;
Expand Down Expand Up @@ -35,5 +39,6 @@ const publish = (options, pkgName, otpPrompt) => {

module.exports = {
getTag,
publish
publish,
getPackageUrl
};
21 changes: 19 additions & 2 deletions lib/tasks.js
Expand Up @@ -2,7 +2,7 @@ const { EOL } = require('os');
const repoPathParse = require('parse-repo');
const _ = require('lodash');
const { bump, runTemplateCommand: run, pushd, copy, popd, isSubDir } = require('./shell');
const { getTag, publish: npmPublish } = require('./npm');
const { getPackageUrl, getTag, publish: npmPublish } = require('./npm');
const Git = require('./git');
const githubClient = require('./github-client');
const semver = require('semver');
Expand All @@ -11,7 +11,7 @@ const { format, truncateLines } = require('./util');
const { parse: parseVersion } = require('./version');
const { getIsLateChangeLog } = require('./recommendations');
const { config } = require('./config');
const { info, warn, logError } = require('./log');
const { log, info, warn, logError } = require('./log');
const { debug, debugConfig } = require('./debug');
const { spinner, getSpinner } = require('./spinner');
const handleDeprecated = require('./deprecated');
Expand All @@ -25,6 +25,11 @@ const {
InvalidVersionError
} = require('./errors');

const getGithubHtmlUrl = releaseInfo => {
// releaseInfo is no initialized during a dry-run, so we need a fallback
return releaseInfo && releaseInfo.html_url ? releaseInfo.html_url : config.options.repo.remote;
}

const validateRepoState = async options => {
const { github, git, dist } = options;
const { requireCleanWorkingDir, requireUpstream } = git;
Expand Down Expand Up @@ -179,12 +184,14 @@ module.exports = async options => {
const uploadAssets = release => githubClient.uploadAssets({ release, repo, github });
const otpPrompt = task => prompt(true, 'src', 'otp', task);
const publish = () => npmPublish(npm, options.name, isInteractive && otpPrompt);
let githubHtmlUrl = null;

if (!isInteractive) {
await spinner(git.commit, commit, 'Git commit');
await spinner(git.tag, tag, 'Git tag');
await spinner(git.push, push, 'Git push');
const releaseInfo = await spinner(github.release, release, 'GitHub release');
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
await spinner(github.assets && releaseInfo, () => uploadAssets(releaseInfo), 'GitHub upload assets');
if (!npm.private) {
await spinner(npm.publish, publish, 'npm publish');
Expand All @@ -195,6 +202,7 @@ module.exports = async options => {
await prompt(git.push, 'src', 'push', push);
await prompt(github.release, 'src', 'release', async () => {
const releaseInfo = await release();
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
return github.assets && releaseInfo && (await uploadAssets(releaseInfo));
});
if (!npm.private) {
Expand Down Expand Up @@ -251,6 +259,7 @@ module.exports = async options => {
await spinner(shouldTag, tag, 'Git tag');
await spinner(git.push, push, 'Git push');
const releaseInfo = await spinner(github.release, release, 'GitHub release');
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
await spinner(github.assets && releaseInfo, () => uploadAssets(releaseInfo), 'GitHub upload assets');
await spinner(npm.publish, publish, 'npm publish');
} else {
Expand All @@ -260,6 +269,7 @@ module.exports = async options => {
await prompt(git.push, 'dist', 'push', push);
await prompt(github.release, 'dist', 'release', async () => {
const releaseInfo = await release();
githubHtmlUrl = getGithubHtmlUrl(releaseInfo);
return github.assets && releaseInfo && (await uploadAssets(releaseInfo));
});
await prompt(npm.publish, 'dist', 'publish', publish);
Expand All @@ -271,6 +281,13 @@ module.exports = async options => {
await run(`!rm -rf ${dist.stageDir}`);
}

if (github.release) {
log(`πŸ”— ${githubHtmlUrl}`);
}
if (npm.publish) {
log(`πŸ”— ${getPackageUrl()}`);
}

getSpinner().stopAndPersist({
symbol: `🏁`,
text: `Done (in ${Math.floor(process.uptime())}s.)`
Expand Down
7 changes: 6 additions & 1 deletion test/npm.js
@@ -1,13 +1,18 @@
const test = require('tape');
const proxyquire = require('proxyquire');
const { Config } = require('../lib/config');
const { getTag } = require('../lib/npm');
const { getPackageUrl, getTag } = require('../lib/npm');

const getMock = config =>
proxyquire('../lib/npm', {
'./config': { config }
});

test('getPackageUrl', t => {
t.equal(getPackageUrl('my-cool-package'), 'https://www.npmjs.com/package/my-cool-package');
t.end();
});

test('getTag', t => {
t.equal(getTag(), 'latest');
t.end();
Expand Down

0 comments on commit cef3566

Please sign in to comment.