UNPKG

@reliverse/rse-sdk

Version:

@reliverse/rse-sdk allows you to create new plugins for @reliverse/rse CLI, interact with reliverse.org, and even extend your own CLI functionality (you may also try @reliverse/dler-sdk for this case).

66 lines (65 loc) 2.04 kB
import { migrateRseConfig } from "@reliverse/cfg"; import { relinka } from "@reliverse/relinka"; import { simpleGit } from "simple-git"; import { cliName } from "../../../../constants.js"; import { getEffectiveDir } from "../../../../utils/getEffectiveDir.js"; import { handleReplacements } from "../../../../utils/replacements/reps-mod.js"; import { handleExistingRepoContent } from "./utils-private-repo.js"; export async function handleExistingRepo(params, shouldCommitAndPush, isDev) { const effectiveDir = getEffectiveDir(params); relinka( "info", `Using existing repo: ${params.githubUsername}/${params.projectName}` ); const { success: repoSuccess, externalRseConfig } = await handleExistingRepoContent( params.memory, params.githubUsername, params.projectName, effectiveDir ); if (!repoSuccess) { throw new Error("Failed to handle existing repository content"); } if (externalRseConfig) { await migrateRseConfig(externalRseConfig, effectiveDir, isDev); } await handleReplacements( effectiveDir, params.selectedTemplate, "", { ...params.config, projectName: params.projectName, frontendUsername: params.githubUsername, primaryDomain: `${params.projectName}.com` }, true, false, false ); if (shouldCommitAndPush) { if (!params.memory.githubKey) { throw new Error("GitHub token not found"); } const git = simpleGit({ baseDir: effectiveDir }); await git.add("."); await git.commit(`Update by ${cliName}`); const latestCommit = await git.log({ maxCount: 1 }); if (!latestCommit.latest) { throw new Error("Failed to get latest commit"); } try { await git.push("origin", "main"); relinka("success", "Created and pushed new commit with changes"); return true; } catch (error) { relinka( "error", "Failed to push commit:", error instanceof Error ? error.message : String(error) ); return false; } } return true; }