mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
feat: git clone by url
ability to git clone by url
This commit is contained in:
75
app/utils/projectCommands.ts
Normal file
75
app/utils/projectCommands.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
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()
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user