1import chalk from 'chalk'; 2 3export function time(label?: string): void { 4 console.time(label); 5} 6 7export function timeEnd(label?: string): void { 8 console.timeEnd(label); 9} 10 11export function error(...message: string[]): void { 12 console.error(...message); 13} 14 15/** Print an error and provide additional info (the stack trace) in debug mode. */ 16export function exception(e: Error): void { 17 const { env } = require('./utils/env'); 18 error(chalk.red(e.toString()) + (env.EXPO_DEBUG ? '\n' + chalk.gray(e.stack) : '')); 19} 20 21export function warn(...message: string[]): void { 22 console.warn(...message.map((value) => chalk.yellow(value))); 23} 24 25export function log(...message: string[]): void { 26 console.log(...message); 27} 28 29/** @deprecated use `debug` package with the `expo:` prefix instead. */ 30export function debug(...message: any[]): void { 31 if (require('./utils/env').env.EXPO_DEBUG) console.log(...message); 32} 33 34/** Clear the terminal of all text. */ 35export function clear(): void { 36 process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'); 37} 38 39/** Log a message and exit the current process. If the `code` is non-zero then `console.error` will be used instead of `console.log`. */ 40export function exit(message: string | Error, code: number = 1): never { 41 if (message instanceof Error) { 42 exception(message); 43 process.exit(code); 44 } 45 46 if (message) { 47 if (code === 0) { 48 log(message); 49 } else { 50 error(message); 51 } 52 } 53 54 process.exit(code); 55} 56 57// The re-export makes auto importing easier. 58export const Log = { 59 time, 60 timeEnd, 61 error, 62 exception, 63 warn, 64 log, 65 debug, 66 clear, 67 exit, 68}; 69