publishOptions.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.githubUrl = githubUrl;
  6. exports.getS3LikeProviderBaseUrl = getS3LikeProviderBaseUrl;
  7. /** @private */
  8. function githubUrl(options, defaultHost = "github.com") {
  9. return `${options.protocol || "https"}://${options.host || defaultHost}`;
  10. }
  11. function getS3LikeProviderBaseUrl(configuration) {
  12. const provider = configuration.provider;
  13. if (provider === "s3") {
  14. return s3Url(configuration);
  15. }
  16. if (provider === "spaces") {
  17. return spacesUrl(configuration);
  18. }
  19. throw new Error(`Not supported provider: ${provider}`);
  20. }
  21. function s3Url(options) {
  22. let url;
  23. if (options.endpoint != null) {
  24. url = `${options.endpoint}/${options.bucket}`;
  25. } else {
  26. if (!options.bucket.includes(".")) {
  27. if (options.region === "cn-north-1") {
  28. url = `https://${options.bucket}.s3.${options.region}.amazonaws.com.cn`;
  29. } else {
  30. url = `https://${options.bucket}.s3.amazonaws.com`;
  31. }
  32. } else {
  33. if (options.region == null) {
  34. throw new Error(`Bucket name "${options.bucket}" includes a dot, but S3 region is missing`);
  35. } // special case, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
  36. url = options.region === "us-east-1" ? `https://s3.amazonaws.com/${options.bucket}` : `https://s3-${options.region}.amazonaws.com/${options.bucket}`;
  37. }
  38. }
  39. if (options.path != null) {
  40. url += `/${options.path}`;
  41. }
  42. return url;
  43. }
  44. function spacesUrl(options) {
  45. if (options.name == null) {
  46. throw new Error(`name is missing`);
  47. }
  48. if (options.region == null) {
  49. throw new Error(`region is missing`);
  50. }
  51. let url = `https://${options.name}.${options.region}.digitaloceanspaces.com`;
  52. if (options.path != null) {
  53. url += `/${options.path}`;
  54. }
  55. return url;
  56. }
  57. //# sourceMappingURL=publishOptions.js.map