@morlay/dsh-context-assembler 0.0.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tool/patch.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { entryListSchema } from "@deepseek-ai/cordis-plugin-include";
5
+ import yaml from "js-yaml";
6
+ import { PATCH_ROWS } from "../src/rows.ts";
7
+
8
+ /**
9
+ * bundle patch 的真源:把 {@link PATCH_ROWS}(`src/rows.ts` 那一份清单)写成 `cordis.patch.yml`。
10
+ *
11
+ * 本包有两种采用方式(见 `src/rows.ts`):`dsh.profile.bundles` 直接列出本包时用这份 patch;由
12
+ * preset 引用时走 preset 自己的行清单——**同一份真源**,不会两边漂移。
13
+ */
14
+
15
+ export const PATCH_FILE = "cordis.patch.yml";
16
+
17
+ const HEADER = `# 本文件由 packages/context/dsh-context-assembler/tool/patch.ts 生成,请勿手工编辑
18
+ `;
19
+
20
+ export function renderPatch(): string {
21
+ const body = yaml.dump([...PATCH_ROWS], {
22
+ schema: entryListSchema,
23
+ lineWidth: -1,
24
+ quotingType: '"',
25
+ });
26
+ return `${HEADER}${body}`;
27
+ }
28
+
29
+ /** 把 bundle patch 落到包根:它是发布产物的一部分(`files` 里有它,装配按出口解析)。 */
30
+ export async function generatePatch(): Promise<string> {
31
+ const path = join(resolve(dirname(fileURLToPath(import.meta.url)), ".."), PATCH_FILE);
32
+ await writeFile(path, renderPatch());
33
+ return path;
34
+ }
35
+
36
+ /** tsdown 的 `build:done` 钩子:每次构建重写 `cordis.patch.yml`,入库的那份因此永远等于 `PATCH_ROWS`。 */
37
+ export function patchHooks(): { "build:done": () => Promise<void> } {
38
+ return {
39
+ "build:done": async () => {
40
+ process.stdout.write(`generated ${await generatePatch()}\n`);
41
+ },
42
+ };
43
+ }