From f7f2c788b1059a109bc1cdbc27aeb3df3168826c Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 3 Apr 2025 11:21:46 -0400 Subject: [PATCH] fix: account for footnotes in README.md --- src/base.ts | 6 +++ src/blocks/blockREADME.test.ts | 48 +++++++++++++++++-- src/blocks/blockREADME.ts | 7 ++- src/options/readDocumentation.ts | 16 ++++--- src/options/readReadmeAdditional.ts | 7 ++- src/options/readReadmeFootnotes.test.ts | 62 +++++++++++++++++++++++++ src/options/readReadmeFootnotes.ts | 18 +++++++ src/schemas.ts | 1 + 8 files changed, 150 insertions(+), 15 deletions(-) create mode 100644 src/options/readReadmeFootnotes.test.ts create mode 100644 src/options/readReadmeFootnotes.ts diff --git a/src/base.ts b/src/base.ts index b35dc66de..e07a1b1c0 100644 --- a/src/base.ts +++ b/src/base.ts @@ -31,6 +31,7 @@ import { readPackageData } from "./options/readPackageData.js"; import { readPnpm } from "./options/readPnpm.js"; import { readReadmeAdditional } from "./options/readReadmeAdditional.js"; import { readReadmeExplainer } from "./options/readReadmeExplainer.js"; +import { readReadmeFootnotes } from "./options/readReadmeFootnotes.js"; import { readReadmeUsage } from "./options/readReadmeUsage.js"; import { readRepository } from "./options/readRepository.js"; import { readRulesetId } from "./options/readRulesetId.js"; @@ -197,6 +198,7 @@ export const base = createBase({ getDevelopmentDocumentation, getReadmeAdditional, getReadmeExplainer, + getReadmeFootnotes, getReadmeUsage, ), ); @@ -281,6 +283,10 @@ export const base = createBase({ async () => await readReadmeExplainer(getReadme), ); + const getReadmeFootnotes = lazyValue( + async () => await readReadmeFootnotes(getReadme), + ); + const getReadmeUsage = lazyValue( async () => await readReadmeUsage(getEmoji, getReadme, getRepository), ); diff --git a/src/blocks/blockREADME.test.ts b/src/blocks/blockREADME.test.ts index ad38c95ad..d45a9e5fe 100644 --- a/src/blocks/blockREADME.test.ts +++ b/src/blocks/blockREADME.test.ts @@ -117,7 +117,7 @@ describe("blockREADME", () => { `); }); - test("options.explainer", () => { + test("options.documentation.readme.explainer", () => { const creation = testBlock(blockREADME, { options: { ...optionsBase, @@ -125,7 +125,7 @@ describe("blockREADME", () => { ...optionsBase.documentation, readme: { ...optionsBase.documentation.readme, - explainer: "\nAnd a one.\nAnd a two.\n", + explainer: "And a one.\nAnd a two.", }, }, }, @@ -142,11 +142,9 @@ describe("blockREADME", () => { 💪 TypeScript: Strict

- And a one. And a two. - ## Usage Test usage. @@ -162,6 +160,48 @@ describe("blockREADME", () => { `); }); + test("options.documentation.readme.footnotes", () => { + const creation = testBlock(blockREADME, { + options: { + ...optionsBase, + documentation: { + ...optionsBase.documentation, + readme: { + ...optionsBase.documentation.readme, + footnotes: "And a one.\nAnd a two.", + }, + }, + }, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "files": { + "README.md": "

Test Title

+ +

Test description

+ +

+ 💪 TypeScript: Strict +

+ + ## Usage + + Test usage. + + ## Development + + See [\`.github/CONTRIBUTING.md\`](./.github/CONTRIBUTING.md), then [\`.github/DEVELOPMENT.md\`](./.github/DEVELOPMENT.md). + Thanks! 💖 + + + And a one. + And a two.", + }, + } + `); + }); + test("options.logo without sizing", () => { const creation = testBlock(blockREADME, { options: { diff --git a/src/blocks/blockREADME.ts b/src/blocks/blockREADME.ts index b0300950e..a6c969283 100644 --- a/src/blocks/blockREADME.ts +++ b/src/blocks/blockREADME.ts @@ -43,6 +43,11 @@ export const blockREADME = base.createBlock({ options.logo && `\n\n`; + const suffixes = [ + ...notices, + options.documentation.readme.footnotes, + ].filter((suffix) => typeof suffix === "string"); + return { files: { "README.md": `

${options.title}

@@ -65,7 +70,7 @@ ${[...sections, options.documentation.readme.additional] .filter(Boolean) .map((section) => `\n${section}`) .join("")} -${notices.length ? `\n${notices.map((notice) => notice.trim()).join("\n\n")}` : ""}`, +${suffixes.length ? `\n${suffixes.map((suffix) => suffix.trim()).join("\n\n")}` : ""}`, }, }; }, diff --git a/src/options/readDocumentation.ts b/src/options/readDocumentation.ts index fc1eb7065..d828f348e 100644 --- a/src/options/readDocumentation.ts +++ b/src/options/readDocumentation.ts @@ -4,20 +4,24 @@ export async function readDocumentation( getDevelopmentDocumentation: () => Promise, getReadmeAdditional: () => Promise, getReadmeExplainer: () => Promise, + getReadmeFootnotes: () => Promise, getReadmeUsage: () => Promise, ): Promise { - const [additional, explainer, development, usage] = await Promise.all([ - getReadmeAdditional(), - getReadmeExplainer(), - getDevelopmentDocumentation(), - getReadmeUsage(), - ]); + const [additional, explainer, footnotes, development, usage] = + await Promise.all([ + getReadmeAdditional(), + getReadmeExplainer(), + getReadmeFootnotes(), + getDevelopmentDocumentation(), + getReadmeUsage(), + ]); return { development, readme: { additional, explainer, + footnotes, usage, }, }; diff --git a/src/options/readReadmeAdditional.ts b/src/options/readReadmeAdditional.ts index a06eb585e..9aed6af68 100644 --- a/src/options/readReadmeAdditional.ts +++ b/src/options/readReadmeAdditional.ts @@ -1,10 +1,9 @@ +import { indicatorTemplatedBy } from "./readReadmeFootnotes.js"; + const indicatorAfterAllContributors = //; const indicatorAfterAllContributorsSpellCheck = //; -const indicatorBeforeTemplatedBy = - /> .* This package (?:is|was) (?:based|build|templated) (?:on|with) |