From 79ec5913698c3b1b6697baa7820ee590d2a35fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serta=C3=A7=20Karahoda?= Date: Tue, 16 Nov 2021 12:18:11 +0300 Subject: [PATCH] Add verbose flag to publish command --- src/commands/publish/apiClient.js | 10 ++++++++-- src/commands/publish/index.js | 7 +++++-- src/index.js | 7 ++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/commands/publish/apiClient.js b/src/commands/publish/apiClient.js index 92c9b76..80d2bb6 100644 --- a/src/commands/publish/apiClient.js +++ b/src/commands/publish/apiClient.js @@ -6,8 +6,14 @@ const { apiBaseUrl, apiClientId } = require("../../config/constants"); const { ClientError, ServerError } = require("../../errors"); function createError(response) { - const { statusCode, body } = response; - const extra = { response: response.toJSON() }; + const { statusCode, body, headers } = response; + const extra = { + response: { + statusCode, + body, + headers + } + }; if (statusCode >= BAD_REQUEST && statusCode < INTERNAL_SERVER_ERROR) { const { message, title } = body; diff --git a/src/commands/publish/index.js b/src/commands/publish/index.js index 1d4d90c..cba0c8f 100644 --- a/src/commands/publish/index.js +++ b/src/commands/publish/index.js @@ -95,7 +95,7 @@ async function validateReadme({ hasOptions }) { } } -module.exports = async function (buildPath) { +module.exports = async function ({ buildPath, verbose }) { console.log("Publishing the extension...\n"); pathResolver.init(buildPath); @@ -140,6 +140,9 @@ module.exports = async function (buildPath) { } catch (error) { console.log(chalk.red("Publishing extension failed:")); console.error(error.message || error); + if (verbose && error.extra) { + console.error(JSON.stringify(error.extra, null, 2)); + } throw error; } -}; \ No newline at end of file +}; diff --git a/src/index.js b/src/index.js index 5e25ace..bc78b8f 100755 --- a/src/index.js +++ b/src/index.js @@ -93,10 +93,11 @@ program .command("publish") .description(`Publish extension, submitting it for review to be listed on ${chalk.underline("https://extensions.zeplin.io.")}`) .option("--path ", `Path for the extension build to be published`) - .action(async command => { + .option("--verbose", "Enables verbose logs") + .action(async ({ path: buildPath, verbose }) => { const publish = require("./commands/publish"); try { - await publish(command.path); + await publish({ buildPath, verbose }); } catch (_) { process.exitCode = 1; } @@ -117,4 +118,4 @@ program.on("command:*", () => { }); beforeCommand(); -program.parse(process.argv); \ No newline at end of file +program.parse(process.argv);