(options: {
preferredProjectLocation: string | null
projectName: string
initializeGit: boolean
})
| 35 | } |
| 36 | |
| 37 | export async function createProject(options: { |
| 38 | preferredProjectLocation: string | null |
| 39 | projectName: string |
| 40 | initializeGit: boolean |
| 41 | }) { |
| 42 | const preferredProjectLocation = options.preferredProjectLocation?.trim() ?? '' |
| 43 | if (preferredProjectLocation.length === 0) { |
| 44 | throw new Error('Set a default project location in Settings first.') |
| 45 | } |
| 46 | |
| 47 | const folderName = sanitizeProjectFolderName(options.projectName) |
| 48 | if (folderName.length === 0) { |
| 49 | throw new Error('Enter a project name.') |
| 50 | } |
| 51 | |
| 52 | const parentDirectory = path.resolve(preferredProjectLocation) |
| 53 | const projectPath = path.join(parentDirectory, folderName) |
| 54 | |
| 55 | await mkdir(parentDirectory, { recursive: true }) |
| 56 | await mkdir(projectPath, { recursive: true }) |
| 57 | |
| 58 | if (options.initializeGit) { |
| 59 | await initializeProjectGit(projectPath) |
| 60 | } |
| 61 | |
| 62 | const result = await startNewThread({ projectId: projectPath }) |
| 63 | moveProjectToTop(projectPath) |
| 64 | return result |
| 65 | } |
| 66 | |
| 67 | async function resolvePathIfPresent(projectPath: string) { |
| 68 | try { |
no test coverage detected