-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathblockDevelopmentDocs.ts
111 lines (99 loc) · 2.69 KB
/
blockDevelopmentDocs.ts
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { z } from "zod";
import { base } from "../base.js";
import { CommandPhase } from "./phases.js";
const zInnerSection = z.object({
contents: z.string(),
heading: z.string(),
});
type InnerSection = z.infer<typeof zInnerSection>;
function printInnerSection(innerSection: InnerSection) {
return [`### ${innerSection.heading}`, ``, innerSection.contents];
}
const zSection = z.object({
contents: z
.union([
z.string(),
z.object({
after: z.array(z.string()).optional(),
before: z.string().optional(),
items: z.array(z.string()).optional(),
plural: z.string().optional(),
}),
])
.optional(),
innerSections: z.array(zInnerSection).optional(),
});
type Section = z.infer<typeof zSection>;
function printSection(heading: string, section: Section) {
const innerSections = section.innerSections?.flatMap(printInnerSection) ?? [];
if (section.contents === undefined) {
return innerSections;
}
const contents =
typeof section.contents === "string"
? { before: section.contents }
: section.contents;
return [
`## ${heading}`,
``,
...(contents.before ? [contents.before] : []),
...(contents.items?.sort((a, b) =>
a.replaceAll("`", "").localeCompare(b.replaceAll("`", "")),
) ?? []),
...(contents.items?.length && contents.plural ? [``, contents.plural] : []),
...(contents.after ?? []),
...innerSections,
];
}
export const blockDevelopmentDocs = base.createBlock({
about: {
name: "Development Docs",
},
addons: {
hints: z.array(z.string()).default([]),
sections: z.record(z.string(), zSection).default({}),
},
migrate() {
return {
scripts: [
{
commands: ["rm DEVELOPMENT.md"],
phase: CommandPhase.Migrations,
},
],
};
},
produce({ addons, options }) {
const lines = [
`# Development`,
``,
...(options.guide
? [
`> If you'd like a more guided walkthrough, see [${options.guide.title}](${options.guide.href}).`,
`> It'll walk you through the common activities you'll need to contribute.`,
``,
]
: []),
`After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation):`,
``,
`\`\`\`shell`,
`git clone https://github.com/(your-name-here)/${options.repository}`,
`cd ${options.repository}`,
`pnpm install`,
`\`\`\``,
``,
...(addons.hints.length ? [...addons.hints, ``] : []),
...Object.entries(addons.sections)
.sort(([a], [b]) => a.localeCompare(b))
.flatMap(([heading, section]) => printSection(heading, section)),
...(options.documentation ? [options.documentation] : []),
];
return {
files: {
".github": {
"DEVELOPMENT.md": lines.join("\n"),
},
},
};
},
});