UNPKG

@amplitude/ampli

Version:

Amplitude CLI

41 lines (40 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = require("chalk"); const base_1 = require("./base"); const components_1 = require("../components"); const errors_1 = require("../errors"); const types_1 = require("../types"); const { bold } = chalk_1.default; class SetupAction extends base_1.default { async run() { var _a; const settings = this.getSettings(); const orgId = settings.getOrgId(); const workspaceId = settings.getWorkspaceId(); const branchName = settings.getBranch(); const sourceId = settings.getSourceId(); const codegenDir = settings.getPath(); if (!sourceId) { this.error(new errors_1.UserFixableError(`Nothing to setup yet. Run ${bold('ampli pull')} to pull down the generated code.`), 1); return; } const { org, workspace, branches, defaultBranch } = await this.getOrgWorkspaceBranches(orgId, workspaceId); const branch = branches.find(b => b.name === branchName); const versionId = await this.getVersionIdFromSettings(settings, branch); const sources = await this.getSources(orgId, workspaceId, defaultBranch, branch, versionId, sourceId); const source = sources[0]; if (source == null) { this.error(new errors_1.UserFixableError(errors_1.USER_ERROR_MESSAGES.sourceDoesNotExist(sourceId)), 1); return; } const runtimes = await this.getRuntimes(); const sourceRuntime = runtimes.find(r => r.id === source.runtime.id); const settingRuntime = settings.getRuntime(runtimes); const runtime = this.compareSettingsAndActualRuntimes(settings, settingRuntime, sourceRuntime); if (runtime) { await components_1.SdkSetupAndUsageInfo((_a = settings.getZone()) !== null && _a !== void 0 ? _a : types_1.DEFAULT_ZONE, org, workspace, source, codegenDir, runtime, this.flags.projectDir); } } } exports.default = SetupAction;