UNPKG

@reliverse/rse

Version:

@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power

69 lines (68 loc) 2.47 kB
import { getOrCreateRseConfig } from "@reliverse/cfg"; import path from "@reliverse/pathkit"; import fs from "@reliverse/relifso"; import { relinka } from "@reliverse/relinka"; import { defineCommand } from "@reliverse/rempts"; import { showManualBuilderMenu } from "./impl/init-impl.js"; import { initMinimalrseProject } from "./impl/init-utils.js"; import { askProjectName } from "../../libs/sdk/utils/prompts/askProjectName.js"; import { getOrCreateReliverseMemory } from "../../libs/sdk/utils/reliverseMemory.js"; import { getCurrentWorkingDirectory } from "../../libs/sdk/utils/terminalHelpers.js"; export default defineCommand({ meta: { name: "init", description: "Initialize a new rse project with minimal setup" }, args: { dev: { type: "boolean", description: "Runs in dev mode", required: false }, target: { type: "string", description: "Path to the directory (opens project selector if not provided)", required: false } }, run: async ({ args }) => { try { const { dev: isDev, target } = args; const cwd = getCurrentWorkingDirectory(); const memory = await getOrCreateReliverseMemory(); const { config } = await getOrCreateRseConfig({ projectPath: cwd, isDev, overrides: {} }); const trimmedTarget = typeof target === "string" ? target.trim() : ""; const explicitTargetProvided = trimmedTarget.length > 0; const projectName = explicitTargetProvided ? trimmedTarget : await askProjectName({}); const projectPath = isDev ? path.resolve(cwd, `tests-runtime/${projectName}`) : path.resolve(cwd, projectName); if (await fs.pathExists(projectPath)) { throw new Error(`Project directory ${projectPath} already exists`); } if (explicitTargetProvided) { await initMinimalrseProject(projectPath, projectName, isDev); } else { await showManualBuilderMenu({ projectName, cwd, isDev, memory, config, skipPrompts: false }); } relinka("success", "Project initialization completed successfully."); process.exit(0); } catch (error) { if (error instanceof Error) { relinka("error", "Error during project initialization:", error.message); } else { relinka("error", "Error during project initialization:", String(error)); } process.exit(1); } } });