{"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n  const appLogger = getAppLogger(configuration);\n  // Try to import prettier if it exists\n  let prettier: any;\n  try {\n    prettier = require('prettier');\n  } catch (error) {\n    // Prettier is not installed, continue without it\n  }\n\n  // Apply Prettier formatting if it's available\n  if (prettier) {\n    try {\n      // Try to find a prettier config file\n      const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n      // Format the code with Prettier\n      const formattedCode = await prettier.format(code, {\n        ...prettierConfig,\n        filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n      });\n\n      const relativePath = relative(configuration.content.baseDir, filePath);\n\n      appLogger(`Applied Prettier formatting to ${relativePath}`, {\n        level: 'info',\n        isVerbose: true,\n      });\n\n      return formattedCode;\n    } catch (error) {\n      const err = error as Error;\n      appLogger(\n        `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n        {\n          level: 'warn',\n          isVerbose: true,\n        }\n      );\n      // Continue with unformatted code on prettier error\n    }\n  }\n\n  return code;\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,gBAAgB;AAElB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAClE,QAAM,YAAY,aAAa,aAAa;AAE5C,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,YAAM,eAAe,SAAS,cAAc,QAAQ,SAAS,QAAQ;AAErE,gBAAU,kCAAkC,YAAY,IAAI;AAAA,QAC1D,OAAO;AAAA,QACP,WAAW;AAAA,MACb,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}