{"version":3,"file":"loadConfig.cjs","names":["jiti"],"sources":["../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport _jiti from \"jiti\";\n\nimport type { Config } from \"./configSchema\";\n\nconst jiti = _jiti(process.cwd());\n\nconst loadModuleWithJiti = <TModule>(id: string): TModule => {\n\tconst mod = jiti(id) as TModule | { default: TModule };\n\n\treturn typeof mod === \"object\" && mod !== null && \"default\" in mod ? mod.default : mod;\n};\n\nconst DEFAULT_CONFIG_PATHS = [\"prismicCodegen.config.ts\", \"prismicCodegen.config.js\"];\n\ntype LoadConfigConfig = {\n\tpath?: string;\n};\n\nexport const loadConfig = (config: LoadConfigConfig): Config => {\n\tif (config.path) {\n\t\tif (existsSync(config.path)) {\n\t\t\treturn loadModuleWithJiti(resolvePath(config.path));\n\t\t} else {\n\t\t\tthrow new Error(`Config file does not exist: ${config.path}`);\n\t\t}\n\t} else {\n\t\tfor (const configPath of DEFAULT_CONFIG_PATHS) {\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\treturn loadModuleWithJiti(resolvePath(configPath));\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no config file exists, an empty config is returned.\n\treturn {};\n};\n"],"mappings":";;;;;;AAOA,MAAMA,UAAAA,GAAAA,KAAAA,SAAa,QAAQ,KAAK,CAAC;AAEjC,MAAM,sBAA+B,OAAwB;CAC5D,MAAM,MAAMA,OAAK,GAAG;AAEpB,QAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,aAAa,MAAM,IAAI,UAAU;;AAGpF,MAAM,uBAAuB,CAAC,4BAA4B,2BAA2B;AAMrF,MAAa,cAAc,WAAqC;AAC/D,KAAI,OAAO,KACV,MAAA,GAAA,GAAA,YAAe,OAAO,KAAK,CAC1B,QAAO,oBAAA,GAAA,KAAA,SAA+B,OAAO,KAAK,CAAC;KAEnD,OAAM,IAAI,MAAM,+BAA+B,OAAO,OAAO;KAG9D,MAAK,MAAM,cAAc,qBACxB,MAAA,GAAA,GAAA,YAAe,WAAW,CACzB,QAAO,oBAAA,GAAA,KAAA,SAA+B,WAAW,CAAC;AAMrD,QAAO,EAAE"}