stack/packages/stack-cli/src/lib/create-project.ts
BilalG1 3b8667d5f8
cli add back init options (#1379)
<!--

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>
2026-04-27 11:45:44 -07:00

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,
});
}