mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 22:32:28 +00:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import fs from "fs/promises"
|
|
import { xdgData, xdgCache, xdgConfig, xdgState } from "xdg-basedir"
|
|
import path from "path"
|
|
|
|
const app = "opencode"
|
|
|
|
const data = path.join(xdgData!, app)
|
|
const cache = path.join(xdgCache!, app)
|
|
const config = path.join(xdgConfig!, app)
|
|
const state = path.join(xdgState!, app)
|
|
|
|
export namespace Global {
|
|
export const Path = {
|
|
data,
|
|
bin: path.join(data, "bin"),
|
|
providers: path.join(config, "providers"),
|
|
cache,
|
|
config,
|
|
state,
|
|
} as const
|
|
}
|
|
|
|
await Promise.all([
|
|
fs.mkdir(Global.Path.data, { recursive: true }),
|
|
fs.mkdir(Global.Path.config, { recursive: true }),
|
|
fs.mkdir(Global.Path.providers, { recursive: true }),
|
|
fs.mkdir(Global.Path.state, { recursive: true }),
|
|
])
|
|
|
|
const CACHE_VERSION = "1"
|
|
|
|
const version = await Bun.file(path.join(Global.Path.cache, "version"))
|
|
.text()
|
|
.catch(() => "0")
|
|
|
|
if (version !== CACHE_VERSION) {
|
|
await fs.rm(Global.Path.cache, { recursive: true, force: true })
|
|
await Bun.file(path.join(Global.Path.cache, "version")).write(CACHE_VERSION)
|
|
}
|