1*8d307f52SEvan Baconimport chalk from 'chalk'; 2*8d307f52SEvan Baconimport terminalLink from 'terminal-link'; 3*8d307f52SEvan Bacon 4*8d307f52SEvan Bacon/** 5*8d307f52SEvan Bacon * Prints a link for given URL, using text if provided, otherwise text is just the URL. 6*8d307f52SEvan Bacon * Format links as dim (unless disabled) and with an underline. 7*8d307f52SEvan Bacon * 8*8d307f52SEvan Bacon * @example https://expo.dev 9*8d307f52SEvan Bacon */ 10*8d307f52SEvan Baconexport function link( 11*8d307f52SEvan Bacon url: string, 12*8d307f52SEvan Bacon { text = url, dim = true }: { text?: string; dim?: boolean } = {} 13*8d307f52SEvan Bacon): string { 14*8d307f52SEvan Bacon let output: string; 15*8d307f52SEvan Bacon // Links can be disabled via env variables https://github.com/jamestalmage/supports-hyperlinks/blob/master/index.js 16*8d307f52SEvan Bacon if (terminalLink.isSupported) { 17*8d307f52SEvan Bacon output = terminalLink(text, url); 18*8d307f52SEvan Bacon } else { 19*8d307f52SEvan Bacon output = `${text === url ? '' : text + ': '}${chalk.underline(url)}`; 20*8d307f52SEvan Bacon } 21*8d307f52SEvan Bacon return dim ? chalk.dim(output) : output; 22*8d307f52SEvan Bacon} 23*8d307f52SEvan Bacon 24*8d307f52SEvan Bacon/** 25*8d307f52SEvan Bacon * Provide a consistent "Learn more" link experience. 26*8d307f52SEvan Bacon * Format links as dim (unless disabled) with an underline. 27*8d307f52SEvan Bacon * 28*8d307f52SEvan Bacon * @example [Learn more](https://expo.dev) 29*8d307f52SEvan Bacon * @example Learn more: https://expo.dev 30*8d307f52SEvan Bacon */ 31*8d307f52SEvan Baconexport function learnMore( 32*8d307f52SEvan Bacon url: string, 33*8d307f52SEvan Bacon { 34*8d307f52SEvan Bacon learnMoreMessage: maybeLearnMoreMessage, 35*8d307f52SEvan Bacon dim = true, 36*8d307f52SEvan Bacon }: { learnMoreMessage?: string; dim?: boolean } = {} 37*8d307f52SEvan Bacon): string { 38*8d307f52SEvan Bacon return link(url, { text: maybeLearnMoreMessage ?? 'Learn more', dim }); 39*8d307f52SEvan Bacon} 40