Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template selection #1051

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/prompts/architect/select_templates.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ Here is a high level description of "{{ state.branch.project.name }}":
{{ state.specification.description }}
```

You have an option to use project templates that implement standard boilerplate/scaffolding so you can start faster and be more productive. To be considered, a template must be compatible with the project requirements (it doesn't need to implement everything that will be used in the project, just a useful subset of needed technologies). You should pick one template that's the best match for this project.
You have an option to use project templates that implement standard boilerplate/scaffolding so you can start faster and be more productive. To be considered, a template must be compatible with the project requirements:
* if the project description has specific technology requirements, don't consider templates that choose different tech (eg. a different framework or library)
* to be considered, the template must use compatible technologies and implement a useful subset of required functionality

If no project templates are a good match, don't pick any! It's better to start from scratch than to use a template that is not a good fit for the project and then spend time reworking it to fit the requirements.
If no project templates are a good match, don't pick any! It's better to start from scratch than to use a template that is not a good fit for the project (for example, don't use a react frontend if a different framework or plain html/css is required) and then spend time reworking it to fit the requirements. If you do choose to pick a template, choose the one that's the best match for this project.

Here are the available project templates:

{% for template in templates.values() %}
### {{ template.name }} ({{ template.stack }})

{{ template.description }}

Contains:
{{ template.summary }}
{% endfor %}

{% endfor %}
Output your response in a valid JSON format like in this example:
```json
{
Expand Down
21 changes: 19 additions & 2 deletions core/templates/tree/react_express/api/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import path from 'path';
import { existsSync } from 'fs';
import { fileURLToPath } from 'node:url';

import cors from 'cors';
import express from 'express';
Expand All @@ -9,6 +11,9 @@ import { authenticateWithToken } from './middlewares/authMiddleware.js';
{% endif %}
import apiRoutes from './routes/index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Set up Express app
const app = express();

Expand All @@ -29,10 +34,22 @@ app.use(authenticateWithToken);

app.use(apiRoutes);

app.use(express.static(path.join(import.meta.dirname, "..", "dist")));
app.use(express.static(path.join(__dirname, "..", "dist")));

// Assume all other routes are frontend and serve pre-built frontend from ../dist/ folder
// Assume all other routes are frontend
app.get(/.*/, async (req, res) => {
// Try to serve pre-built frontend from ../dist/ folder
const clientBundlePath = path.join(__dirname, "..", "dist", "index.html");

if (!existsSync(clientBundlePath)) {
if (process.env.NODE_ENV === "development") {
// In development, we just want to redirect to the Vite dev server
return res.redirect("http://localhost:5173");
} else {
// Looks like "npm run build:ui" wasn't run and the UI isn't built, show a nice error message instead
return res.status(404).send("Front-end not available.");
}
}
res.sendFile(path.join(import.meta.dirname, "..", "dist", "index.html"));
});

Expand Down
Loading