import inquirer from 'inquirer' import { logger } from '@laughing-cli/utils' import type { AvailablePackages } from '../installers' import { availablePackages } from '../installers' interface CliFlags { noGit: boolean noInstall: boolean default: boolean } interface CliResults { packages: AvailablePackages[] } const defaultOptions: CliResults = { packages: ['lint'], } export const runCli = async () => { const cliResults = defaultOptions // Explained below why this is in a try/catch block try { const { packages } = await inquirer.prompt>({ name: 'packages', type: 'checkbox', message: 'Which packages would you like to enable?', choices: availablePackages.map(pkgName => ({ name: pkgName, checked: false, })), }) cliResults.packages = packages } catch (err) { // If the user is not calling create-t3-app from an interactive terminal, inquirer will throw an error with isTTYError = true // If this happens, we catch the error, tell the user what has happened, and then contiue to run the program with a default t3 app if (err instanceof Error && (err as any).isTTYError) { logger.warn( 'laughing-cli needs an interactive terminal to provide options', ) } else { throw err } } return cliResults }