123456789101112131415161718192021222324252627282930313233343536373839 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const tslib_1 = require("tslib");
- const path = require("path");
- const chalk_1 = require("chalk");
- function upload(env, { note, channelTag, metadata }) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { createArchive } = yield Promise.resolve().then(() => require('./utils/archive'));
- const { DeployClient } = yield Promise.resolve().then(() => require('./deploy'));
- let channel;
- const token = yield env.session.getAppUserToken();
- const deploy = new DeployClient(token, env.client);
- if (channelTag) {
- env.tasks.next('Retrieving deploy channel');
- channel = yield deploy.getChannel(channelTag);
- }
- const wwwPath = path.join(env.project.directory, 'www'); // TODO don't hardcode
- const zip = yield createArchive('zip');
- zip.directory(wwwPath, '/');
- zip.finalize();
- env.tasks.next('Requesting snapshot upload');
- const snapshot = yield deploy.requestSnapshotUpload({ note, user_metadata: metadata });
- const uploadTask = env.tasks.next('Uploading snapshot');
- yield deploy.uploadSnapshot(snapshot, zip, (loaded, total) => {
- uploadTask.progress(loaded, total);
- });
- env.tasks.end();
- env.log.ok(`Uploaded snapshot ${chalk_1.default.bold(snapshot.uuid)}!`);
- if (channel) {
- env.tasks.next(`Deploying to '${channel.tag}' channel`);
- yield deploy.deploy(snapshot.uuid, channel.uuid);
- env.tasks.end();
- env.log.ok(`Deployed snapshot ${chalk_1.default.bold(snapshot.uuid)} to channel ${chalk_1.default.bold(channel.tag)}!`);
- }
- return snapshot;
- });
- }
- exports.upload = upload;
|