builder/lib/processors/jsdoc/apiIndexGenerator.js

  1. const resourceFactory = require("@ui5/fs").resourceFactory;
  2. const createIndex = require("./lib/createIndexFiles");
  3. /**
  4. * Compiles API index resources from all <code>api.json</code> resources available in the given test resources directory
  5. * as created by the [sdkTransformer]{@link module:@ui5/builder.processors.sdkTransformer} processor.
  6. * The resulting index resources (e.g. <code>api-index.json</code>, <code>api-index-deprecated.json</code>,
  7. * <code>api-index-experimental.json</code> and <code>api-index-since.json</code>) are mainly to be used in the SDK.
  8. *
  9. * @public
  10. * @alias module:@ui5/builder.processors.apiIndexGenerator
  11. * @param {object} parameters Parameters
  12. * @param {string} parameters.versionInfoPath Path to <code>sap-ui-version.json</code> resource
  13. * @param {string} parameters.testResourcesRootPath Path to <code>/test-resources</code> root directory in the
  14. * given fs
  15. * @param {string} parameters.targetApiIndexPath Path to create the generated API index JSON resource for
  16. * @param {string} parameters.targetApiIndexDeprecatedPath Path to create the generated API index "deprecated" JSON
  17. * resource for
  18. * @param {string} parameters.targetApiIndexExperimentalPath Path to create the generated API index "experimental" JSON
  19. * resource for
  20. * @param {string} parameters.targetApiIndexSincePath Path to create the generated API index "since" JSON resource for
  21. * @param {fs|module:@ui5/fs.fsInterface} parameters.fs Node fs or
  22. * custom [fs interface]{@link module:resources/module:@ui5/fs.fsInterface} to use
  23. * @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with created resources <code>api-index.json</code>,
  24. * <code>api-index-deprecated.json</code>, <code>api-index-experimental.json</code> and
  25. * <code>api-index-since.json</code> (names depend on the supplied paths)
  26. */
  27. const apiIndexGenerator = async function({
  28. versionInfoPath, testResourcesRootPath, targetApiIndexPath, targetApiIndexDeprecatedPath,
  29. targetApiIndexExperimentalPath, targetApiIndexSincePath, fs
  30. } = {}) {
  31. if (!versionInfoPath || !testResourcesRootPath || !targetApiIndexPath || !targetApiIndexDeprecatedPath ||
  32. !targetApiIndexExperimentalPath || !targetApiIndexSincePath || !fs) {
  33. throw new Error("[apiIndexGenerator]: One or more mandatory parameters not provided");
  34. }
  35. const resourceMap = await createIndex(versionInfoPath, testResourcesRootPath, targetApiIndexPath,
  36. targetApiIndexDeprecatedPath, targetApiIndexExperimentalPath, targetApiIndexSincePath, {
  37. fs,
  38. returnOutputFiles: true
  39. });
  40. return Object.keys(resourceMap).map((resPath) => {
  41. return resourceFactory.createResource({
  42. path: resPath,
  43. string: resourceMap[resPath]
  44. });
  45. });
  46. };
  47. module.exports = apiIndexGenerator;