MCPcopy
hub / github.com/AutoMaker-Org/automaker / initializeProject

Function initializeProject

apps/ui/src/lib/project-init.ts:41–136  ·  view source on GitHub ↗
(projectPath: string)

Source from the content-addressed store, hash-verified

39 * @returns Result indicating what was created or if the project was already initialized
40 */
41export async function initializeProject(projectPath: string): Promise<ProjectInitResult> {
42 const api = getElectronAPI();
43 const createdFiles: string[] = [];
44 const existingFiles: string[] = [];
45
46 try {
47 // Validate that the project directory exists and is a directory
48 const projectExists = await api.exists(projectPath);
49 if (!projectExists) {
50 return {
51 success: false,
52 isNewProject: false,
53 error: `Project directory does not exist: ${projectPath}. Create it first before initializing.`,
54 };
55 }
56
57 // Verify it's actually a directory (not a file)
58 const projectStat = await api.stat(projectPath);
59 if (!projectStat.success) {
60 return {
61 success: false,
62 isNewProject: false,
63 error: projectStat.error || `Failed to stat project directory: ${projectPath}`,
64 };
65 }
66
67 if (projectStat.stats && !projectStat.stats.isDirectory) {
68 return {
69 success: false,
70 isNewProject: false,
71 error: `Project path is not a directory: ${projectPath}`,
72 };
73 }
74
75 // Initialize git repository if it doesn't exist
76 const gitDirExists = await api.exists(`${projectPath}/.git`);
77 if (!gitDirExists) {
78 logger.info('Initializing git repository...');
79 try {
80 // Initialize git and create an initial empty commit via server route
81 const result = await api.worktree?.initGit(projectPath);
82 if (result?.success && result.result?.initialized) {
83 createdFiles.push('.git');
84 logger.info('Git repository initialized with initial commit');
85 } else if (result?.success && !result.result?.initialized) {
86 // Git already existed (shouldn't happen since we checked, but handle it)
87 existingFiles.push('.git');
88 logger.info('Git repository already exists');
89 } else {
90 logger.warn('Failed to initialize git repository:', result?.error);
91 }
92 } catch (gitError) {
93 logger.warn('Failed to initialize git repository:', gitError);
94 // Don't fail the whole initialization if git init fails
95 }
96 } else {
97 existingFiles.push('.git');
98 }

Callers 15

SidebarFunction · 0.90
SidebarHeaderFunction · 0.90
useProjectCreationFunction · 0.90
ProjectSwitcherFunction · 0.90
OverviewViewFunction · 0.90
WelcomeViewFunction · 0.90
handleCreateBlankProjectFunction · 0.90
handleCreateFromTemplateFunction · 0.90
DashboardViewFunction · 0.90
handleCreateBlankProjectFunction · 0.90

Calls 5

getElectronAPIFunction · 0.90
statMethod · 0.80
mkdirMethod · 0.80
writeFileMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected