Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 15
env:
CREATE_PRISMA_TELEMETRY_API_KEY: ${{ secrets.CREATE_PRISMA_TELEMETRY_API_KEY }}
CREATE_PRISMA_TELEMETRY_HOST: ${{ vars.CREATE_PRISMA_TELEMETRY_HOST }}
permissions:
contents: read
id-token: write
Expand Down Expand Up @@ -160,6 +163,9 @@ jobs:
if: github.event_name == 'push' && startsWith(github.event.head_commit.message, 'chore(release):')
runs-on: ubuntu-latest
timeout-minutes: 15
env:
CREATE_PRISMA_TELEMETRY_API_KEY: ${{ secrets.CREATE_PRISMA_TELEMETRY_API_KEY }}
CREATE_PRISMA_TELEMETRY_HOST: ${{ vars.CREATE_PRISMA_TELEMETRY_HOST }}
permissions:
contents: write
id-token: write
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ When add-ons are enabled, `create` prompts for the relevant agent and IDE select
When `postgresql` is selected, `create` can provision Prisma Postgres via `create-db --json` and auto-fill `DATABASE_URL`.
Generated projects also include `db:seed` and configure Prisma's `migrations.seed` hook to run `tsx prisma/seed.ts`.

## Telemetry

Published builds may send anonymous PostHog telemetry for `create` runs to help improve the CLI. It does not include project names, file paths, or database URLs. Disable it with `DO_NOT_TRACK`, `CREATE_PRISMA_DISABLE_TELEMETRY`, or `CREATE_PRISMA_TELEMETRY_DISABLED`.

## Scripts

- `bun run build` - Build to `dist/`
Expand Down
49 changes: 49 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"execa": "^9.6.1",
"fs-extra": "^11.3.3",
"handlebars": "^4.7.8",
"posthog-node": "4.18.0",
"trpc-cli": "^0.12.4",
"zod": "^4.3.6"
},
Expand Down
113 changes: 98 additions & 15 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@ import {
collectCreateAddonSetupContext,
executeCreateAddonSetupContext,
} from "../tasks/setup-addons";
import {
trackCreateCompleted,
trackCreateFailed,
type CreateTelemetryFailureStage,
} from "../telemetry";
import { getCreatePrismaIntro } from "../ui/branding";

const DEFAULT_PROJECT_NAME = "my-app";
const DEFAULT_TEMPLATE: CreateTemplate = "hono";
const DEFAULT_SCHEMA_PRESET: SchemaPreset = "basic";

type ExecuteCreateContextResult =
| { ok: true }
| {
ok: false;
stage: CreateTelemetryFailureStage;
error?: unknown;
};

function toPackageName(projectName: string): string {
return (
projectName
Expand Down Expand Up @@ -148,19 +161,59 @@ async function inspectTargetPath(targetPath: string): Promise<CreateTargetPathSt
}

export async function runCreateCommand(rawInput: CreateCommandInput = {}): Promise<void> {
const startedAt = Date.now();
let input: CreateCommandInput = {};
let context: CreatePromptContext | undefined;
let failureStage: CreateTelemetryFailureStage = "validate_input";

try {
const input = CreateCommandInputSchema.parse(rawInput);
input = CreateCommandInputSchema.parse(rawInput);

intro(getCreatePrismaIntro());

const context = await collectCreateContext(input);
failureStage = "collect_context";
context = await collectCreateContext(input);
if (!context) {
return;
}
Comment thread
AmanVarshney01 marked this conversation as resolved.

await executeCreateContext(context);
failureStage = "unknown";
const executionResult = await executeCreateContext(context);
if (!executionResult.ok) {
if (executionResult.error) {
cancel(
`Create command failed: ${
executionResult.error instanceof Error
? executionResult.error.message
: String(executionResult.error)
}`,
);
}

await trackCreateFailed({
input,
context,
durationMs: Date.now() - startedAt,
error: executionResult.error,
stage: executionResult.stage,
});
return;
}

await trackCreateCompleted({
input,
context,
durationMs: Date.now() - startedAt,
});
} catch (error) {
cancel(`Create command failed: ${error instanceof Error ? error.message : String(error)}`);
await trackCreateFailed({
input,
context,
durationMs: Date.now() - startedAt,
error,
stage: failureStage,
});
}
}

Expand Down Expand Up @@ -230,7 +283,9 @@ async function collectCreateContext(
};
}

async function executeCreateContext(context: CreatePromptContext): Promise<void> {
async function executeCreateContext(
context: CreatePromptContext,
): Promise<ExecuteCreateContextResult> {
const scaffoldSpinner = spinner();
scaffoldSpinner.start(`Scaffolding ${context.template} project...`);
try {
Expand All @@ -245,8 +300,11 @@ async function executeCreateContext(context: CreatePromptContext): Promise<void>
scaffoldSpinner.stop("Project files scaffolded.");
} catch (error) {
scaffoldSpinner.stop("Could not scaffold project files.");
cancel(error instanceof Error ? error.message : String(error));
return;
return {
ok: false,
stage: "scaffold_template",
error,
};
}

if (
Expand All @@ -261,17 +319,42 @@ async function executeCreateContext(context: CreatePromptContext): Promise<void>

const cdStep = `- cd ${formatPathForDisplay(context.targetDirectory)}`;
if (context.addonSetupContext) {
await executeCreateAddonSetupContext({
context: context.addonSetupContext,
packageManager: context.prismaSetupContext.packageManager,
try {
await executeCreateAddonSetupContext({
context: context.addonSetupContext,
packageManager: context.prismaSetupContext.packageManager,
projectDir: context.targetDirectory,
verbose: context.prismaSetupContext.verbose,
});
} catch (error) {
return {
ok: false,
stage: "addons",
error,
};
}
}

try {
const prismaSetupResult = await executePrismaSetupContext(context.prismaSetupContext, {
prependNextSteps: [cdStep],
projectDir: context.targetDirectory,
verbose: context.prismaSetupContext.verbose,
includeDevNextStep: true,
});

if (!prismaSetupResult) {
return {
ok: false,
stage: "prisma_setup",
};
}
} catch (error) {
return {
ok: false,
stage: "prisma_setup",
error,
};
}

await executePrismaSetupContext(context.prismaSetupContext, {
prependNextSteps: [cdStep],
projectDir: context.targetDirectory,
includeDevNextStep: true,
});
return { ok: true };
}
Loading
Loading