message: feat(cli): improve error handling and messaging when reading theme file
diff: @@ -6,10 +6,23 @@ import { isObject } from "@chakra-ui/utils"
  import { createThemeTypingsInterface } from "../command/tokens/create-theme-typings-interface"
  import { themeKeyConfiguration } from "../command/tokens/config"
  +const bold = (text: string) => `\x1b[1m${text}\x1b[22m`
  +
  async function importTheme(path: string) {
  const module = await import(path)
  + const theme = module.default ?? module.theme
  +
  + if (!theme)
  + throw new Error(`
  + Theme export not found in module: '${path}'.
  +
  + A theme should have a ${bold("default")} export or a ${bold(
  + "theme",
  + )} named export.
  + Found the following exports: ${bold(Object.keys(module).join(", "))}
  + `)
  - return module.default ?? module.theme
  + return theme
  }
  async function readTheme(themeFilePath: string) {
  @@ -24,8 +37,14 @@ async function readTheme(themeFilePath: string) {
  await fs.promises.stat(absoluteThemePath)
  return importTheme(absoluteThemePath)
  - } catch {
  + } catch (statError) {
  + try {
  return importTheme(require.resolve(themeFilePath, { paths: [cwd] }))
  + } catch (resolveError) {
  + throw new Error(
  + `Theme file or package not found \n${statError} \n${resolveError}`,
  + )
  + }
  }
  }
  