-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployService.js
More file actions
30 lines (26 loc) · 1.15 KB
/
Copy pathdeployService.js
File metadata and controls
30 lines (26 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Router } from 'express';
import projectService from '../services/projectService.js';
import { buildDeployPlan, summarizeDeploy } from '../services/deployService.js';
const router = Router();
// Generate a deploy plan (config files) for a project
router.post('/plan', (req, res) => {
try {
const { projectId, name, owner } = req.body;
const ws = projectService.getWorkspace(projectId);
const files = projectService.listFiles(ws.dir).map(f => ({ path: f.path, content: f.contentPreview }));
const plan = buildDeployPlan({ name: name || 'my-app', files }, { owner });
res.json(plan);
} catch (e) { res.status(400).json({ error: e.message }); }
});
// Write the generated deploy config files into the project workspace
router.post('/apply', (req, res) => {
try {
const { projectId, generatedFiles } = req.body;
for (const f of generatedFiles || []) {
projectService.writeFileText(projectId, f.path, f.content);
}
const ws = projectService.getWorkspace(projectId);
res.json({ ok: true, files: projectService.listFiles(ws.dir) });
} catch (e) { res.status(400).json({ error: e.message }); }
});
export default router;