BaseS3Publisher.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BaseS3Publisher = void 0;
  4. const builder_util_1 = require("builder-util");
  5. const electron_publish_1 = require("electron-publish");
  6. const promises_1 = require("fs/promises");
  7. const path = require("path");
  8. class BaseS3Publisher extends electron_publish_1.Publisher {
  9. constructor(context, options) {
  10. super(context);
  11. this.options = options;
  12. }
  13. configureS3Options(args) {
  14. // if explicitly set to null, do not add
  15. if (this.options.acl !== null) {
  16. args.push("--acl", this.options.acl || "public-read");
  17. }
  18. }
  19. // http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html
  20. async upload(task) {
  21. const fileName = path.basename(task.file);
  22. const cancellationToken = this.context.cancellationToken;
  23. const target = (this.options.path == null ? "" : `${this.options.path}/`) + fileName;
  24. const args = ["publish-s3", "--bucket", this.getBucketName(), "--key", target, "--file", task.file];
  25. this.configureS3Options(args);
  26. if (process.env.__TEST_S3_PUBLISHER__ != null) {
  27. const testFile = path.join(process.env.__TEST_S3_PUBLISHER__, target);
  28. await (0, promises_1.mkdir)(path.dirname(testFile), { recursive: true });
  29. await (0, promises_1.symlink)(task.file, testFile);
  30. return;
  31. }
  32. // https://github.com/aws/aws-sdk-go/issues/279
  33. this.createProgressBar(fileName, -1);
  34. // if (progressBar != null) {
  35. // const callback = new ProgressCallback(progressBar)
  36. // uploader.on("progress", () => {
  37. // if (!cancellationToken.cancelled) {
  38. // callback.update(uploader.loaded, uploader.contentLength)
  39. // }
  40. // })
  41. // }
  42. return await cancellationToken.createPromise((resolve, reject, onCancel) => {
  43. (0, builder_util_1.executeAppBuilder)(args, process => {
  44. onCancel(() => {
  45. process.kill("SIGINT");
  46. });
  47. })
  48. .then(() => {
  49. try {
  50. builder_util_1.log.debug({ provider: this.providerName, file: fileName, bucket: this.getBucketName() }, "uploaded");
  51. }
  52. finally {
  53. resolve(undefined);
  54. }
  55. })
  56. .catch(reject);
  57. });
  58. }
  59. toString() {
  60. return `${this.providerName} (bucket: ${this.getBucketName()})`;
  61. }
  62. }
  63. exports.BaseS3Publisher = BaseS3Publisher;
  64. //# sourceMappingURL=BaseS3Publisher.js.map