UNPKG

@atlassian/wrm-troubleshooting

Version:

A tool that can help you with troubleshooting the configuration of webpack and Atlassian P2 project.

139 lines 7.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.verifyWrmRuntime = void 0; const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt")); const valid_url_1 = __importDefault(require("valid-url")); const applicationUrls_1 = require("../applicationUrls"); const atlassianPluginXml_1 = require("../atlassianPluginXml"); const pom_1 = require("../pom"); const webpackWrmPlugin_1 = require("../webpackWrmPlugin"); const fetchWithTimeout_1 = require("../wrm/fetchWithTimeout"); const wrmRestApi_1 = require("../wrm/wrmRestApi"); const types_1 = require("./types"); inquirer_1.default.registerPrompt('autocomplete', inquirer_autocomplete_prompt_1.default); const verifyWrmRuntime = async (options, payload) => { const { pomFile, pomXml } = payload; // Skip running in-app WRM check if (options.noWrm) { return (0, types_1.getPassedResult)(); } if (!options.yes) { console.log(); console.log(`So far, we haven't found any issues with the ${chalk_1.default.bold(webpackWrmPlugin_1.WRM_PLUGIN_NAME)} webpack plugin or in project configuration.`); console.log(`Additionally, we can check if the generated bundles from webpack can be loaded by the ${chalk_1.default.bold('Web-Resource Manager')} (WRM) in the application runtime.`); console.log(`For that, you will haven to run your project first. You can run the project using "${chalk_1.default.bold('atlas-run')}" command from ${chalk_1.default.bold('Atlassian SDK')}`); console.log('You can read more about this command here: https://developer.atlassian.com/server/framework/atlassian-sdk/atlas-run/'); console.log(); } // Confirm running WRM runtime check if (!options.yes) { const { confirmCheckingWrmRuntime } = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirmCheckingWrmRuntime', message: `Should we verify the WRM runtime now?`, }); if (!confirmCheckingWrmRuntime) { // TODO: Add some message? return (0, types_1.getPassedResult)(); } } console.log('👀 We will run WRM runtime check now. This might take some time...'); let applicationUrl = options.applicationUrl; if (!applicationUrl) { console.log(); console.log('To run WRM runime check, you need to provide a full URL of the running Atlassian Server or DC application like e.g. Jira.'); console.log('If you are using Atlassian SDK you can check the application default ports and paths here:'); console.log('https://developer.atlassian.com/server/framework/atlassian-sdk/working-with-the-sdk/#supported-atlassian-applications-and-default-ports'); console.log(); const OTHER_URL = Symbol('otherUrl'); ({ applicationUrl } = (await inquirer_1.default.prompt({ type: 'list', name: 'applicationUrl', message: `Select the full URL to application you are running or select "other" to type a custom URL:`, choices: [ { name: 'other', value: OTHER_URL, }, new inquirer_1.default.Separator(), ...applicationUrls_1.applicationUrls.map(({ product, defaultUrl }) => ({ name: `${defaultUrl} - ${product}`, value: defaultUrl, })), new inquirer_1.default.Separator(), ], }))); // Let the user type the custom URL if (applicationUrl === OTHER_URL) { const defaultUrl = 'http://localhost:2990/jira'; ({ applicationUrl } = (await inquirer_1.default.prompt({ type: 'input', name: 'applicationUrl', message: `What is the full URL to your running application? E.g ${defaultUrl}`, validate(input) { const isValid = Boolean(input && valid_url_1.default.isWebUri(input)); return isValid ? isValid : 'Provided URL is not valid. Try correcting your answer.'; }, transformer(input) { // Remove "/" from the end return input && input.trim().replace(/\/+$/, ''); }, default: defaultUrl, }))); } } // Get list of generated web-resources const webResourceDefinitions = await (0, atlassianPluginXml_1.getPluginWebResourceDefinitions)(pomFile, pomXml); if (webResourceDefinitions instanceof Error) { return (0, types_1.getFailedResult)(new Error("We couldn't parse the XML of some of web-resources generated by webpack.")); } // TODO: This should be checked after we run webpack bundle if (!webResourceDefinitions.length) { return (0, types_1.getFailedResult)(new Error("We couldn't find any definitions of the web-resources in the XML files generated by webpack.")); } // Call WRM API to get some resources let webResourceKey = options.resourceKey; // TODO: Check if provided web-resource belongs to the resource from generated resources if (!webResourceKey) { ({ webResourceKey } = (await inquirer_1.default.prompt({ // @ts-expect-error We are using inquirer plugin that is causing TS error type: 'autocomplete', name: 'webResourceKey', message: 'Select a web-resource key you want to verify:', source: (answersSoFar, input) => { const userInput = input || ''; return webResourceDefinitions .filter((webResource) => webResource.key.match(new RegExp(userInput, 'i'))) .map((webResource) => ({ name: webResource.key, value: webResource.key, })); }, }))); } // Get full web-resource key const pluginKey = (0, pom_1.getAtlassianPluginKeyFromPom)(pomXml); const fullWebResourceKey = (0, atlassianPluginXml_1.getFullWebResourceKey)(pluginKey, webResourceKey); // TODO: Check if the application is running const webResources = await (0, wrmRestApi_1.fetchWebResources)(applicationUrl, fullWebResourceKey, options.timeout); if (webResources instanceof fetchWithTimeout_1.FetchTimeoutError) { return (0, types_1.getRestTimeoutResult)(wrmRestApi_1.fetchWebResources.name, options.timeout); } if (webResources instanceof Error) { return (0, types_1.getFailedResult)(webResources); } if (webResources.length < 1) { return (0, types_1.getFailedResult)(new Error(`We didn't manage to retrieve any resources for the "${webResourceKey}" web-resource with WRM runtime.`)); } return (0, types_1.getPassedResult)({ webResourceKey, webResources, }); }; exports.verifyWrmRuntime = verifyWrmRuntime; //# sourceMappingURL=verifyWrmRuntime.js.map