Skip to content

Commit f708b9e

Browse files
committed
add css generate prompt
1 parent a6d713a commit f708b9e

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

backend/src/build-system/handlers/frontend-code-generate/index.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from 'src/build-system/utils/database-utils';
1919

2020
// The function from step #1
21-
import { generateFrontEndCodePrompt } from './prompt';
21+
import { generateFrontEndCodePrompt, generateCSSPrompt } from './prompt';
2222

2323
/**
2424
* FrontendCodeHandler is responsible for generating the frontend codebase
@@ -61,6 +61,8 @@ export class FrontendCodeHandler implements BuildHandler<string> {
6161
path.resolve(frontendPath, 'src', file),
6262
);
6363

64+
const extension = currentFullFilePath.split('.').pop() || '';
65+
6466
// Retrieve the direct dependencies for this file
6567
const directDepsArray = fileInfos[file]?.dependsOn || [];
6668

@@ -96,15 +98,30 @@ export class FrontendCodeHandler implements BuildHandler<string> {
9698
`2 Generating file in dependency order directDependencies: ${directDependencies}`,
9799
);
98100

99-
// Generate the prompt
100-
const frontendCodePrompt = generateFrontEndCodePrompt(
101-
sitemapDoc,
102-
uxDataMapDoc,
103-
backendRequirementDoc.overview,
104-
currentFullFilePath,
105-
directDependencies,
106-
dependenciesContext,
101+
let frontendCodePrompt = '';
102+
103+
if (extension === 'css') {
104+
frontendCodePrompt = generateCSSPrompt(
105+
file,
106+
directDependencies,
107+
dependenciesContext,
108+
);
109+
} else {
110+
// Generate the prompt
111+
frontendCodePrompt = generateFrontEndCodePrompt(
112+
sitemapDoc,
113+
uxDataMapDoc,
114+
backendRequirementDoc.overview,
115+
file,
116+
directDependencies,
117+
dependenciesContext,
118+
);
119+
}
120+
this.logger.log(
121+
'generate code prompt for frontendCodePrompt or css: ' +
122+
frontendCodePrompt,
107123
);
124+
108125
this.logger.debug('Generated frontend code prompt.');
109126

110127
let generatedCode = '';

backend/src/build-system/handlers/frontend-code-generate/prompt.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,33 @@ export const generateFrontEndCodePrompt = (
6060
6161
`;
6262
};
63+
64+
export function generateCSSPrompt(
65+
fileName: string,
66+
directDependencies: string,
67+
dependenciesContext: string,
68+
): string {
69+
return `
70+
You are an expert CSS developer. Generate valid, production-ready CSS for the file "${fileName}".
71+
72+
## Context
73+
- Direct Dependencies (if any and may include references to other styles or partials):
74+
${directDependencies}
75+
76+
- Direct Dependencies Context (if any):
77+
${dependenciesContext}
78+
79+
## Rules & Guidelines
80+
1. **Do NOT** include any JavaScript or React code—only plain CSS.
81+
2. **Do NOT** wrap your output in code fences (\`\`\`).
82+
3. You may define classes, IDs, or any selectors you need, but **be sure** to keep it purely CSS.
83+
4. Ensure the output is well-structured, readable, and adheres to best practices (e.g., BEM if you prefer).
84+
5. Include comments for clarity if needed, but keep them concise.
85+
86+
## Output Format
87+
Please produce the complete CSS content in the format described:
88+
<GENERATE>
89+
/* Your CSS content here */
90+
</GENERATE>
91+
`;
92+
}

0 commit comments

Comments
 (0)