Repository navigation
Expand file tree
/
Copy pathrender-workflow.ts
More file actions
69 lines (65 loc) · 1.94 KB
/
Copy pathrender-workflow.ts
File metadata and controls
69 lines (65 loc) · 1.94 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
import {
defineSlopcameraWorkflow,
runSlopcameraWorkflow,
} from "@hraness/slopcamera/workflow"
interface RenderWorkflowInput {
readonly path: string
readonly outDirectory?: string
}
function parseInput(value: unknown): RenderWorkflowInput {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
throw new Error("Workflow input must be an object.")
}
const path = Reflect.get(value, "path")
const outDirectory = Reflect.get(value, "outDirectory")
if (typeof path !== "string" || path.length < 1) {
throw new Error("Workflow input requires path.")
}
if (outDirectory !== undefined && typeof outDirectory !== "string") {
throw new Error("outDirectory must be a string when provided.")
}
return {
path,
...(outDirectory === undefined ? {} : { outDirectory }),
}
}
export const checkedRenderWorkflow = defineSlopcameraWorkflow({
id: "checked-render",
version: 1,
parseInput,
async run(workflow, input) {
const checked = await workflow.operation(
"check-source",
"slopcamera.diagram.check",
{ path: input.path },
)
if (checked.findings.length > 0) {
throw new Error("Diagram has lint findings; render was skipped.")
}
const rendered = await workflow.operation(
"render-assets",
"slopcamera.diagram.render",
{
path: input.path,
...(input.outDirectory === undefined
? {}
: { outDirectory: input.outDirectory }),
},
)
return {
artifacts: rendered.artifacts,
findingCount: checked.findings.length,
}
},
})
if (import.meta.main) {
const path = Bun.argv[2]
if (path === undefined) {
throw new Error("Usage: bun run examples/render-workflow.ts <diagram> [out-dir]")
}
const result = await runSlopcameraWorkflow(checkedRenderWorkflow, {
path,
...(Bun.argv[3] === undefined ? {} : { outDirectory: Bun.argv[3] }),
})
console.log(JSON.stringify(result, null, 2))
}