@forge/cli

14.1.0-next.1-experimental-13c2f8d14.1.0-next.21-experimental-554d417
out/command-line/view/global-install-view.js
+out/command-line/view/global-install-view.jsNew file
+126
Index: package/out/command-line/view/global-install-view.js
===================================================================
--- package/out/command-line/view/global-install-view.js
+++ package/out/command-line/view/global-install-view.js
@@ -0,0 +1,126 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.GlobalInstallView = void 0;
+const tslib_1 = require("tslib");
+const chalk_1 = tslib_1.__importDefault(require("chalk"));
+const semver_1 = require("semver");
+const cli_shared_1 = require("@forge/cli-shared");
+class GlobalInstallView {
+    ui;
+    constructor(ui) {
+        this.ui = ui;
+    }
+    toTextTarget(target) {
+        if (target.orgName === undefined)
+            return { unit: target.unitId };
+        if (target.onlyUnit)
+            return { org: target.orgName };
+        return { unit: target.unitName ?? target.unitId, org: target.orgName };
+    }
+    async selectByName(prompt, items) {
+        const nameCounts = new Map();
+        for (const { name } of items) {
+            nameCounts.set(name, (nameCounts.get(name) ?? 0) + 1);
+        }
+        const byLabel = new Map();
+        const labels = items.map((item) => {
+            const label = (nameCounts.get(item.name) ?? 0) > 1 ? `${item.name} (${item.id})` : item.name;
+            byLabel.set(label, item);
+            return label;
+        });
+        const chosen = await this.ui.promptForFilterableList(prompt, labels);
+        return byLabel.get(chosen) ?? items[0];
+    }
+    fetchWithSpinner(fetch) {
+        return this.ui.displaySpinner(fetch);
+    }
+    selectOrganization(orgs) {
+        return this.selectByName(cli_shared_1.Text.install.global.promptOrganization, orgs);
+    }
+    showSelectUnitOverview() {
+        this.ui.emptyLine();
+        this.ui.info(cli_shared_1.Text.install.global.selectUnitOverview);
+    }
+    selectUnit(units) {
+        return this.selectByName(cli_shared_1.Text.install.global.promptUnit, units);
+    }
+    showInstallConfirmation(target) {
+        this.ui.emptyLine();
+        this.ui.info(cli_shared_1.Text.install.global.installConfirmation(this.toTextTarget(target)));
+    }
+    confirmContinueInstall() {
+        return this.ui.confirm(cli_shared_1.Text.install.global.promptContinueInstall);
+    }
+    confirmContinueConnect() {
+        return this.ui.confirm(cli_shared_1.Text.install.global.promptContinueConnect);
+    }
+    runInstall(progress) {
+        return this.ui.displayProgress(progress, cli_shared_1.Text.install.global.cmd.start, cli_shared_1.Text.install.global.cmd.end);
+    }
+    showInstallSuccess(environment, target) {
+        this.ui.info(cli_shared_1.Text.install.global.installSuccess(environment, this.toTextTarget(target)));
+    }
+    runUpgrade(progress) {
+        return this.ui.displayProgress(progress, cli_shared_1.Text.install.global.upgrade.start, cli_shared_1.Text.install.global.upgrade.end);
+    }
+    async promptForUnitUpgrade(installations) {
+        const index = await this.ui.promptForSingleChoiceTable(cli_shared_1.Text.install.global.promptUnitUpgrade, cli_shared_1.Text.install.global.unitUpgradeOverview, cli_shared_1.Text.install.global.unitUpgradeTableHeaders, installations.map((installation) => ({
+            names: [
+                (0, cli_shared_1.environmentToOption)(installation.environmentKey),
+                installation.unitId,
+                installation.connections.length ? installation.connections.map(cli_shared_1.productDisplayName).join(', ') : '—',
+                `${(0, semver_1.major)(installation.version).toString()} ${cli_shared_1.Text.install.booleanToScope(installation.isLatest)}`
+            ],
+            value: installation.unitId,
+            primary: installation.unitId
+        })));
+        return installations[index];
+    }
+    showUpgradeSuccess(environment, target) {
+        this.ui.info(cli_shared_1.Text.install.global.upgradeSuccess(environment, this.toTextTarget(target)));
+    }
+    showAlreadyInstalled(target) {
+        this.ui.info(cli_shared_1.Text.install.global.alreadyInstalled(this.toTextTarget(target)));
+    }
+    confirmConnect(another) {
+        this.ui.emptyLine();
+        return this.ui.confirm(another ? cli_shared_1.Text.install.global.promptConnectAnother : cli_shared_1.Text.install.global.promptConnect);
+    }
+    async selectConnection(options) {
+        this.ui.emptyLine();
+        const byProduct = new Map(options.map((option) => [option.product, option]));
+        const chosen = await this.ui.promptForList(cli_shared_1.Text.install.global.promptConnection, options.map((option) => option.product), {
+            format: (product) => {
+                const option = byProduct.get(product);
+                return option?.linked ? chalk_1.default.grey(`${product}${cli_shared_1.Text.install.global.linkedSuffix}`) : product;
+            }
+        });
+        return byProduct.get(chosen);
+    }
+    showAlreadyLinked(product) {
+        this.ui.info(cli_shared_1.Text.install.global.alreadyLinked(product));
+    }
+    async promptForConnectionTarget(kind) {
+        this.ui.emptyLine();
+        if (kind === 'workspace') {
+            this.ui.info(cli_shared_1.Text.install.global.enterWorkspaceOverview);
+            return this.ui.promptForText(cli_shared_1.Text.install.global.promptWorkspace);
+        }
+        this.ui.info(cli_shared_1.Text.install.global.enterSiteOverview);
+        return this.ui.promptForText(cli_shared_1.Text.install.global.promptSiteUrl);
+    }
+    showConnectConfirmation(product, kind) {
+        this.ui.emptyLine();
+        this.ui.info(kind === 'workspace'
+            ? cli_shared_1.Text.install.global.connectConfirmationWorkspace(product)
+            : cli_shared_1.Text.install.global.connectConfirmationSite(product));
+    }
+    runConnect(progress) {
+        return this.ui.displayProgress(progress, cli_shared_1.Text.install.global.connect.start, cli_shared_1.Text.install.global.connect.end);
+    }
+    showConnectionSuccess(environment, product, site) {
+        this.ui.info(cli_shared_1.Text.install.global.connectionSuccess(environment, product, site));
+    }
+}
+exports.GlobalInstallView = GlobalInstallView;
+//# sourceMappingURL=global-install-view.js.map
\ No newline at end of file