Skip to content

Commit 945b627

Browse files
committed
Fix: Handle React template creation by using scaffold copying instead of GitHub cloning
- Modified createFromTemplate.ts to check if template has no GitHub URL - For 'react' template, use scaffold directory copying instead of trying to clone - This fixes the 'Template react has no GitHub URL' error when creating regular React apps - Maintains compatibility with other templates that do have GitHub URLs
1 parent 6828c83 commit 945b627

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/ipc/handlers/createFromTemplate.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,45 @@ Available packages and libraries:
916916
const template = await getTemplateOrThrow(templateId);
917917
logger.info(`Template found: ${template.title}, isFrontend: ${template.isFrontend}, githubUrl: ${template.githubUrl}`);
918918

919+
// For templates without GitHub URL (like "react"), use scaffold copying
919920
if (!template.githubUrl) {
920-
throw new Error(`Template ${templateId} has no GitHub URL`);
921+
if (templateId === "react") {
922+
logger.info(`Template ${templateId} has no GitHub URL, using scaffold copying`);
923+
// Use scaffold copying for React template
924+
const scaffoldPath = "/Volumes/Farhan/Desktop/AliFullstack/scaffold";
925+
926+
logger.info(`Using scaffold path: ${scaffoldPath}`);
927+
if (!fs.existsSync(scaffoldPath)) {
928+
logger.error(`Scaffold directory not found at: ${scaffoldPath}`);
929+
throw new Error(`Scaffold directory not found at: ${scaffoldPath}`);
930+
}
931+
932+
// Copy scaffold to frontend
933+
await fs.copy(scaffoldPath, frontendPath, {
934+
overwrite: true,
935+
filter: (src, dest) => {
936+
const relativePath = path.relative(scaffoldPath, src);
937+
return !relativePath.includes('node_modules') && !relativePath.includes('.git');
938+
}
939+
});
940+
941+
logger.info(`Successfully copied scaffold to ${frontendPath}`);
942+
943+
// Install frontend dependencies
944+
try {
945+
const packageJsonPath = path.join(frontendPath, "package.json");
946+
if (fs.existsSync(packageJsonPath)) {
947+
logger.info(`Installing React scaffold dependencies in ${frontendPath}`);
948+
await installDependenciesForFramework(frontendPath, "nodejs");
949+
}
950+
} catch (installError) {
951+
logger.warn(`Failed to install React scaffold dependencies:`, installError);
952+
}
953+
954+
return;
955+
} else {
956+
throw new Error(`Template ${templateId} has no GitHub URL`);
957+
}
921958
}
922959

923960
const repoCachePath = await cloneRepo(template.githubUrl);

0 commit comments

Comments
 (0)