From 1f7285f1b073a580d1974221a33c04821e3d5bdd Mon Sep 17 00:00:00 2001 From: TiagoDanin Date: Sat, 11 Jan 2020 09:57:27 -0300 Subject: [PATCH] Improve preview mode show commands --- source/index.js | 17 +++++++++-------- source/npm/publish.js | 6 ++++++ source/npm/util.js | 11 +++++------ source/ui.js | 4 ++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/source/index.js b/source/index.js index 8bb291ed..a68bf2d8 100644 --- a/source/index.js +++ b/source/index.js @@ -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]) @@ -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]) @@ -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) => { @@ -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}) @@ -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() @@ -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; diff --git a/source/npm/publish.js b/source/npm/publish.js index 57e0d636..101e1d5c 100644 --- a/source/npm/publish.js +++ b/source/npm/publish.js @@ -23,6 +23,10 @@ const pkgPublish = (pkgManager, options) => { args.push('--access', 'public'); } + if (options.preview) { + return args; + } + return execa(pkgManager, args); }; @@ -34,3 +38,5 @@ module.exports = (context, pkgManager, task, options) => return pkgPublish(pkgManager, {...options, otp}); })) ); + +module.exports.pkgPublish = pkgPublish; diff --git a/source/npm/util.js b/source/npm/util.js index f272e6d2..3b506a32 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -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); diff --git a/source/ui.js b/source/ui.js index e02682be..69a18cde 100644 --- a/source/ui.js +++ b/source/ui.js @@ -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'); @@ -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) {