forked from BeOnAuto/auto-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-codegen.ts
More file actions
48 lines (40 loc) · 1.58 KB
/
run-codegen.ts
File metadata and controls
48 lines (40 loc) · 1.58 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
import { execSync } from 'child_process';
import * as path from 'path';
import * as fs from 'fs';
const QUERY_FILES = ['queries.ts', 'mutations.ts'];
const GRAPHQL_DIR = 'src/graphql';
function runCommand(cmd: string, cwd: string): string {
try {
return execSync(cmd, { cwd, encoding: 'utf-8', stdio: 'pipe' });
} catch (e) {
const error = e as { stdout?: Buffer; stderr?: Buffer; message?: string };
let output = '';
if (error.stdout) output += error.stdout.toString();
if (error.stderr) output += error.stderr.toString();
if (!output && error.message != null) output = error.message;
return output;
}
}
export function runCodegen(projectPath: string): void {
const resolvedPath = path.resolve(projectPath);
if (!fs.existsSync(resolvedPath)) {
throw new Error(`❌ Project path does not exist: ${resolvedPath}`);
}
const schemaPath = path.join(resolvedPath, 'schema.graphql');
if (!fs.existsSync(schemaPath)) {
throw new Error(`❌ Schema file not found at ${schemaPath}`);
}
const filePaths = QUERY_FILES.map((file) => path.join(resolvedPath, GRAPHQL_DIR, file));
for (const file of filePaths) {
if (!fs.existsSync(file)) {
console.warn(`⚠️ File not found, skipping: ${file}`);
}
}
console.log('▶ Installing dependencies via `npx pnpm` in', resolvedPath);
const installOutput = runCommand('npx pnpm install', resolvedPath);
console.log(installOutput);
console.log('\n▶ Running codegen...');
const output = runCommand('npx pnpm codegen', resolvedPath);
console.log(output);
console.log('✅ Codegen completed.');
}