Skip to content

Commit

Permalink
Improve preview mode show commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Jan 11, 2020
1 parent 9d79205 commit 1f7285f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
17 changes: 9 additions & 8 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module.exports = async (input = 'patch', options) => {
enabled: () => options.yarn === true,
skip: () => {
if (options.preview) {
return '[Preview] Command not executed: yarn version…';
return `[Preview] Command not executed: yarn version --new-version ${input}.`;
}
},
task: () => exec('yarn', ['version', '--new-version', input])
Expand All @@ -187,7 +187,7 @@ module.exports = async (input = 'patch', options) => {
enabled: () => options.yarn === false,
skip: () => {
if (options.preview) {
return '[Preview] Command not executed npm version…';
return `[Preview] Command not executed: npm version ${input}.`;
}
},
task: () => exec('npm', ['version', input])
Expand All @@ -198,9 +198,10 @@ module.exports = async (input = 'patch', options) => {
tasks.add([
{
title: `Publishing package using ${pkgManagerName}`,
skip: async () => {
skip: () => {
if (options.preview) {
return `[Preview] Command not executed ${pkgManager} publish…`;
const args = publish.pkgPublish(pkgManager, options);
return `[Preview] Command not executed: ${pkgManager} ${args} …`;
}
},
task: (context, task) => {
Expand Down Expand Up @@ -228,7 +229,7 @@ module.exports = async (input = 'patch', options) => {
title: 'Enabling two-factor authentication',
skip: () => {
if (options.preview) {
return '[Preview] Command not executed npm access 2fa-required…';
return `[Preview] Command not executed: npm access 2fa-required ${pkg.name} --opt …`;
}
},
task: (context, task) => enable2fa(task, pkg.name, {otp: context.otp})
Expand All @@ -247,11 +248,11 @@ module.exports = async (input = 'patch', options) => {
}

if (options.preview) {
return '[Preview] Command not executed git push';
return '[Preview] Command not executed git push --follow-tags.';
}

if (publishStatus === 'FAILED' && runPublish) {
return 'Couldn\'t publish package to npm; not pushing.';
return 'Couldn\'t publish package to npm: not pushing.';
}
},
task: () => git.push()
Expand All @@ -262,7 +263,7 @@ module.exports = async (input = 'patch', options) => {
enabled: () => isOnGitHub === true,
skip: () => {
if (options.preview) {
return 'GitHub Releases draft not opened in preview mode.';
return '[Preview] GitHub Releases draft will not be opened in preview mode.';
}

return !options.releaseDraft;
Expand Down
6 changes: 6 additions & 0 deletions source/npm/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const pkgPublish = (pkgManager, options) => {
args.push('--access', 'public');
}

if (options.preview) {
return args;
}

return execa(pkgManager, args);
};

Expand All @@ -34,3 +38,5 @@ module.exports = (context, pkgManager, task, options) =>
return pkgPublish(pkgManager, {...options, otp});
}))
);

module.exports.pkgPublish = pkgPublish;
11 changes: 5 additions & 6 deletions source/npm/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,12 @@ exports.checkIgnoreStrategy = ({files}) => {
}
};

exports.registry = async (pkgManager, pkg) => {
exports.getRegistryUrl = async (pkgManager, pkg) => {
const args = ['config', 'get', 'registry'];
const isExternalRegistry = exports.isExternalRegistry(pkg);

const externalRegistry = isExternalRegistry ? pkg.publishConfig.registry : false;
if (externalRegistry) {
args.push('--registry', externalRegistry);
if (exports.isExternalRegistry(pkg)) {
args.push({
registryUrl: pkg.publishConfig.registry
});
}

const {stdout} = await execa(pkgManager, args);
Expand Down
4 changes: 2 additions & 2 deletions source/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const githubUrlFromGit = require('github-url-from-git');
const isScoped = require('is-scoped');
const util = require('./util');
const git = require('./git-util');
const {prereleaseTags, checkIgnoreStrategy, registry} = require('./npm/util');
const {prereleaseTags, checkIgnoreStrategy, getRegistryUrl} = require('./npm/util');
const version = require('./version');
const prettyVersionDiff = require('./pretty-version-diff');

Expand Down Expand Up @@ -53,7 +53,7 @@ module.exports = async (options, pkg) => {
const oldVersion = pkg.version;
const extraBaseUrls = ['gitlab.com'];
const repoUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls});
const registryUrl = await registry(options.yarn ? 'yarn' : 'npm', pkg);
const registryUrl = await getRegistryUrl(options.yarn ? 'yarn' : 'npm', pkg);
const runPublish = options.publish && !pkg.private;

if (runPublish) {
Expand Down

0 comments on commit 1f7285f

Please sign in to comment.