@forge/cli
12.11.012.12.0-next.9
out/command-line/controller/default-environment-controller.jsout/command-line/controller/default-environment-controller.js+15−5
Index: package/out/command-line/controller/default-environment-controller.js
===================================================================
--- package/out/command-line/controller/default-environment-controller.js
+++ package/out/command-line/controller/default-environment-controller.js
@@ -1,8 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultEnvironmentController = exports.DefaultEnvironmentNotSetError = void 0;
const cli_shared_1 = require("@forge/cli-shared");
+const graphql_client_1 = require("../../environment/graphql-client");
const environment_1 = require("../environment");
const utils_1 = require("../utils");
class DefaultEnvironmentNotSetError extends Error {
constructor() {
@@ -16,18 +17,18 @@
cachedConfigService;
getAppConfig;
userRepository;
createEnvironmentCommand;
- listEnvironmentCommand;
+ environmentClient;
getAppOwnerQuery;
- constructor(ui, credentialStore, cachedConfigService, getAppConfig, userRepository, createEnvironmentCommand, listEnvironmentCommand, getAppOwnerQuery) {
+ constructor(ui, credentialStore, cachedConfigService, getAppConfig, userRepository, createEnvironmentCommand, environmentClient, getAppOwnerQuery) {
this.ui = ui;
this.credentialStore = credentialStore;
this.cachedConfigService = cachedConfigService;
this.getAppConfig = getAppConfig;
this.userRepository = userRepository;
this.createEnvironmentCommand = createEnvironmentCommand;
- this.listEnvironmentCommand = listEnvironmentCommand;
+ this.environmentClient = environmentClient;
this.getAppOwnerQuery = getAppOwnerQuery;
}
async run(nonInteractive) {
const defaultEnvironment = await this.getDefaultEnvironment();
@@ -75,10 +76,19 @@
}
return this.createAndSetDefaultEnvironment(newEnvironmentKey);
}
async environmentExists(environmentKey) {
- const environments = await this.listEnvironmentCommand.execute();
- return environments.some((environment) => environmentKey === environment.key);
+ const { id: appId } = await this.getAppConfig();
+ try {
+ await this.environmentClient.getEnvironmentByKey({ appId, environmentKey });
+ return true;
+ }
+ catch (err) {
+ if (err instanceof graphql_client_1.EnvironmentNotFoundError) {
+ return false;
+ }
+ throw err;
+ }
}
async setExistingEnvironmentAsDefault(contributorName, environmentKey) {
this.ui.warn(cli_shared_1.Text.defaultEnv.warn);
this.ui.emptyLine();