@eide/foir-cli 0.1.42 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ // src/config/loader.ts
2
+ import { resolve } from "path";
3
+ import { pathToFileURL } from "url";
4
+ import { existsSync } from "fs";
5
+ var CONFIG_FILE_NAMES = [
6
+ "foir.config.ts",
7
+ "foir.config.js",
8
+ "foir.config.mjs",
9
+ ".foirrc.ts",
10
+ ".foirrc.js",
11
+ ".foirrc.mjs"
12
+ ];
13
+ function findConfigFile(explicitPath) {
14
+ if (explicitPath) {
15
+ const abs = resolve(explicitPath);
16
+ if (existsSync(abs)) return abs;
17
+ throw new Error(`Config file not found: ${explicitPath}`);
18
+ }
19
+ const cwd = process.cwd();
20
+ for (const name of CONFIG_FILE_NAMES) {
21
+ const candidate = resolve(cwd, name);
22
+ if (existsSync(candidate)) return candidate;
23
+ }
24
+ return null;
25
+ }
26
+ async function loadConfigFile(filePath) {
27
+ const url = pathToFileURL(filePath).href;
28
+ const mod = await import(url);
29
+ const config = mod.default ?? mod;
30
+ return config;
31
+ }
32
+ async function loadConfigProject() {
33
+ const configPath = findConfigFile();
34
+ if (!configPath) return void 0;
35
+ try {
36
+ const config = await loadConfigFile(configPath);
37
+ return config.project;
38
+ } catch {
39
+ return void 0;
40
+ }
41
+ }
42
+
43
+ export {
44
+ findConfigFile,
45
+ loadConfigFile,
46
+ loadConfigProject
47
+ };