Skip to content

Commit

Permalink
Showing 2 changed files with 43 additions and 16 deletions.
55 changes: 40 additions & 15 deletions src/steps/updateReadme.test.ts
Original file line number Diff line number Diff line change
@@ -63,12 +63,37 @@ describe("updateReadme", () => {

it("doesn't add a notice when the file contains it already", async () => {
mockReadFileSafe.mockResolvedValue(`
Existing JoshuaKGoldberg/create-typescript-app content.
Existing JoshuaKGoldberg/create-typescript-app content.
<!-- You can remove this notice if you don't want it 🙂 no worries! -->
> 💙 This package was templated using [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
`);

await updateReadme(options);

expect(mockWriteFile.mock.calls).toMatchInlineSnapshot(`
[
[
"./README.md",
"
Existing NewOwner/create-typescript-app content.
<!-- You can remove this notice if you don't want it 🙂 no worries! -->
> 💙 This package was templated using [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
> 💙 This package was templated using [create-typescript-app](https://github.com/NewOwner/create-typescript-app).
",
],
]
`);
});

it("doesn't add a notice when the file contains an older version of it already", async () => {
mockReadFileSafe.mockResolvedValue(`
Existing JoshuaKGoldberg/create-typescript-app content.
💙 This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
`);

await updateReadme(options);

@@ -77,22 +102,22 @@ describe("updateReadme", () => {
[
"./README.md",
"
Existing NewOwner/create-typescript-app content.
<!-- You can remove this notice if you don't want it 🙂 no worries! -->
> 💙 This package was templated using [create-typescript-app](https://github.com/NewOwner/create-typescript-app).
",
Existing NewOwner/create-typescript-app content.
💙 This package is based on [@NewOwner](https://github.com/NewOwner)'s [create-typescript-app](https://github.com/NewOwner/create-typescript-app).
",
],
]
`);
});

it("doesn't add a notice when the file contains an older version of it already", async () => {
it("removes the project logo when it exists", async () => {
mockReadFileSafe.mockResolvedValue(`
Existing JoshuaKGoldberg/create-typescript-app content.
Existing JoshuaKGoldberg/create-typescript-app content.
<img align="right" alt="Project logo: the TypeScript blue square with rounded corners, but a plus sign instead of 'TS'" height="128" src="./docs/create-typescript-app.png" width="128">
💙 This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
💙 This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
`);

await updateReadme(options);
@@ -102,9 +127,9 @@ describe("updateReadme", () => {
[
"./README.md",
"
Existing NewOwner/create-typescript-app content.
Existing NewOwner/create-typescript-app content.
💙 This package is based on [@NewOwner](https://github.com/NewOwner)'s [create-typescript-app](https://github.com/NewOwner/create-typescript-app).
💙 This package is based on [@NewOwner](https://github.com/NewOwner)'s [create-typescript-app](https://github.com/NewOwner/create-typescript-app).
",
],
]
4 changes: 3 additions & 1 deletion src/steps/updateReadme.ts
Original file line number Diff line number Diff line change
@@ -22,7 +22,9 @@ export async function updateReadme(
) {
let contents = await readFileSafe("./README.md", "");

contents = contents.replaceAll("JoshuaKGoldberg", options.owner);
contents = contents
.replaceAll("JoshuaKGoldberg", options.owner)
.replace(/\n<img .+ alt="Project logo.+>\n/gs, "");

if (!options.excludeTemplatedBy && !endOfReadmeMatcher.test(contents)) {
contents += endOfReadmeNotice;

0 comments on commit 6e81c74

Please sign in to comment.