Skip to content

Commit 2c41380

Browse files
authoredApr 2, 2025··
fix: preserve additional README.md content in transition (#2090)
## PR Checklist - [x] Addresses an existing open issue: fixes #2088 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Switches from two string docs options -`documentation` and `usage` to an object with: * `development` * `readme`: * `additional` * `usage` `readme.additional` is a new field that takes in content from `README.md` after a contributors table, if it exists. 🎁
1 parent 5bbf8be commit 2c41380

17 files changed

+283
-90
lines changed
 

Diff for: ‎docs/Configuration Files.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ These options are generally only programmatically used internally, but can still
2222
| Option | Description | Default (If Available) |
2323
| ------------------- | ------------------------------------------------------------------------ | --------------------------------------------------------- |
2424
| `contributors` | AllContributors contributors to store in `.all-contributorsrc` | Existing contributors in the file, or just your username |
25-
| `documentation` | any additional docs to add to `.github/DEVELOPMENT.md` | Extra content in `.github/DEVELOPMENT.md` |
25+
| `documentation` | additional docs to add to `.github/DEVELOPMENT.md` and/or `README.md` | Extra content in those two files |
2626
| `existingLabels` | existing labels to switch to the standard template labels | Existing labels on the repository from the GitHub API |
2727
| `explainer` | additional `README.md` sentence(s) describing the package | Extra content in `README.md` after badges and description |
2828
| `guide` | link to a contribution guide to place at the top of development docs | Block quote on top of `.github/DEVELOPMENT.md` |
2929
| `logo` | local image file and alt text to display near the top of the `README.md` | First non-badge image's `alt` and `src` in `README.md` |
3030
| `node` | Node.js engine version(s) to pin and require a minimum of | Values from `.nvmrc` and `package.json`'s `"engines"` |
3131
| `packageData` | additional properties to include in `package.json` | Existing values in `package.json` |
3232
| `rulesetId` | GitHub branch ruleset ID for main branch protections | Existing ruleset on the `main` branch from the GitHub API |
33-
| `usage` | Markdown docs to put in `README.md` under the `## Usage` heading | Existing usage lines in `README.md` |
3433
| `workflowsVersions` | existing versions of GitHub Actions workflows used | Existing action versions in `.github/workflows/*.yml` |
3534

3635
For example, changing `node` versions to values different from what would be inferred:

Diff for: ‎src/base.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ describe("base", () => {
2020
).contributors,
2121
description:
2222
"Quickstart-friendly TypeScript template with comprehensive, configurable, opinionated tooling. 🎁",
23-
documentation: "",
23+
documentation: {
24+
development: expect.any(String),
25+
readme: {
26+
additional: expect.any(String),
27+
usage: expect.any(String),
28+
},
29+
},
2430
email: {
2531
github: "github@joshuakgoldberg.com",
2632
npm: "npm@joshuakgoldberg.com",
@@ -51,7 +57,6 @@ describe("base", () => {
5157
pnpm: expect.any(String),
5258
repository: "create-typescript-app",
5359
title: "Create TypeScript App",
54-
usage: expect.any(String),
5560
version: expect.any(String),
5661
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-require-imports
5762
words: require("../cspell.json").words,

Diff for: ‎src/base.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { readAllContributors } from "./options/readAllContributors.js";
99
import { readAuthor } from "./options/readAuthor.js";
1010
import { readBin } from "./options/readBin.js";
1111
import { readDescription } from "./options/readDescription.js";
12+
import { readDevelopmentDocumentation } from "./options/readDevelopmentDocumentation.js";
1213
import { readDocumentation } from "./options/readDocumentation.js";
1314
import { readEmailFromCodeOfConduct } from "./options/readEmailFromCodeOfConduct.js";
1415
import { readEmailFromGit } from "./options/readEmailFromGit.js";
@@ -28,13 +29,14 @@ import { readOwner } from "./options/readOwner.js";
2829
import { readPackageAuthor } from "./options/readPackageAuthor.js";
2930
import { readPackageData } from "./options/readPackageData.js";
3031
import { readPnpm } from "./options/readPnpm.js";
32+
import { readReadmeAdditional } from "./options/readReadmeAdditional.js";
33+
import { readReadmeUsage } from "./options/readReadmeUsage.js";
3134
import { readRepository } from "./options/readRepository.js";
3235
import { readRulesetId } from "./options/readRulesetId.js";
3336
import { readTitle } from "./options/readTitle.js";
34-
import { readUsage } from "./options/readUsage.js";
3537
import { readWords } from "./options/readWords.js";
3638
import { readWorkflowsVersions } from "./options/readWorkflowsVersions.js";
37-
import { zContributor, zWorkflowsVersions } from "./schemas.js";
39+
import { zContributor, zDocumentation, zWorkflowsVersions } from "./schemas.js";
3840

3941
export const base = createBase({
4042
options: {
@@ -58,10 +60,9 @@ export const base = createBase({
5860
.default("A very lovely package. Hooray!")
5961
.describe("'Sentence case.' description of the repository"),
6062
directory: z.string().describe("Directory to create the repository in"),
61-
documentation: z
62-
.string()
63-
.optional()
64-
.describe("any additional docs to add to .github/DEVELOPMENT.md"),
63+
documentation: zDocumentation.describe(
64+
"additional docs to add to .md files",
65+
),
6566
email: z
6667
.union([
6768
z.string(),
@@ -154,10 +155,6 @@ export const base = createBase({
154155
.optional()
155156
.describe("GitHub branch ruleset ID for main branch protections"),
156157
title: z.string().describe("'Title Case' title for the repository"),
157-
usage: z
158-
.string()
159-
.optional()
160-
.describe("Markdown docs to put in README.md under the ## Usage heading"),
161158
version: z
162159
.string()
163160
.optional()
@@ -190,8 +187,17 @@ export const base = createBase({
190187
async () => await readDescription(getPackageData, getReadme),
191188
);
192189

190+
const getDevelopmentDocumentation = lazyValue(
191+
async () => await readDevelopmentDocumentation(take),
192+
);
193+
193194
const getDocumentation = lazyValue(
194-
async () => await readDocumentation(take),
195+
async () =>
196+
await readDocumentation(
197+
getDevelopmentDocumentation,
198+
getReadmeAdditional,
199+
getReadmeUsage,
200+
),
195201
);
196202

197203
const getEmail = lazyValue(
@@ -263,6 +269,14 @@ export const base = createBase({
263269
async () => await readFileSafe("README.md", ""),
264270
);
265271

272+
const getReadmeAdditional = lazyValue(
273+
async () => await readReadmeAdditional(getReadme),
274+
);
275+
276+
const getReadmeUsage = lazyValue(
277+
async () => await readReadmeUsage(getEmoji, getReadme, getRepository),
278+
);
279+
266280
const getRepository = lazyValue(
267281
async () => await readRepository(getGitDefaults, getPackageData, options),
268282
);
@@ -275,10 +289,6 @@ export const base = createBase({
275289
async () => await readTitle(getReadme, getRepository),
276290
);
277291

278-
const getUsage = lazyValue(
279-
async () => await readUsage(getEmoji, getReadme, getRepository),
280-
);
281-
282292
const getVersion = lazyValue(async () => (await getPackageData()).version);
283293

284294
const getWords = lazyValue(async () => await readWords(take));
@@ -308,7 +318,6 @@ export const base = createBase({
308318
repository: getRepository,
309319
rulesetId: getRulesetId,
310320
title: getTitle,
311-
usage: getUsage,
312321
version: getVersion,
313322
words: getWords,
314323
workflowsVersions: getWorkflowData,

Diff for: ‎src/blocks/blockCSpell.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe("blockCSpell", () => {
280280
"scripts": [
281281
{
282282
"commands": [
283-
"node path/to/cspell-populate-words/bin/index.mjs --words "access" --words "public" --words "description" --words "Test description" --words "directory" --words "." --words "email" --words "github" --words "github@email.com" --words "npm" --words "npm@email.com" --words "emoji" --words "💖" --words "owner" --words "test-owner" --words "preset" --words "minimal" --words "repository" --words "test-repository" --words "title" --words "Test Title"",
283+
"node path/to/cspell-populate-words/bin/index.mjs --words "access" --words "public" --words "description" --words "Test description" --words "directory" --words "." --words "documentation" --words "readme" --words "usage" --words "Test usage." --words "email" --words "github" --words "github@email.com" --words "npm" --words "npm@email.com" --words "emoji" --words "💖" --words "owner" --words "test-owner" --words "preset" --words "minimal" --words "repository" --words "test-repository" --words "title" --words "Test Title"",
284284
],
285285
"phase": 3,
286286
},

Diff for: ‎src/blocks/blockDevelopmentDocs.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ describe("blockDevelopmentDocs", () => {
149149
const creation = testBlock(blockDevelopmentDocs, {
150150
options: {
151151
...optionsBase,
152-
documentation: "More documentation.",
152+
documentation: {
153+
...optionsBase.documentation,
154+
development: "More documentation.",
155+
},
153156
},
154157
});
155158

Diff for: ‎src/blocks/blockDevelopmentDocs.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export const blockDevelopmentDocs = base.createBlock({
8787
...Object.entries(addons.sections)
8888
.sort(([a], [b]) => a.localeCompare(b))
8989
.flatMap(([heading, section]) => printSection(heading, section)),
90-
...(options.documentation ? [options.documentation] : []),
90+
...(options.documentation.development
91+
? [options.documentation.development]
92+
: []),
9193
];
9294

9395
return {

Diff for: ‎src/blocks/blockREADME.test.ts

+56-22
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import { describe, expect, test } from "vitest";
44
import { blockREADME } from "./blockREADME.js";
55
import { optionsBase } from "./options.fakes.js";
66

7-
const options = {
8-
...optionsBase,
9-
usage: "Use it.",
10-
};
11-
127
describe("blockREADME", () => {
138
test("description with one sentence", () => {
149
const creation = testBlock(blockREADME, {
1510
options: {
16-
...options,
11+
...optionsBase,
1712
description: "One sentence.",
1813
},
1914
});
@@ -31,7 +26,7 @@ describe("blockREADME", () => {
3126
3227
## Usage
3328
34-
Use it.
29+
Test usage.
3530
3631
## Development
3732
@@ -47,7 +42,7 @@ describe("blockREADME", () => {
4742
test("description with two sentences", () => {
4843
const creation = testBlock(blockREADME, {
4944
options: {
50-
...options,
45+
...optionsBase,
5146
description: "First sentence. Second sentence.",
5247
},
5348
});
@@ -68,13 +63,54 @@ describe("blockREADME", () => {
6863
6964
## Usage
7065
66+
Test usage.
67+
68+
## Development
69+
70+
See [\`.github/CONTRIBUTING.md\`](./.github/CONTRIBUTING.md), then [\`.github/DEVELOPMENT.md\`](./.github/DEVELOPMENT.md).
71+
Thanks! 💖
72+
73+
",
74+
},
75+
}
76+
`);
77+
});
78+
79+
test("options.documentation", () => {
80+
const creation = testBlock(blockREADME, {
81+
options: {
82+
...optionsBase,
83+
documentation: {
84+
development: "Development docs.",
85+
readme: {
86+
additional: "Additional docs.",
87+
usage: "Use it.",
88+
},
89+
},
90+
},
91+
});
92+
93+
expect(creation).toMatchInlineSnapshot(`
94+
{
95+
"files": {
96+
"README.md": "<h1 align="center">Test Title</h1>
97+
98+
<p align="center">Test description</p>
99+
100+
<p align="center">
101+
<img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
102+
</p>
103+
104+
## Usage
105+
71106
Use it.
72107
73108
## Development
74109
75110
See [\`.github/CONTRIBUTING.md\`](./.github/CONTRIBUTING.md), then [\`.github/DEVELOPMENT.md\`](./.github/DEVELOPMENT.md).
76111
Thanks! 💖
77112
113+
Additional docs.
78114
",
79115
},
80116
}
@@ -84,7 +120,7 @@ describe("blockREADME", () => {
84120
test("options.explainer", () => {
85121
const creation = testBlock(blockREADME, {
86122
options: {
87-
...options,
123+
...optionsBase,
88124
explainer: ["And a one.", "And a two."],
89125
},
90126
});
@@ -105,7 +141,7 @@ describe("blockREADME", () => {
105141
106142
## Usage
107143
108-
Use it.
144+
Test usage.
109145
110146
## Development
111147
@@ -121,7 +157,7 @@ describe("blockREADME", () => {
121157
test("options.logo without sizing", () => {
122158
const creation = testBlock(blockREADME, {
123159
options: {
124-
...options,
160+
...optionsBase,
125161
logo: {
126162
alt: "My logo",
127163
src: "img.jpg",
@@ -144,7 +180,7 @@ describe("blockREADME", () => {
144180
145181
## Usage
146182
147-
Use it.
183+
Test usage.
148184
149185
## Development
150186
@@ -160,7 +196,7 @@ describe("blockREADME", () => {
160196
test("options.logo with sizing", () => {
161197
const creation = testBlock(blockREADME, {
162198
options: {
163-
...options,
199+
...optionsBase,
164200
logo: {
165201
alt: "My logo",
166202
height: 100,
@@ -185,7 +221,7 @@ describe("blockREADME", () => {
185221
186222
## Usage
187223
188-
Use it.
224+
Test usage.
189225
190226
## Development
191227
@@ -201,7 +237,7 @@ describe("blockREADME", () => {
201237
test("options.explainer and options.logo", () => {
202238
const creation = testBlock(blockREADME, {
203239
options: {
204-
...options,
240+
...optionsBase,
205241
explainer: ["And a one.", "And a two."],
206242
logo: {
207243
alt: "My logo",
@@ -230,7 +266,7 @@ describe("blockREADME", () => {
230266
231267
## Usage
232268
233-
Use it.
269+
Test usage.
234270
235271
## Development
236272
@@ -244,9 +280,7 @@ describe("blockREADME", () => {
244280
});
245281

246282
test("without addons", () => {
247-
const creation = testBlock(blockREADME, {
248-
options,
249-
});
283+
const creation = testBlock(blockREADME, { options: optionsBase });
250284

251285
expect(creation).toMatchInlineSnapshot(`
252286
{
@@ -261,7 +295,7 @@ describe("blockREADME", () => {
261295
262296
## Usage
263297
264-
Use it.
298+
Test usage.
265299
266300
## Development
267301
@@ -295,7 +329,7 @@ describe("blockREADME", () => {
295329
notices: ["> Hello, world! 💖"],
296330
sections: [`## Other\n\nHello!`],
297331
},
298-
options,
332+
options: optionsBase,
299333
});
300334

301335
expect(creation).toMatchInlineSnapshot(`
@@ -314,7 +348,7 @@ describe("blockREADME", () => {
314348
315349
## Usage
316350
317-
Use it.
351+
Test usage.
318352
319353
## Development
320354

Diff for: ‎src/blocks/blockREADME.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ ${formatBadges(badges)}
5454
${[logo, explainer].filter(Boolean).join("")}
5555
## Usage
5656
57-
${options.usage}
57+
${options.documentation.readme.usage}
5858
5959
## Development
6060
6161
See [\`.github/CONTRIBUTING.md\`](./.github/CONTRIBUTING.md), then [\`.github/DEVELOPMENT.md\`](./.github/DEVELOPMENT.md).
6262
Thanks! ${options.emoji}
63-
${sections.map((section) => `\n${section}`).join("")}
63+
${[...sections, options.documentation.readme.additional]
64+
.filter(Boolean)
65+
.map((section) => `\n${section}`)
66+
.join("")}
6467
${notices.length ? `\n${notices.map((notice) => notice.trim()).join("\n\n")}` : ""}`,
6568
},
6669
};

Diff for: ‎src/blocks/options.fakes.ts

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ export const optionsBase = {
44
access: "public",
55
description: "Test description",
66
directory: ".",
7+
documentation: {
8+
readme: {
9+
usage: "Test usage.",
10+
},
11+
},
712
email: {
813
github: "github@email.com",
914
npm: "npm@email.com",

Diff for: ‎src/options/readDocumentation.test.ts renamed to ‎src/options/readDevelopmentDocumentation.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { describe, expect, it } from "vitest";
22

3-
import { readDocumentation } from "./readDocumentation.js";
3+
import { readDevelopmentDocumentation } from "./readDevelopmentDocumentation.js";
44

5-
describe(readDocumentation, () => {
5+
describe(readDevelopmentDocumentation, () => {
66
it("returns undefined when no .github/DEVELOPMENT.md exists", async () => {
7-
const documentation = await readDocumentation(() =>
7+
const documentation = await readDevelopmentDocumentation(() =>
88
Promise.resolve(undefined),
99
);
1010

1111
expect(documentation).toBeUndefined();
1212
});
1313

1414
it("filters known headings when .github/DEVELOPMENT.md exists", async () => {
15-
const documentation = await readDocumentation(() =>
15+
const documentation = await readDevelopmentDocumentation(() =>
1616
Promise.resolve(`# Development\nremoved\n\n## Unknown\n\nKept.\n`),
1717
);
1818

Diff for: ‎src/options/readDevelopmentDocumentation.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { TakeInput } from "bingo";
2+
import { inputFromFile } from "input-from-file";
3+
4+
import { swallowError } from "../utils/swallowError.js";
5+
6+
const knownHeadings = new Set([
7+
"building",
8+
"development",
9+
"formatting",
10+
"linting",
11+
"testing",
12+
"type checking",
13+
]);
14+
15+
export async function readDevelopmentDocumentation(take: TakeInput) {
16+
const existing = swallowError(
17+
await take(inputFromFile, {
18+
filePath: ".github/DEVELOPMENT.md",
19+
}),
20+
);
21+
if (!existing) {
22+
return undefined;
23+
}
24+
25+
return existing
26+
.split(/\n\n(?=##\s)/)
27+
.filter((section) => !knownHeadings.has(parseHeading(section)))
28+
.join("\n\n");
29+
}
30+
31+
function parseHeading(section: string) {
32+
return section
33+
.split("\n")[0]
34+
.replace(/^#+\s+/, "")
35+
.trim()
36+
.toLowerCase();
37+
}

Diff for: ‎src/options/readDocumentation.ts

+18-34
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
1-
import { TakeInput } from "bingo";
2-
import { inputFromFile } from "input-from-file";
1+
import { Documentation } from "../schemas.js";
32

4-
import { swallowError } from "../utils/swallowError.js";
3+
export async function readDocumentation(
4+
getDevelopmentDocumentation: () => Promise<string | undefined>,
5+
getReadmeAdditional: () => Promise<string | undefined>,
6+
getReadmeUsage: () => Promise<string>,
7+
): Promise<Documentation> {
8+
const [additional, development, usage] = await Promise.all([
9+
getReadmeAdditional(),
10+
getDevelopmentDocumentation(),
11+
getReadmeUsage(),
12+
]);
513

6-
const knownHeadings = new Set([
7-
"building",
8-
"development",
9-
"formatting",
10-
"linting",
11-
"testing",
12-
"type checking",
13-
]);
14-
15-
export async function readDocumentation(take: TakeInput) {
16-
const existing = swallowError(
17-
await take(inputFromFile, {
18-
filePath: ".github/DEVELOPMENT.md",
19-
}),
20-
);
21-
if (!existing) {
22-
return undefined;
23-
}
24-
25-
return existing
26-
.split(/\n\n(?=##\s)/)
27-
.filter((section) => !knownHeadings.has(parseHeading(section)))
28-
.join("\n\n");
29-
}
30-
31-
function parseHeading(section: string) {
32-
return section
33-
.split("\n")[0]
34-
.replace(/^#+\s+/, "")
35-
.trim()
36-
.toLowerCase();
14+
return {
15+
development,
16+
readme: {
17+
additional,
18+
usage,
19+
},
20+
};
3721
}

Diff for: ‎src/options/readReadmeAdditional.test.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { readReadmeAdditional } from "./readReadmeAdditional.js";
4+
5+
describe(readReadmeAdditional, () => {
6+
it("returns undefined when there is no existing readme content", async () => {
7+
const getReadme = () => Promise.resolve("");
8+
9+
const result = await readReadmeAdditional(getReadme);
10+
11+
expect(result).toBeUndefined();
12+
});
13+
14+
it("returns undefined when there is no contributors indicator", async () => {
15+
const getReadme = () => Promise.resolve(`# My Package`);
16+
17+
const result = await readReadmeAdditional(getReadme);
18+
19+
expect(result).toBeUndefined();
20+
});
21+
22+
it("returns all content after contributors when there is no template notice", async () => {
23+
const getReadme = () =>
24+
Promise.resolve(`# My Package
25+
26+
Usage.
27+
28+
<!-- spellchecker:enable -->
29+
30+
After.
31+
`);
32+
33+
const result = await readReadmeAdditional(getReadme);
34+
35+
expect(result).toBe("After.");
36+
});
37+
38+
it("returns all content after contributors when there is a comment template notice", async () => {
39+
const getReadme = () =>
40+
Promise.resolve(`# My Package
41+
42+
Usage.
43+
44+
<!-- spellchecker:enable -->
45+
46+
After.
47+
48+
<!-- You can remove this notice if you don't want it 🙂 no worries! -->
49+
`);
50+
51+
const result = await readReadmeAdditional(getReadme);
52+
53+
expect(result).toBe("After.");
54+
});
55+
56+
it("returns all content after contributors when there is a quote template notice", async () => {
57+
const getReadme = () =>
58+
Promise.resolve(`# My Package
59+
60+
Usage.
61+
62+
<!-- spellchecker:enable -->
63+
64+
After.
65+
66+
> 💝 This package was templated with ...
67+
`);
68+
69+
const result = await readReadmeAdditional(getReadme);
70+
71+
expect(result).toBe("After.");
72+
});
73+
});

Diff for: ‎src/options/readReadmeAdditional.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const indicatorAfterContributors = /<!--\s*spellchecker:\s*enable\s*-->/;
2+
3+
const indicatorBeforeTemplatedBy =
4+
/> .* This package was templated with |<!-- You can remove this notice/;
5+
6+
export async function readReadmeAdditional(getReadme: () => Promise<string>) {
7+
const readme = await getReadme();
8+
if (!readme) {
9+
return undefined;
10+
}
11+
12+
const indexAfterContributors = indicatorAfterContributors.exec(readme);
13+
if (!indexAfterContributors) {
14+
return undefined;
15+
}
16+
17+
const templatedByMatch = indicatorBeforeTemplatedBy.exec(readme);
18+
19+
return readme
20+
.slice(
21+
indexAfterContributors.index + indexAfterContributors[0].length,
22+
templatedByMatch?.index,
23+
)
24+
.trim();
25+
}

Diff for: ‎src/options/readUsage.test.ts renamed to ‎src/options/readReadmeUsage.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from "vitest";
22

3-
import { readUsage } from "./readUsage.js";
3+
import { readReadmeUsage } from "./readReadmeUsage.js";
44

55
const mockReadUsageFromReadme = vi.fn();
66

@@ -10,13 +10,13 @@ vi.mock("./readUsageFromReadme.js", () => ({
1010
},
1111
}));
1212

13-
describe(readUsage, () => {
13+
describe(readReadmeUsage, () => {
1414
it("returns the existing usage when readUsageFromReadme provides one", async () => {
1515
const existing = "Use it.";
1616

1717
mockReadUsageFromReadme.mockReturnValueOnce(existing);
1818

19-
const usage = await readUsage(
19+
const usage = await readReadmeUsage(
2020
() => Promise.resolve("💖"),
2121
() => Promise.resolve(""),
2222
() => Promise.resolve(undefined),
@@ -28,7 +28,7 @@ describe(readUsage, () => {
2828
it("returns sample usage when readUsageFromReadme doesn't provide usage", async () => {
2929
mockReadUsageFromReadme.mockReturnValueOnce(undefined);
3030

31-
const usage = await readUsage(
31+
const usage = await readReadmeUsage(
3232
() => Promise.resolve("💖"),
3333
() => Promise.resolve(""),
3434
() => Promise.resolve("test-repository"),

Diff for: ‎src/options/readUsage.ts renamed to ‎src/options/readReadmeUsage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readUsageFromReadme } from "./readUsageFromReadme.js";
22

3-
export async function readUsage(
3+
export async function readReadmeUsage(
44
getEmoji: () => Promise<string>,
55
getReadme: () => Promise<string>,
66
getRepository: () => Promise<string | undefined>,

Diff for: ‎src/schemas.ts

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ export const zContributor = z.object({
1010

1111
export type Contributor = z.infer<typeof zContributor>;
1212

13+
export const zReadme = z.object({
14+
additional: z.string().optional(),
15+
usage: z.string(),
16+
});
17+
18+
export type Readme = z.infer<typeof zReadme>;
19+
20+
export const zDocumentation = z.object({
21+
development: z.string().optional(),
22+
readme: zReadme,
23+
});
24+
25+
export type Documentation = z.infer<typeof zDocumentation>;
26+
1327
export const zWorkflowVersion = z.object({
1428
hash: z.string().optional(),
1529
pinned: z.boolean().optional(),

0 commit comments

Comments
 (0)
Please sign in to comment.