Skip to content
Myr

render.ts

This file

Path

packages/drafting/src/render.ts

62 lines · 1.9 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

lines 1–3why, one step back
1// The model never writes the `.ask.ts` source: every string it gave enters the
2// file through `JSON.stringify`, as a string literal. Only the test file is3// the model's own text.

Merge branch 'build/908-drafter-workers-ai'oscabrielbefore adoption004e40e

lines 4–62why, one step back
4import { Brand } from "@repo/brand";
5import type { ConfigFile } from "@repo/protocol/domain/common";6import { RepoPath } from "@repo/protocol/ids";78import type { DraftedAsk } from "./drafted.ts";910const text = (value: string) => JSON.stringify(value);1112const list = (values: readonly string[]) => `[${values.map(text).join(", ")}]`;1314const kindHandle = { fix: "kinds.fix" } as const satisfies Record<15 DraftedAsk["kind"],16 string17>;1819export const renderAskFile = (drafted: DraftedAsk): string => {20 const fields: readonly (readonly [string, string | undefined])[] = [21 [22 "context",23 drafted.context === undefined || drafted.context.length === 024 ? undefined25 : list(drafted.context),26 ],27 [28 "current",29 drafted.current === undefined ? undefined : text(drafted.current),30 ],31 [32 "outOfScope",33 drafted.outOfScope === undefined || drafted.outOfScope.length === 034 ? undefined35 : list(drafted.outOfScope),36 ],37 ["path", text(drafted.test.path)],38 ["territory", `territory.paths(${drafted.territory.map(text).join(", ")})`],39 ["want", text(drafted.want)],40 ];4142 return [43 `import { kinds, territory } from ${text(`${Brand.cliPackage}/rules`)};`,44 "",45 `export default ${kindHandle[drafted.kind]}.ask({`,46 ...fields.flatMap(([key, value]) =>47 value === undefined ? [] : [` ${key}: ${value},`]48 ),49 "});",50 "",51 ].join("\n");52};5354export const draftedFiles = (55 drafted: DraftedAsk56): readonly [ConfigFile, ConfigFile] => [57 {58 content: renderAskFile(drafted),59 path: RepoPath.make(`${Brand.configDir}/asks/${drafted.id}.ask.ts`),60 },61 { content: drafted.test.source, path: drafted.test.path },62];