stack/packages/stack-cli/src/commands/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

53 lines
1.7 KiB
TypeScript

import { Command } from "commander";
import { resolveSessionAuth } from "../lib/auth.js";
import { getInternalUser } from "../lib/app.js";
import { createProjectInteractively } from "../lib/create-project.js";
export function registerProjectCommand(program: Command) {
const project = program
.command("project")
.description("Manage projects");
project
.command("list")
.description("List your owned projects")
.action(async () => {
const flags = program.opts();
const auth = resolveSessionAuth(flags);
const user = await getInternalUser(auth);
const projects = await user.listOwnedProjects();
if (program.opts().json) {
console.log(JSON.stringify(projects.map((p) => ({ id: p.id, displayName: p.displayName })), null, 2));
} else {
if (projects.length === 0) {
console.log("No projects found.");
return;
}
for (const p of projects) {
console.log(`${p.id}\t${p.displayName}`);
}
}
});
project
.command("create")
.description("Create a new project")
.option("--display-name <name>", "Project display name")
.action(async (opts) => {
const flags = program.opts();
const auth = resolveSessionAuth(flags);
const user = await getInternalUser(auth);
const newProject = await createProjectInteractively(user, {
displayName: opts.displayName,
});
if (program.opts().json) {
console.log(JSON.stringify({ id: newProject.id, displayName: newProject.displayName }, null, 2));
} else {
console.log(`Project created: ${newProject.id} (${newProject.displayName})`);
}
});
}