builder/lib/tasks/jsdoc/generateApiIndex.js

  1. const ui5Fs = require("@ui5/fs");
  2. const ReaderCollectionPrioritized = ui5Fs.ReaderCollectionPrioritized;
  3. const fsInterface = ui5Fs.fsInterface;
  4. const apiIndexGenerator = require("../../processors/jsdoc/apiIndexGenerator");
  5. /**
  6. * Compiles an api-index.json resource from all available api.json resources as created by the
  7. * [executeJsdocSdkTransformation]{@link module:@ui5/builder.tasks.executeJsdocSdkTransformation} task.
  8. * The resulting api-index.json resource is mainly to be used in the SDK.
  9. *
  10. * @public
  11. * @alias module:@ui5/builder.tasks.generateApiIndex
  12. * @param {object} parameters Parameters
  13. * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
  14. * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
  15. * @param {object} parameters.options Options
  16. * @param {string} parameters.options.projectName Project name
  17. * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
  18. */
  19. module.exports = async function({
  20. workspace,
  21. dependencies,
  22. options: {projectName}
  23. }) {
  24. const combo = new ReaderCollectionPrioritized({
  25. name: `generateApiIndex - workspace + dependencies: ${projectName}`,
  26. readers: [workspace, dependencies]
  27. });
  28. const versionInfoPath = "/resources/sap-ui-version.json";
  29. const testResourcesRootPath = "/test-resources";
  30. const targetApiIndexPath = "/docs/api/api-index.json";
  31. const targetApiIndexDeprecatedPath = "/docs/api/api-index-deprecated.json";
  32. const targetApiIndexExperimentalPath = "/docs/api/api-index-experimental.json";
  33. const targetApiIndexSincePath = "/docs/api/api-index-since.json";
  34. const createdResources = await apiIndexGenerator({
  35. versionInfoPath,
  36. testResourcesRootPath,
  37. targetApiIndexPath,
  38. targetApiIndexDeprecatedPath,
  39. targetApiIndexExperimentalPath,
  40. targetApiIndexSincePath,
  41. fs: fsInterface(combo),
  42. });
  43. await Promise.all(createdResources.map((resource) => {
  44. return workspace.write(resource);
  45. }));
  46. };