@forge/cli-shared

8.18.08.18.1-next.0
out/ui/command-line-ui.js
~out/ui/command-line-ui.jsModified
+31−28
Index: package/out/ui/command-line-ui.js
===================================================================
--- package/out/ui/command-line-ui.js
+++ package/out/ui/command-line-ui.js
@@ -13,9 +13,8 @@
 const text_1 = require("./text");
 const multiple_table_prompt_1 = require("./multiple-table-prompt");
 const single_table_prompt_1 = require("./single-table-prompt");
 const shared_1 = require("../shared");
-const cache_1 = require("../cache");
 var ProgressLogType;
 (function (ProgressLogType) {
     ProgressLogType[ProgressLogType["startText"] = 0] = "startText";
     ProgressLogType[ProgressLogType["successText"] = 1] = "successText";
@@ -25,53 +24,57 @@
     return new Promise((resolve) => setTimeout(resolve, timeMs));
 }
 class CommandLineUI {
     verbose;
+    customEffectsEnabled;
     logger;
     spinner;
     promptInternal;
     insideProgress = false;
+    statsigService;
+    cachedSpinnerConfig = 'dots';
     addedProgressPadding = false;
     static ANSI_MOVE_CURSOR_UP_ONE = '\x1B[1A';
     static ANSI_CLEAR_CURSOR_LINE = '\x1B[2K';
     static NON_TTY_ENV_DEFAULT_COLUMNS = 100;
-    constructor(verbose, spinner, logger) {
+    constructor(verbose, statsigService, spinner, logger, customEffectsEnabled) {
         this.verbose = verbose;
+        this.customEffectsEnabled = customEffectsEnabled;
         this.spinner = spinner || (0, ora_1.default)({ discardStdin: false });
         this.logger = logger || console;
         this.promptInternal = inquirer_1.default.createPromptModule({ skipTTYChecks: false });
+        this.statsigService = statsigService || null;
         this.registerCustomUIElements();
     }
-    getSeasonalSpinner() {
+    setStatsigService(statsigService) {
+        this.statsigService = statsigService;
+        this.initCustomSpinner();
+    }
+    seasonalSpinnerEffectsEnabled() {
         if (process.env.FORGE_DISABLE_SEASONAL_EFFECTS) {
-            return 'dots';
+            return false;
         }
-        try {
-            const cachedConf = cache_1.CachedConf.getCache(cache_1.CONFIG_PROJECT_NAME);
-            const seasonalEffectsEnabled = cachedConf.get('seasonal-effects') ?? true;
-            if (!seasonalEffectsEnabled) {
-                return 'dots';
-            }
+        if (this.customEffectsEnabled) {
+            return this.customEffectsEnabled();
         }
-        catch {
+        return true;
+    }
+    initCustomSpinner() {
+        if (!this.seasonalSpinnerEffectsEnabled() || !this.statsigService) {
+            return;
         }
-        const now = new Date();
-        const month = now.getMonth();
-        const day = now.getDate();
-        if (month === 9) {
-            return {
-                interval: 300,
-                frames: ['🎃', '🟠', '⚫', '🟤']
-            };
-        }
-        if (month === 11 && day <= 25) {
-            return {
-                interval: 300,
-                frames: ['🎄', '🔴', '🟢', '⚪']
-            };
-        }
-        return 'dots';
+        this.statsigService
+            .getCustomSpinnerConfig()
+            .then((frames) => {
+            if (frames && frames.length > 0) {
+                this.cachedSpinnerConfig = { interval: 300, frames };
+            }
+        })
+            .catch(() => this.debug(text_1.Text.settings.customEffects.setupError));
     }
+    getSpinner() {
+        return this.cachedSpinnerConfig;
+    }
     async prompt(questions, initialAnswers) {
         try {
             return await this.promptInternal(questions, initialAnswers);
         }
@@ -89,9 +92,9 @@
         try {
             this.insideProgress = true;
             this.addedProgressPadding = false;
             if (!this.debugEnabled) {
-                this.spinner.spinner = this.getSeasonalSpinner();
+                this.spinner.spinner = this.getSpinner();
                 this.spinner.start();
             }
             this.log(startText, ProgressLogType.startText);
             const result = await progress();