| 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 | import { installPackages } from "./install-packages"; |
| 7 | |
| 8 | export async function createProject( |
| 9 | projectDirectory: string, |
| 10 | options: ProjectOptions, |
| 11 | ): Promise<ProjectResult | null> { |
| 12 | const projectOptions = await promptForOptions({ |
| 13 | ...options, |
| 14 | projectName: projectDirectory, |
| 15 | }); |
| 16 | |
| 17 | if (!projectOptions) { |
| 18 | return null; |
| 19 | } |
| 20 | |
| 21 | const scaffolded = await scaffoldTemplate(projectOptions); |
| 22 | |
| 23 | if (!scaffolded) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | await installPackages(projectOptions); |
| 28 | |
| 29 | const gitInitialized = await initializeGit( |
| 30 | projectOptions.projectName ?? projectDirectory, |
| 31 | projectOptions.yes, |
| 32 | ); |
| 33 | |
| 34 | const dependenciesInstalled = await installDependencies( |
| 35 | projectOptions.projectName ?? projectDirectory, |
| 36 | projectOptions.yes, |
| 37 | ); |
| 38 | |
| 39 | return { |
| 40 | projectName: projectOptions.projectName ?? projectDirectory, |
| 41 | gitInitialized, |
| 42 | dependenciesInstalled, |
| 43 | template: projectOptions.template ?? "default", |
| 44 | }; |
| 45 | } |