Files
bolt.new/app/utils/projectCommands.ts
Dustin Loring 855121a70e feat: git clone by url
ability to git clone by url
2025-01-17 07:36:07 -05:00

75 lines
1.8 KiB
TypeScript

import { generateId, type Message } from 'ai';
interface FileContent {
path: string;
content: string;
}
interface DetectedCommand {
type: string;
command: string;
description: string;
}
export async function detectProjectCommands(files: FileContent[]): Promise<DetectedCommand[]> {
const commands: DetectedCommand[] = [];
// Look for package.json to detect npm/node projects
const packageJson = files.find(f => f.path === 'package.json');
if (packageJson) {
try {
const pkg = JSON.parse(packageJson.content);
// Add install command
commands.push({
type: 'install',
command: 'npm install',
description: 'Install dependencies'
});
// Add dev command if it exists
if (pkg.scripts?.dev) {
commands.push({
type: 'dev',
command: 'npm run dev',
description: 'Start development server'
});
}
// Add build command if it exists
if (pkg.scripts?.build) {
commands.push({
type: 'build',
command: 'npm run build',
description: 'Build the project'
});
}
} catch (e) {
console.error('Error parsing package.json:', e);
}
}
return commands;
}
export function createCommandsMessage(commands: DetectedCommand[]): Message | null {
if (commands.length === 0) {
return null;
}
const commandsContent = commands.map(cmd =>
`<boltAction type="shell" title="${cmd.description}">
${cmd.command}
</boltAction>`
).join('\n');
return {
role: 'assistant',
content: `Here are the available commands for this project:
<boltArtifact id="project-commands" title="Project Commands">
${commandsContent}
</boltArtifact>`,
id: generateId(),
createdAt: new Date()
};
}