Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
86 lines (72 loc) · 2.26 KB
/
Copy pathindex.ts
File metadata and controls
86 lines (72 loc) · 2.26 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
import { parseArgs } from "util";
const { positionals } = parseArgs({
args: Bun.argv.slice(2),
allowPositionals: true,
strict: true,
});
const command = positionals[0];
switch (command) {
case "start": {
const { startServer } = await import("./src/server/index.ts");
await startServer();
break;
}
case "validate": {
const files = positionals.slice(1);
if (files.length === 0) {
console.error("Usage: trigger validate <file.yaml> [file2.yaml ...]");
process.exit(1);
}
const { env } = await import("./src/env.ts");
const { logger } = await import("./src/logger.ts");
const { initBuiltinActions } = await import("./src/pipeline/executor.ts");
const { loadCustomActions } = await import("./src/pipeline/action-loader.ts");
const { rebuildConfigSchema, getActiveSchema } = await import("./src/config/loader.ts");
logger.level = "silent";
initBuiltinActions();
await loadCustomActions(env.ACTIONS_DIR);
rebuildConfigSchema();
const schema = getActiveSchema();
let hasErrors = false;
for (const file of files) {
const bunFile = Bun.file(file);
if (!(await bunFile.exists())) {
console.error(`\x1b[31m✗\x1b[0m ${file}: file not found`);
hasErrors = true;
continue;
}
const text = await bunFile.text();
let parsed: unknown;
try {
parsed = Bun.YAML.parse(text);
} catch (err) {
console.error(`\x1b[31m✗\x1b[0m ${file}: YAML parse error — ${err instanceof Error ? err.message : err}`);
hasErrors = true;
continue;
}
const result = schema.safeParse(parsed);
if (result.success) {
console.log(`\x1b[32m✓\x1b[0m ${file}`);
} else {
hasErrors = true;
console.error(`\x1b[31m✗\x1b[0m ${file}:`);
for (const issue of result.error.issues) {
console.error(` ${issue.path.join(".") || "/"}: ${issue.message}`);
}
}
}
process.exit(hasErrors ? 1 : 0);
break;
}
default:
console.error(
`Usage: trigger <command>
Commands:
start Start the server
validate Validate YAML pipeline config files
Examples:
bun index.ts start
bun index.ts validate configs/*.yaml`,
);
process.exit(1);
}