mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a "create-cloud" mode to the CLI init flow. * New interactive project creation flow that can prompt for display name and select/create a team-backed project. * **Behavior Changes** * Init now resolves mode from flags, config, or interactive prompts; prompts to choose linking vs creating when inputs are missing. * Non-interactive runs now error when required inputs are absent; cloud linking offers auto-create in interactive mode. * **Refactor** * Centralized auth, project-creation, and env key writing for clearer, safer linking and creation flows. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: aadesh18 <110230993+aadesh18@users.noreply.github.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { input } from "@inquirer/prompts";
|
|
import type { CurrentInternalUser } from "@stackframe/js";
|
|
import { CliError } from "./errors.js";
|
|
import { isNonInteractiveEnv } from "./interactive.js";
|
|
|
|
type CreateProjectOptions = {
|
|
displayName?: string,
|
|
defaultDisplayName?: string,
|
|
};
|
|
|
|
export async function createProjectInteractively(
|
|
user: CurrentInternalUser,
|
|
opts: CreateProjectOptions = {},
|
|
) {
|
|
let displayName = opts.displayName;
|
|
if (!displayName) {
|
|
if (isNonInteractiveEnv()) {
|
|
throw new CliError("--display-name is required in non-interactive environments (CI).");
|
|
}
|
|
displayName = await input({
|
|
message: "Project display name:",
|
|
default: opts.defaultDisplayName,
|
|
validate: (v) => v.trim().length > 0 || "Display name cannot be empty.",
|
|
});
|
|
}
|
|
|
|
const teams = await user.listTeams();
|
|
if (teams.length === 0) {
|
|
throw new CliError("No teams found on your account. Create a team at app.stack-auth.com first.");
|
|
}
|
|
|
|
return await user.createProject({
|
|
displayName: displayName.trim(),
|
|
teamId: teams[0].id,
|
|
});
|
|
}
|