builder/lib/processors/jsdoc/sdkTransformer.js

  1. import {createResource} from "@ui5/fs/resourceFactory";
  2. import transformer from "./lib/transformApiJson.cjs";
  3. /**
  4. * @public
  5. * @module @ui5/builder/processors/jsdoc/sdkTransformer
  6. */
  7. /**
  8. * Transform api.json as created by [jsdocGenerator]{@link @ui5/builder/processors/jsdoc/jsdocGenerator}
  9. * for usage in a UI5 SDK
  10. *
  11. * @public
  12. * @function default
  13. * @static
  14. *
  15. * @param {object} parameters Parameters
  16. * @param {string} parameters.apiJsonPath Path to the projects api.json file as created by
  17. * [jsdocGenerator]{@link @ui5/builder/processors/jsdoc/jsdocGenerator}
  18. * @param {string} parameters.dotLibraryPath Path to the projects .library file
  19. * @param {string[]} parameters.dependencyApiJsonPaths List of paths to the api.json files of all dependencies of
  20. * the project as created by [jsdocGenerator]{@link @ui5/builder/processors/jsdoc/jsdocGenerator}
  21. * @param {string} parameters.targetApiJsonPath Path to create the new, transformed api.json resource for
  22. * @param {fs|module:@ui5/fs/fsInterface} parameters.fs Node fs or
  23. * custom [fs interface]{@link module:@ui5/fs/fsInterface} to use
  24. *
  25. * @returns {Promise<@ui5/fs/Resource[]>} Promise resolving with created resources
  26. */
  27. const sdkTransformer = async function({
  28. apiJsonPath, dotLibraryPath, dependencyApiJsonPaths, targetApiJsonPath, fs} = {}
  29. ) {
  30. if (!apiJsonPath || !dotLibraryPath || !targetApiJsonPath || !dependencyApiJsonPaths || !fs) {
  31. throw new Error("[sdkTransformer]: One or more mandatory parameters not provided");
  32. }
  33. const fakeTargetPath = "/ignore/this/path/resource/will/be/returned";
  34. const apiJsonContent = await transformer(apiJsonPath, fakeTargetPath, dotLibraryPath, dependencyApiJsonPaths, "", {
  35. fs,
  36. returnOutputFiles: true
  37. });
  38. return [createResource({
  39. path: targetApiJsonPath,
  40. string: apiJsonContent
  41. })];
  42. };
  43. export default sdkTransformer;