refactor(packages): extract utils package
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { getOpenCodeConfigPaths, detectPluginConfigFile } from "../../shared"
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../shared/plugin-identity"
|
||||
import type {
|
||||
OpenCodeBinaryType,
|
||||
OpenCodeConfigPaths,
|
||||
@@ -43,7 +44,10 @@ export function getConfigJsonc(): string {
|
||||
|
||||
export function getOmoConfigPath(): string {
|
||||
const configDir = getConfigContext().paths.configDir
|
||||
const detected = detectPluginConfigFile(configDir)
|
||||
const detected = detectPluginConfigFile(configDir, {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
if (detected.format !== "none") return detected.path
|
||||
return getConfigContext().paths.omoConfig
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from "node:path"
|
||||
|
||||
import { OhMyOpenCodeConfigSchema } from "../../../config"
|
||||
import { detectPluginConfigFile, getOpenCodeConfigDir, parseJsonc } from "../../../shared"
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../../shared/plugin-identity"
|
||||
import { CHECK_IDS, CHECK_NAMES, PACKAGE_NAME } from "../constants"
|
||||
import type { CheckResult, DoctorIssue } from "../types"
|
||||
import { loadAvailableModelsFromCache } from "./model-resolution-cache"
|
||||
@@ -20,11 +21,17 @@ interface ConfigValidationResult {
|
||||
}
|
||||
|
||||
function findConfigPath(): string | null {
|
||||
const projectConfig = detectPluginConfigFile(PROJECT_CONFIG_DIR)
|
||||
const projectConfig = detectPluginConfigFile(PROJECT_CONFIG_DIR, {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
if (projectConfig.format !== "none") return projectConfig.path
|
||||
|
||||
const userConfigDir = getOpenCodeConfigDir({ binary: "opencode" })
|
||||
const userConfig = detectPluginConfigFile(userConfigDir)
|
||||
const userConfig = detectPluginConfigFile(userConfigDir, {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
if (userConfig.format !== "none") return userConfig.path
|
||||
|
||||
return null
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { readFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { detectPluginConfigFile, getOpenCodeConfigDir, parseJsonc } from "../../../shared"
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../../shared/plugin-identity"
|
||||
import type { OmoConfig } from "./model-resolution-types"
|
||||
|
||||
const PROJECT_CONFIG_DIR = join(process.cwd(), ".opencode")
|
||||
|
||||
export function loadOmoConfig(): OmoConfig | null {
|
||||
const projectDetected = detectPluginConfigFile(PROJECT_CONFIG_DIR)
|
||||
const projectDetected = detectPluginConfigFile(PROJECT_CONFIG_DIR, {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
if (projectDetected.format !== "none") {
|
||||
try {
|
||||
const content = readFileSync(projectDetected.path, "utf-8")
|
||||
@@ -17,7 +21,10 @@ export function loadOmoConfig(): OmoConfig | null {
|
||||
}
|
||||
|
||||
const userConfigDir = getOpenCodeConfigDir({ binary: "opencode" })
|
||||
const userDetected = detectPluginConfigFile(userConfigDir)
|
||||
const userDetected = detectPluginConfigFile(userConfigDir, {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
if (userDetected.format !== "none") {
|
||||
try {
|
||||
const content = readFileSync(userDetected.path, "utf-8")
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { CheckResult } from "../types"
|
||||
import { readFileSync, promises as fs } from "node:fs"
|
||||
import path from "node:path"
|
||||
import { detectPluginConfigFile, getOpenCodeConfigDir, parseJsonc } from "../../../shared"
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../../shared/plugin-identity"
|
||||
|
||||
export async function checkTeamMode(): Promise<CheckResult> {
|
||||
const config = loadTeamModeConfig()
|
||||
@@ -33,8 +34,14 @@ export async function checkTeamMode(): Promise<CheckResult> {
|
||||
}
|
||||
|
||||
function loadTeamModeConfig() {
|
||||
const projectConfig = detectPluginConfigFile(path.join(process.cwd(), ".opencode"))
|
||||
const userConfig = detectPluginConfigFile(getOpenCodeConfigDir({ binary: "opencode" }))
|
||||
const projectConfig = detectPluginConfigFile(path.join(process.cwd(), ".opencode"), {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
const userConfig = detectPluginConfigFile(getOpenCodeConfigDir({ binary: "opencode" }), {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
const configPath = projectConfig.format !== "none" ? projectConfig.path : userConfig.path
|
||||
if (!configPath) return { team_mode: undefined }
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { createLspMcpConfig } from "../../../mcp/lsp"
|
||||
import { detectPluginConfigFile, getOpenCodeConfigDir, parseJsonc } from "../../../shared"
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../../shared/plugin-identity"
|
||||
|
||||
type OmoConfigForDoctor = {
|
||||
disabled_mcps?: string[]
|
||||
@@ -13,7 +14,10 @@ type InstalledLspServersOptions = {
|
||||
}
|
||||
|
||||
function readOmoConfig(configDirectory: string): OmoConfigForDoctor | null {
|
||||
const detected = detectPluginConfigFile(configDirectory)
|
||||
const detected = detectPluginConfigFile(configDirectory, {
|
||||
basenames: [CONFIG_BASENAME],
|
||||
legacyBasenames: [LEGACY_CONFIG_BASENAME],
|
||||
})
|
||||
if (detected.format === "none") {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user