You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

11 months ago
  1. /**
  2. * Dynamically load the correct repository loader from a specific platform
  3. * by default will return GitHub.
  4. * @param {('github'|'gitlab')} platform
  5. * @returns {import("./GithubRepo/RepoLoader")|import("./GitlabRepo/RepoLoader")} the repo loader class for provider
  6. */
  7. function resolveRepoLoader(platform = "github") {
  8. switch (platform) {
  9. case "github":
  10. console.log(`Loading GitHub RepoLoader...`);
  11. return require("./GithubRepo/RepoLoader");
  12. case "gitlab":
  13. console.log(`Loading GitLab RepoLoader...`);
  14. return require("./GitlabRepo/RepoLoader");
  15. default:
  16. console.log(`Loading GitHub RepoLoader...`);
  17. return require("./GithubRepo/RepoLoader");
  18. }
  19. }
  20. /**
  21. * Dynamically load the correct repository loader function from a specific platform
  22. * by default will return Github.
  23. * @param {('github'|'gitlab')} platform
  24. * @returns {import("./GithubRepo")['fetchGithubFile'] | import("./GitlabRepo")['fetchGitlabFile']} the repo loader class for provider
  25. */
  26. function resolveRepoLoaderFunction(platform = "github") {
  27. switch (platform) {
  28. case "github":
  29. console.log(`Loading GitHub loader function...`);
  30. return require("./GithubRepo").loadGithubRepo;
  31. case "gitlab":
  32. console.log(`Loading GitLab loader function...`);
  33. return require("./GitlabRepo").loadGitlabRepo;
  34. default:
  35. console.log(`Loading GitHub loader function...`);
  36. return require("./GithubRepo").loadGithubRepo;
  37. }
  38. }
  39. module.exports = { resolveRepoLoader, resolveRepoLoaderFunction };