chcpConfigXmlReader.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Helper class to read plugin-specific options from the config.xml.
  3. */
  4. var fs = require('fs');
  5. var path = require('path');
  6. var xmlHelper = require('./xmlHelper.js');
  7. var cordovaContext;
  8. var projectRoot;
  9. module.exports = {
  10. readOptions: readOptions
  11. };
  12. // region Public API
  13. /**
  14. * Read plugin options from config.xml.
  15. * If none is specified - default options are returned.
  16. *
  17. * @param {Object} ctx - cordova context object
  18. * @return {Object} plugin prefereces
  19. */
  20. function readOptions(ctx) {
  21. var configFilePath = path.join(ctx.opts.projectRoot, 'config.xml');
  22. var configXmlContent = xmlHelper.readXmlAsJson(configFilePath, true);
  23. return parseConfig(configXmlContent);
  24. }
  25. // endregion
  26. // region Private API
  27. /**
  28. * Retrieve plugin preferences from the config.xml content.
  29. *
  30. * @param {Object} configXmlContent - config.xml content as JSON object
  31. * @return {Object} plugin preferences
  32. */
  33. function parseConfig(configXmlContent) {
  34. if (!configXmlContent.chcp) {
  35. return {};
  36. }
  37. return configXmlContent.chcp;
  38. }
  39. // endregion