UNPKG

@atlassian/wrm-troubleshooting

Version:

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

69 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFullWebResourceKey = exports.removeOldModuleDescriptors = exports.getGeneratedModuleDescriptorPaths = exports.getPluginWebResourceDefinitions = void 0; const fs_1 = require("fs"); const globWithOptions_1 = require("./globWithOptions"); const pom_1 = require("./pom"); const xmlParser_1 = require("./xmlParser"); async function getPluginWebResourceDefinitions(pomFile, pomXml) { const generatedXmlPaths = await getGeneratedModuleDescriptorPaths(pomFile, pomXml); const wrmWebResources = []; for (const xmlFile of generatedXmlPaths) { const webResources = await getWebResourcesFromFile(xmlFile); if (webResources instanceof Error) { return webResources; } wrmWebResources.push(...webResources); } return wrmWebResources.sort((a, b) => a.key.localeCompare(b.key)); } exports.getPluginWebResourceDefinitions = getPluginWebResourceDefinitions; const WEB_RESOURCE_XML_KEY = 'web-resource'; async function getWebResourcesFromFile(xmlFile) { const xml = await (0, xmlParser_1.parseXmlFromFile)(xmlFile); if (xml instanceof Error) { return xml; } const rootKey = Object.keys(xml)[0]; const project = xml[rootKey][0]; if (!(WEB_RESOURCE_XML_KEY in project)) { return []; } const webResourcesXml = project[WEB_RESOURCE_XML_KEY]; return webResourcesXml.map((webResourceXml) => { const webResource = { key: webResourceXml.attrs.key, }; return webResource; }); } async function getGeneratedModuleDescriptorPaths(pomFile, pomXml) { const pomScanFolders = (0, pom_1.getAbsoluteScanFoldersConfig)(pomXml, pomFile); return getXmlFilesFromDirectory(pomScanFolders); } exports.getGeneratedModuleDescriptorPaths = getGeneratedModuleDescriptorPaths; async function removeOldModuleDescriptors(pomFile, pomXml) { const generatedXmlPaths = await getGeneratedModuleDescriptorPaths(pomFile, pomXml); // Delete files in parallel await Promise.all(generatedXmlPaths.map((filePath) => silentlyDeleteFile(filePath))); } exports.removeOldModuleDescriptors = removeOldModuleDescriptors; async function silentlyDeleteFile(filePath) { try { await fs_1.promises.unlink(filePath); } catch (e) { // gracefully skip the error } } async function getXmlFilesFromDirectory(directory) { return await (0, globWithOptions_1.globWithOptions)('**/*.xml', { cwd: directory, ignore: [], // Remove default ignored directories so we can scan within "target" directory }); } function getFullWebResourceKey(pluginKey, webResourceKey) { return `${pluginKey}:${webResourceKey}`; } exports.getFullWebResourceKey = getFullWebResourceKey; //# sourceMappingURL=atlassianPluginXml.js.map