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

34 lines (33 loc) 1.64 kB
import { updateRseConfig } from "@reliverse/cfg"; import { re } from "@reliverse/relico"; import { inputPrompt, deleteLastLine } from "@reliverse/rempts"; import { DEFAULT_CLI_USERNAME } from "../../constants.js"; export async function askUsernameFrontend(config, shouldAskIfExists) { if (!shouldAskIfExists && config.projectAuthor && config.projectAuthor !== "") return config.projectAuthor; const previousName = typeof config.projectAuthor === "string" ? config.projectAuthor : ""; const hasPreviousName = previousName !== ""; const placeholder = hasPreviousName ? previousName : DEFAULT_CLI_USERNAME; const content = hasPreviousName ? `Last used name: ${re.cyanBright(placeholder)} (just press <Enter> to use it again)` : `You can press Enter to use the default name: ${re.cyanBright(DEFAULT_CLI_USERNAME)}`; const userInput = await inputPrompt({ title: "Enter a name/username for the frontend (e.g. footer, contact page, etc.):", content, placeholder: hasPreviousName ? "No worries about @ symbol anywhere, I'll add it for you." : `[Default: ${placeholder}] No worries about @ symbol anywhere, I'll add it for you.`, defaultValue: hasPreviousName ? previousName : DEFAULT_CLI_USERNAME }); const trimmedInput = userInput.trim(); if (trimmedInput === "") { if (hasPreviousName) { return previousName; } await updateRseConfig( process.cwd(), { projectAuthor: DEFAULT_CLI_USERNAME }, false ); deleteLastLine(); return DEFAULT_CLI_USERNAME; } await updateRseConfig(process.cwd(), { projectAuthor: trimmedInput }, false); return trimmedInput; }