@atlassian/wrm-troubleshooting
Version:
A tool that can help you with troubleshooting the configuration of webpack and Atlassian P2 project.
42 lines • 1.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseXmlContent = void 0;
exports.parseXmlFromFile = parseXmlFromFile;
const chalk_1 = __importDefault(require("chalk"));
const fast_xml_parser_1 = require("fast-xml-parser");
const fs_1 = require("fs");
const paths_1 = require("./paths");
const readFileContent = (filePath) => {
return fs_1.promises.readFile(filePath, { encoding: 'utf8' });
};
const parseXmlContent = (xmlContent) => {
const xmlParseOptions = {
arrayMode: true,
ignoreAttributes: false,
attrNodeName: 'attrs',
attributeNamePrefix: '',
};
let root;
try {
root = (0, fast_xml_parser_1.parse)(xmlContent, xmlParseOptions);
}
catch (error) {
return new Error(`Can't parse the XML content`);
}
return root;
};
exports.parseXmlContent = parseXmlContent;
async function parseXmlFromFile(filePath) {
let xmlContent;
try {
xmlContent = await readFileContent(filePath);
}
catch (e) {
return new Error(`Can't read the content of "${chalk_1.default.green((0, paths_1.getRelativePath)(filePath))}"`);
}
return (0, exports.parseXmlContent)(xmlContent);
}
//# sourceMappingURL=xmlParser.js.map