feat: enhance Vercel deployment process with framework detection and source file handling

- Implemented a function to detect project frameworks based on package.json and configuration files.
- Added support for including source files in the deployment request for frameworks that require building.
- Updated the action function to handle framework detection and adjust deployment configuration accordingly.
- Removed unnecessary console logs and improved error handling for file reading operations.
This commit is contained in:
xKevIsDev
2025-07-08 01:20:58 +01:00
parent ac9fba59f6
commit b5d17f2d7e
3 changed files with 299 additions and 27 deletions

View File

@@ -96,12 +96,9 @@ export function useVercelDeploy() {
await container.fs.readdir(dir);
finalBuildPath = dir;
buildPathExists = true;
console.log(`Using build directory: ${finalBuildPath}`);
break;
} catch (error) {
console.log(`Directory ${dir} doesn't exist, trying next option. ${error}`);
// Directory doesn't exist, try the next one
} catch {
// Directory doesn't exist, expected — just skip it
continue;
}
}
@@ -135,6 +132,47 @@ export function useVercelDeploy() {
const fileContents = await getAllFiles(finalBuildPath);
// Get all source project files for framework detection
const allProjectFiles: Record<string, string> = {};
async function getAllProjectFiles(dirPath: string): Promise<void> {
const entries = await container.fs.readdir(dirPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name);
if (entry.isFile()) {
try {
const content = await container.fs.readFile(fullPath, 'utf-8');
// Store with relative path from project root
let relativePath = fullPath;
if (fullPath.startsWith('/home/project/')) {
relativePath = fullPath.replace('/home/project/', '');
} else if (fullPath.startsWith('./')) {
relativePath = fullPath.replace('./', '');
}
allProjectFiles[relativePath] = content;
} catch (error) {
// Skip binary files or files that can't be read as text
console.log(`Skipping file ${entry.name}: ${error}`);
}
} else if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
await getAllProjectFiles(fullPath);
}
}
}
// Try to read from the current directory first
try {
await getAllProjectFiles('.');
} catch {
// Fallback to /home/project if current directory doesn't work
await getAllProjectFiles('/home/project');
}
// Use chatId instead of artifact.id
const existingProjectId = localStorage.getItem(`vercel-project-${currentChatId}`);
@@ -146,6 +184,7 @@ export function useVercelDeploy() {
body: JSON.stringify({
projectId: existingProjectId || undefined,
files: fileContents,
sourceFiles: allProjectFiles,
token: vercelConn.token,
chatId: currentChatId,
}),