-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathopencode-config-format.ts
More file actions
31 lines (26 loc) · 947 Bytes
/
opencode-config-format.ts
File metadata and controls
31 lines (26 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { existsSync } from "node:fs"
import { join } from "path"
import { getConfigJson, getConfigJsonc } from "./config-context"
export type ConfigFormat = "json" | "jsonc" | "none"
export function detectConfigFormat(directory?: string): { format: ConfigFormat; path: string } {
if (directory) {
const configJsonc = join(directory, "opencode.jsonc")
const configJson = join(directory, "opencode.json")
if (existsSync(configJsonc)) {
return { format: "jsonc", path: configJsonc }
}
if (existsSync(configJson)) {
return { format: "json", path: configJson }
}
return { format: "none", path: configJson }
}
const configJsonc = getConfigJsonc()
const configJson = getConfigJson()
if (existsSync(configJsonc)) {
return { format: "jsonc", path: configJsonc }
}
if (existsSync(configJson)) {
return { format: "json", path: configJson }
}
return { format: "none", path: configJson }
}