UI for Zipcoin Blue

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const path = require("path");
  5. const chalk_1 = require("chalk");
  6. function upload(env, { note, channelTag, metadata }) {
  7. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  8. const { createArchive } = yield Promise.resolve().then(() => require('./utils/archive'));
  9. const { DeployClient } = yield Promise.resolve().then(() => require('./deploy'));
  10. let channel;
  11. const token = yield env.session.getAppUserToken();
  12. const deploy = new DeployClient(token, env.client);
  13. if (channelTag) {
  14. env.tasks.next('Retrieving deploy channel');
  15. channel = yield deploy.getChannel(channelTag);
  16. }
  17. const wwwPath = path.join(env.project.directory, 'www'); // TODO don't hardcode
  18. const zip = yield createArchive('zip');
  19. zip.directory(wwwPath, '/');
  20. zip.finalize();
  21. env.tasks.next('Requesting snapshot upload');
  22. const snapshot = yield deploy.requestSnapshotUpload({ note, user_metadata: metadata });
  23. const uploadTask = env.tasks.next('Uploading snapshot');
  24. yield deploy.uploadSnapshot(snapshot, zip, (loaded, total) => {
  25. uploadTask.progress(loaded, total);
  26. });
  27. env.tasks.end();
  28. env.log.ok(`Uploaded snapshot ${chalk_1.default.bold(snapshot.uuid)}!`);
  29. if (channel) {
  30. env.tasks.next(`Deploying to '${channel.tag}' channel`);
  31. yield deploy.deploy(snapshot.uuid, channel.uuid);
  32. env.tasks.end();
  33. env.log.ok(`Deployed snapshot ${chalk_1.default.bold(snapshot.uuid)} to channel ${chalk_1.default.bold(channel.tag)}!`);
  34. }
  35. return snapshot;
  36. });
  37. }
  38. exports.upload = upload;