Repository navigation
Expand file tree
/
Copy pathProjectManagerAgent.js
More file actions
286 lines (229 loc) · 8.86 KB
/
Copy pathProjectManagerAgent.js
File metadata and controls
286 lines (229 loc) · 8.86 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import fs from "fs/promises";
import path from "path";
import { exec } from "child_process";
import util from "util";
import chalk from "chalk";
import FileManager from "./fileManager.js";
import CodeAnalyzer from "./codeAnalyzer.js";
import TesterAgent from "./TesterAgent.js";
import DevOpsAgent from "./DevOpsAgent.js";
const execPromise = util.promisify(exec);
const ProjectManagerAgent = {
async run(projectStructure, readme) {
console.log(chalk.cyan("🚀 Project Manager Agent starting..."));
await this.buildApp();
await this.runTests();
await this.performUIChecks();
await this.checkDependencies();
await this.optimizeAssets();
await this.monitorPerformance();
await this.generateDockerfile();
await this.setupCICD();
await this.generateChangeLog();
await this.setupEnvironmentConfig();
await this.generateBuildScript();
await this.orchestrateAgents(projectStructure, readme);
console.log(chalk.green("✅ Project Manager Agent completed its tasks."));
},
async orchestrateAgents(projectStructure, readme) {
console.log(chalk.yellow("Orchestrating other agents..."));
await TesterAgent.run(projectStructure, readme);
await DevOpsAgent.run(projectStructure, readme);
},
async buildApp() {
console.log(chalk.yellow("Building the application..."));
try {
const { stdout, stderr } = await execPromise("npm run build");
console.log(chalk.green("Build output:"), stdout);
if (stderr) {
console.error(chalk.red("Build errors:"), stderr);
}
} catch (error) {
console.error(chalk.red("Error building the application:"), error);
}
},
async runTests() {
console.log(chalk.yellow("Running tests..."));
try {
const { stdout, stderr } = await execPromise("npm test");
console.log(chalk.green("Test output:"), stdout);
if (stderr) {
console.error(chalk.red("Test errors:"), stderr);
}
} catch (error) {
console.error(chalk.red("Error running tests:"), error);
}
},
async performUIChecks() {
console.log(chalk.yellow("Performing basic UI checks..."));
const uiFiles = await this.findUIFiles();
for (const file of uiFiles) {
await this.checkUIFile(file);
}
},
async findUIFiles() {
const files = await FileManager.getFilesToProcess();
return files.filter((file) => {
const ext = path.extname(file).toLowerCase();
return [".html", ".js", ".jsx", ".ts", ".tsx"].includes(ext);
});
},
async checkUIFile(file) {
console.log(chalk.blue(`Checking UI file: ${file}`));
const content = await FileManager.read(file);
const issues = await CodeAnalyzer.analyzeUICode(content);
if (issues.length > 0) {
console.log(chalk.yellow(`UI issues found in ${file}:`));
issues.forEach((issue) => console.log(chalk.yellow(`- ${issue}`)));
} else {
console.log(chalk.green(`No UI issues found in ${file}`));
}
},
async generateBuildScript() {
console.log(chalk.yellow("Generating build script..."));
const buildScript = `
#!/bin/bash
set -e
echo "Installing dependencies..."
npm install
echo "Running linter..."
npm run lint
echo "Running tests..."
npm test
echo "Building the application..."
npm run build
echo "Build completed successfully!"
`.trim();
await FileManager.write("build.sh", buildScript);
await fs.chmod("build.sh", "755");
console.log(chalk.green("Build script generated: build.sh"));
},
async checkDependencies() {
console.log(chalk.yellow("Checking project dependencies..."));
try {
const { stdout, stderr } = await execPromise("npm outdated --json");
if (stdout) {
const outdatedDeps = JSON.parse(stdout);
if (Object.keys(outdatedDeps).length > 0) {
console.log(chalk.yellow("Outdated dependencies found:"));
for (const [dep, info] of Object.entries(outdatedDeps)) {
console.log(chalk.yellow(`- ${dep}: ${info.current} -> ${info.latest}`));
}
} else {
console.log(chalk.green("All dependencies are up to date."));
}
}
if (stderr) {
console.error(chalk.red("Error checking dependencies:"), stderr);
}
} catch (error) {
console.error(chalk.red("Error checking dependencies:"), error);
}
},
async optimizeAssets() {
console.log(chalk.yellow("Optimizing assets..."));
const assetExtensions = [".jpg", ".jpeg", ".png", ".svg", ".gif"];
const files = await FileManager.getFilesToProcess();
const assetFiles = files.filter((file) => assetExtensions.includes(path.extname(file).toLowerCase()));
for (const file of assetFiles) {
console.log(chalk.blue(`Optimizing asset: ${file}`));
try {
if (path.extname(file).toLowerCase() === ".svg") {
await this.optimizeSVG(file);
} else {
await this.optimizeImage(file);
}
} catch (error) {
console.error(chalk.red(`Error optimizing ${file}:`), error);
}
}
},
async optimizeSVG(file) {
const { stdout, stderr } = await execPromise(`svgo ${file}`);
if (stdout) console.log(chalk.green(stdout));
if (stderr) console.error(chalk.red(stderr));
},
async optimizeImage(file) {
const { stdout, stderr } = await execPromise(`imagemin ${file} --out-dir=./optimized`);
if (stdout) console.log(chalk.green(stdout));
if (stderr) console.error(chalk.red(stderr));
},
async monitorPerformance() {
console.log(chalk.yellow("Monitoring application performance..."));
try {
const { stdout, stderr } = await execPromise("node --prof app.js");
if (stdout) console.log(chalk.green("Performance data collected."));
if (stderr) console.error(chalk.red("Error collecting performance data:"), stderr);
await execPromise("node --prof-process isolate-*-v8.log > processed.txt");
console.log(chalk.green("Performance data processed. Check processed.txt for results."));
} catch (error) {
console.error(chalk.red("Error monitoring performance:"), error);
}
},
async generateDockerfile() {
console.log(chalk.yellow("Generating Dockerfile..."));
const dockerfileContent = `
FROM node:14
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
`.trim();
await FileManager.write("Dockerfile", dockerfileContent);
console.log(chalk.green("Dockerfile generated."));
},
async setupCICD() {
console.log(chalk.yellow("Setting up CI/CD configuration..."));
const githubWorkflowContent = `
name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm ci
- run: npm run build --if-present
- run: npm test
`.trim();
await FileManager.write(".github/workflows/ci-cd.yml", githubWorkflowContent);
console.log(chalk.green("GitHub Actions workflow configured."));
},
async generateChangeLog() {
console.log(chalk.yellow("Generating changelog..."));
try {
const { stdout, stderr } = await execPromise('git log --pretty=format:"%h - %s (%cr)" --abbrev-commit');
if (stdout) {
await FileManager.write("CHANGELOG.md", `# Changelog\n\n${stdout}`);
console.log(chalk.green("Changelog generated: CHANGELOG.md"));
}
if (stderr) console.error(chalk.red("Error generating changelog:"), stderr);
} catch (error) {
console.error(chalk.red("Error generating changelog:"), error);
}
},
async setupEnvironmentConfig() {
console.log(chalk.yellow("Setting up environment configuration..."));
const envExampleContent = `
NODE_ENV=development
PORT=3000
DATABASE_URL=mongodb://localhost:27017/myapp
JWT_SECRET=your_jwt_secret_here
`.trim();
await FileManager.write(".env.example", envExampleContent);
console.log(chalk.green(".env.example file created."));
console.log(chalk.yellow("Remember to create a .env file with your actual configuration."));
},
};
export default ProjectManagerAgent;