builder/lib/processors/jsdoc/sdkTransformer.js

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