( appName: string, silent: boolean, getTelemetry?: () => TelemetryClient | undefined, )
| 14 | import type { TelemetryClient } from './telemetry.js' |
| 15 | |
| 16 | export function createUIEnvironment( |
| 17 | appName: string, |
| 18 | silent: boolean, |
| 19 | getTelemetry?: () => TelemetryClient | undefined, |
| 20 | ): Environment { |
| 21 | const defaultEnvironment = createDefaultEnvironment() |
| 22 | |
| 23 | let newEnvironment = { |
| 24 | ...defaultEnvironment, |
| 25 | appName, |
| 26 | } |
| 27 | |
| 28 | if (!silent) { |
| 29 | newEnvironment = { |
| 30 | ...newEnvironment, |
| 31 | intro: (message: string) => { |
| 32 | intro(message) |
| 33 | }, |
| 34 | outro: (message: string) => { |
| 35 | outro(message) |
| 36 | }, |
| 37 | info: (title?: string, message?: string) => { |
| 38 | log.info( |
| 39 | `${title ? chalk.red(title) : ''}${message ? '\n' + chalk.green(message) : ''}`, |
| 40 | ) |
| 41 | }, |
| 42 | error: (title?: string, message?: string) => { |
| 43 | log.error( |
| 44 | `${title ? `${title}: ` : ''}${message ? '\n' + message : ''}`, |
| 45 | ) |
| 46 | }, |
| 47 | warn: (title?: string, message?: string) => { |
| 48 | log.warn(`${title ? `${title}: ` : ''}${message ? '\n' + message : ''}`) |
| 49 | }, |
| 50 | confirm: async (message: string) => { |
| 51 | const shouldContinue = await confirm({ |
| 52 | message, |
| 53 | }) |
| 54 | if (isCancel(shouldContinue)) { |
| 55 | cancel('Operation cancelled.') |
| 56 | process.exit(0) |
| 57 | } |
| 58 | return shouldContinue |
| 59 | }, |
| 60 | spinner: () => { |
| 61 | const s = spinner() |
| 62 | return { |
| 63 | start: (message: string) => { |
| 64 | s.start(message) |
| 65 | }, |
| 66 | stop: (message: string) => { |
| 67 | s.stop(message) |
| 68 | }, |
| 69 | } |
| 70 | }, |
| 71 | startStep: (info: StatusEvent) => { |
| 72 | getTelemetry?.()?.startStep(info) |
| 73 | }, |
no test coverage detected