Merge branch 'main' into chore/remove-cursor-target-support
This commit is contained in:
68
src/targets/gemini.ts
Normal file
68
src/targets/gemini.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import path from "path"
|
||||
import { backupFile, copyDir, ensureDir, pathExists, readJson, writeJson, writeText } from "../utils/files"
|
||||
import type { GeminiBundle } from "../types/gemini"
|
||||
|
||||
export async function writeGeminiBundle(outputRoot: string, bundle: GeminiBundle): Promise<void> {
|
||||
const paths = resolveGeminiPaths(outputRoot)
|
||||
await ensureDir(paths.geminiDir)
|
||||
|
||||
if (bundle.generatedSkills.length > 0) {
|
||||
for (const skill of bundle.generatedSkills) {
|
||||
await writeText(path.join(paths.skillsDir, skill.name, "SKILL.md"), skill.content + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle.skillDirs.length > 0) {
|
||||
for (const skill of bundle.skillDirs) {
|
||||
await copyDir(skill.sourceDir, path.join(paths.skillsDir, skill.name))
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle.commands.length > 0) {
|
||||
for (const command of bundle.commands) {
|
||||
await writeText(path.join(paths.commandsDir, `${command.name}.toml`), command.content + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle.mcpServers && Object.keys(bundle.mcpServers).length > 0) {
|
||||
const settingsPath = path.join(paths.geminiDir, "settings.json")
|
||||
const backupPath = await backupFile(settingsPath)
|
||||
if (backupPath) {
|
||||
console.log(`Backed up existing settings.json to ${backupPath}`)
|
||||
}
|
||||
|
||||
// Merge mcpServers into existing settings if present
|
||||
let existingSettings: Record<string, unknown> = {}
|
||||
if (await pathExists(settingsPath)) {
|
||||
try {
|
||||
existingSettings = await readJson<Record<string, unknown>>(settingsPath)
|
||||
} catch {
|
||||
console.warn("Warning: existing settings.json could not be parsed and will be replaced.")
|
||||
}
|
||||
}
|
||||
|
||||
const existingMcp = (existingSettings.mcpServers && typeof existingSettings.mcpServers === "object")
|
||||
? existingSettings.mcpServers as Record<string, unknown>
|
||||
: {}
|
||||
const merged = { ...existingSettings, mcpServers: { ...existingMcp, ...bundle.mcpServers } }
|
||||
await writeJson(settingsPath, merged)
|
||||
}
|
||||
}
|
||||
|
||||
function resolveGeminiPaths(outputRoot: string) {
|
||||
const base = path.basename(outputRoot)
|
||||
// If already pointing at .gemini, write directly into it
|
||||
if (base === ".gemini") {
|
||||
return {
|
||||
geminiDir: outputRoot,
|
||||
skillsDir: path.join(outputRoot, "skills"),
|
||||
commandsDir: path.join(outputRoot, "commands"),
|
||||
}
|
||||
}
|
||||
// Otherwise nest under .gemini
|
||||
return {
|
||||
geminiDir: path.join(outputRoot, ".gemini"),
|
||||
skillsDir: path.join(outputRoot, ".gemini", "skills"),
|
||||
commandsDir: path.join(outputRoot, ".gemini", "commands"),
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,19 @@ import type { CodexBundle } from "../types/codex"
|
||||
import type { DroidBundle } from "../types/droid"
|
||||
import type { CursorBundle } from "../types/cursor"
|
||||
import type { PiBundle } from "../types/pi"
|
||||
import type { GeminiBundle } from "../types/gemini"
|
||||
import { convertClaudeToOpenCode, type ClaudeToOpenCodeOptions } from "../converters/claude-to-opencode"
|
||||
import { convertClaudeToCodex } from "../converters/claude-to-codex"
|
||||
import { convertClaudeToDroid } from "../converters/claude-to-droid"
|
||||
import { convertClaudeToCursor } from "../converters/claude-to-cursor"
|
||||
import { convertClaudeToPi } from "../converters/claude-to-pi"
|
||||
import { convertClaudeToGemini } from "../converters/claude-to-gemini"
|
||||
import { writeOpenCodeBundle } from "./opencode"
|
||||
import { writeCodexBundle } from "./codex"
|
||||
import { writeDroidBundle } from "./droid"
|
||||
import { writeCursorBundle } from "./cursor"
|
||||
import { writePiBundle } from "./pi"
|
||||
import { writeGeminiBundle } from "./gemini"
|
||||
|
||||
export type TargetHandler<TBundle = unknown> = {
|
||||
name: string
|
||||
@@ -53,4 +56,10 @@ export const targets: Record<string, TargetHandler> = {
|
||||
convert: convertClaudeToPi as TargetHandler<PiBundle>["convert"],
|
||||
write: writePiBundle as TargetHandler<PiBundle>["write"],
|
||||
},
|
||||
gemini: {
|
||||
name: "gemini",
|
||||
implemented: true,
|
||||
convert: convertClaudeToGemini as TargetHandler<GeminiBundle>["convert"],
|
||||
write: writeGeminiBundle as TargetHandler<GeminiBundle>["write"],
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user