(
apiKey: string | undefined,
databaseId: string | undefined,
templateName: string | undefined,
force: boolean,
config: PrismaConfigInternal,
baseDir: string,
)
| 139 | } |
| 140 | |
| 141 | private async run( |
| 142 | apiKey: string | undefined, |
| 143 | databaseId: string | undefined, |
| 144 | templateName: string | undefined, |
| 145 | force: boolean, |
| 146 | config: PrismaConfigInternal, |
| 147 | baseDir: string, |
| 148 | ): Promise<string | HelpError> { |
| 149 | const flowStart = performance.now() |
| 150 | const stepsCompleted: string[] = [] |
| 151 | const steps: BootstrapStepStatus = { |
| 152 | init: 'skipped', |
| 153 | template: 'not-applicable', |
| 154 | link: 'skipped', |
| 155 | generate: 'not-applicable', |
| 156 | migrate: 'not-applicable', |
| 157 | seed: 'not-applicable', |
| 158 | } |
| 159 | |
| 160 | let distinctId: string |
| 161 | try { |
| 162 | distinctId = await checkpoint.getSignature() |
| 163 | } catch { |
| 164 | distinctId = 'unknown' |
| 165 | } |
| 166 | |
| 167 | const initialState = detectProjectState(baseDir) |
| 168 | |
| 169 | const telemetryCtx = { |
| 170 | distinctId, |
| 171 | databaseId, |
| 172 | linkResult: null as LinkResult | null, |
| 173 | projectState: initialState, |
| 174 | } |
| 175 | |
| 176 | await emitFlowStarted(telemetryCtx) |
| 177 | |
| 178 | try { |
| 179 | let templateScaffolded = false |
| 180 | const isEmptyProject = !initialState.hasSchemaFile && !initialState.hasPackageJson |
| 181 | |
| 182 | // --- Step 1: Init or Template (mutually exclusive, only for from-scratch projects) --- |
| 183 | // |
| 184 | // When no schema exists, the user is starting from scratch. We either: |
| 185 | // (a) scaffold a starter template from prisma-examples (replaces init), or |
| 186 | // (b) run `prisma init` for a minimal empty setup (requires an existing package.json) |
| 187 | // |
| 188 | // Empty directories without a package.json need special handling: prisma init creates |
| 189 | // a prisma.config.ts that depends on `dotenv`, which can't be installed without a |
| 190 | // Node.js project. We surface this clearly and require either a template (which |
| 191 | // provides its own package.json) or manual project initialization first. |
| 192 | if (!initialState.hasSchemaFile) { |
| 193 | if (isEmptyProject) { |
| 194 | console.log(`\n${yellow('!')} No project found in this directory.`) |
| 195 | console.log(` A ${bold('package.json')} is required for Prisma to work.`) |
| 196 | console.log( |
| 197 | ` Initialize one with: ${dim('npm init -y')}, ${dim('pnpm init')}, ${dim('yarn init')}, or ${dim('bun init')}\n`, |
| 198 | ) |
no test coverage detected