| 1 | import type { ProjectOptions, ProjectResult } from "@/types"; |
| 2 | import { initializeGit } from "./initialize-git"; |
| 3 | import { installDependencies } from "./install-dependencies"; |
| 4 | import { promptForOptions } from "./prompt-for-options"; |
| 5 | import { scaffoldTemplate } from "./scaffold-template"; |
| 6 | |
| 7 | export async function createProject( |
| 8 | projectDirectory: string, |
| 9 | options: ProjectOptions, |
| 10 | ): Promise<ProjectResult | null> { |
| 11 | const projectOptions = await promptForOptions({ |
| 12 | ...options, |
| 13 | projectName: projectDirectory, |
| 14 | }); |
| 15 | |
| 16 | if (!projectOptions) { |
| 17 | return null; |
| 18 | } |
| 19 | |
| 20 | const scaffolded = await scaffoldTemplate(projectOptions); |
| 21 | |
| 22 | if (!scaffolded) { |
| 23 | return null; |
| 24 | } |
| 25 | |
| 26 | const gitInitialized = await initializeGit( |
| 27 | projectOptions.projectName ?? projectDirectory, |
| 28 | projectOptions.yes, |
| 29 | ); |
| 30 | |
| 31 | const dependenciesInstalled = await installDependencies( |
| 32 | projectOptions.projectName ?? projectDirectory, |
| 33 | projectOptions.yes, |
| 34 | ); |
| 35 | |
| 36 | return { |
| 37 | projectName: projectOptions.projectName ?? projectDirectory, |
| 38 | gitInitialized, |
| 39 | dependenciesInstalled, |
| 40 | template: projectOptions.template ?? "default", |
| 41 | }; |
| 42 | } |