Skip to content

Commit 5cd4a95

Browse files
feat: preserve existing unknown .github/DEVELOPMENT.md sections (#1173)
## PR Checklist - [x] Addresses an existing open issue: fixes #1167 - [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 Now, when `.github/DEVELOPMENT.md` exists, any `##` that doesn't match the new headings will be preserved and moved to the bottom of the file. Note that this doesn't show up nicely in the migration test end-to-end snapshots because `updateLocalFiles` manually removes the `## Setup Scripts` sections.
1 parent b0a6140 commit 5cd4a95

File tree

6 files changed

+317
-80
lines changed

6 files changed

+317
-80
lines changed

script/__snapshots__/migrate-test-e2e.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ exports[`expected file changes > cspell.json 1`] = `
174174
"mtfoley",
175175
"npmignore",
176176
@@ ... @@
177+
"packagejson",
177178
"quickstart",
178179
"tada",
180+
+ "templating",
179181
"tsup",
180182
- "vitest"
181183
+ "vitest",

src/steps/writing/creation/dotGitHub/createDevelopment.test.ts src/steps/writing/creation/dotGitHub/createDevelopment/index.test.ts

+153-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import { describe, expect, it } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
22

3-
import { Options } from "../../../../shared/types.js";
4-
import { createDevelopment } from "./createDevelopment.js";
3+
import { Options } from "../../../../../shared/types.js";
4+
import { createDevelopment } from "./index.js";
5+
6+
const mockReadFileSafe = vi.fn();
7+
8+
vi.mock("../../../../../shared/readFileSafe.js", () => ({
9+
get readFileSafe() {
10+
return mockReadFileSafe;
11+
},
12+
}));
513

614
const options = {
715
access: "public",
@@ -21,8 +29,10 @@ const options = {
2129
} satisfies Options;
2230

2331
describe("createDevelopment", () => {
24-
it("creates a file with extra options turned on when options disable them", () => {
25-
const actual = createDevelopment({
32+
it("creates a file with extra options turned on when options disable them", async () => {
33+
mockReadFileSafe.mockResolvedValue("");
34+
35+
const actual = await createDevelopment({
2636
...options,
2737
excludeLintKnip: false,
2838
excludeLintMd: false,
@@ -77,7 +87,7 @@ describe("createDevelopment", () => {
7787
7888
- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files
7989
- \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports
80-
- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files
90+
- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint): Checks Markdown source files
8191
- \`pnpm lint:package-json\` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the \`package.json\` file
8292
- \`pnpm lint:packages\` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the \`pnpm-lock.yml\` file
8393
- \`pnpm lint:spelling\` ([cspell](https://cspell.org)): Spell checks across all source files
@@ -134,8 +144,10 @@ describe("createDevelopment", () => {
134144
`);
135145
});
136146

137-
it("creates a file with extra options turned off when options enable them", () => {
138-
const actual = createDevelopment({
147+
it("creates a file with extra options turned off when options enable them", async () => {
148+
mockReadFileSafe.mockResolvedValue("");
149+
150+
const actual = await createDevelopment({
139151
...options,
140152
excludeLintKnip: true,
141153
excludeLintMd: true,
@@ -192,7 +204,7 @@ describe("createDevelopment", () => {
192204
193205
## Linting
194206
195-
[ESLint](https://eslint.org) is used with with [typescript-eslint](https://typescript-eslint.io) to lint JavaScript and TypeScript source files.
207+
[ESLint](https://eslint.org) is used with with [typescript-eslint](https://typescript-eslint.io)) to lint JavaScript and TypeScript source files.
196208
You can run it locally on the command-line:
197209
198210
\`\`\`shell
@@ -248,4 +260,136 @@ describe("createDevelopment", () => {
248260
"
249261
`);
250262
});
263+
264+
it("preserves existing sections when they don't match the new sections", async () => {
265+
mockReadFileSafe.mockResolvedValue(`## Existing One
266+
267+
Abc 123.
268+
269+
## Building
270+
271+
Will be removed.
272+
273+
## Tests
274+
275+
Will be removed.
276+
277+
## Existing Two
278+
279+
Def 456.
280+
`);
281+
282+
const actual = await createDevelopment({
283+
...options,
284+
excludeLintKnip: false,
285+
excludeLintMd: false,
286+
excludeLintPackageJson: false,
287+
excludeLintPackages: false,
288+
excludeLintSpelling: false,
289+
});
290+
291+
expect(actual).toMatchInlineSnapshot(`
292+
"# Development
293+
294+
After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation):
295+
296+
\`\`\`shell
297+
git clone https://github.com/<your-name-here>/test-repository
298+
cd test-repository
299+
pnpm install
300+
\`\`\`
301+
302+
> This repository includes a list of suggested VS Code extensions.
303+
> It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development.
304+
305+
## Building
306+
307+
Will be removed.
308+
309+
## Formatting
310+
311+
[Prettier](https://prettier.io) is used to format code.
312+
It should be applied automatically when you save files in VS Code or make a Git commit.
313+
314+
To manually reformat all files, you can run:
315+
316+
\`\`\`shell
317+
pnpm format --write
318+
\`\`\`
319+
320+
## Linting
321+
322+
This package includes several forms of linting to enforce consistent code quality and styling.
323+
Each should be shown in VS Code, and can be run manually on the command-line:
324+
325+
- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files
326+
- \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports
327+
- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint): Checks Markdown source files
328+
- \`pnpm lint:package-json\` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the \`package.json\` file
329+
- \`pnpm lint:packages\` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the \`pnpm-lock.yml\` file
330+
- \`pnpm lint:spelling\` ([cspell](https://cspell.org)): Spell checks across all source files
331+
332+
Read the individual documentation for each linter to understand how it can be configured and used best.
333+
334+
For example, ESLint can be run with \`--fix\` to auto-fix some lint rule complaints:
335+
336+
\`\`\`shell
337+
pnpm run lint --fix
338+
\`\`\`
339+
340+
Note that you'll likely need to run \`pnpm build\` before \`pnpm lint\` so that lint rules which check the file system can pick up on any built files.
341+
342+
## Testing
343+
344+
[Vitest](https://vitest.dev) is used for tests.
345+
You can run it locally on the command-line:
346+
347+
\`\`\`shell
348+
pnpm run test
349+
\`\`\`
350+
351+
Add the \`--coverage\` flag to compute test coverage and place reports in the \`coverage/\` directory:
352+
353+
\`\`\`shell
354+
pnpm run test --coverage
355+
\`\`\`
356+
357+
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
358+
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
359+
360+
### Debugging Tests
361+
362+
This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests.
363+
To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5).
364+
365+
## Type Checking
366+
367+
You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files.
368+
369+
However, it can be useful to run the TypeScript command-line (\`tsc\`) to type check all files in \`src/\`:
370+
371+
\`\`\`shell
372+
pnpm tsc
373+
\`\`\`
374+
375+
Add \`--watch\` to keep the type checker running in a watch mode that updates the display as you save files:
376+
377+
\`\`\`shell
378+
pnpm tsc --watch
379+
\`\`\`
380+
381+
## Existing One
382+
383+
Abc 123.
384+
385+
## Tests
386+
387+
Will be removed.
388+
389+
## Existing Two
390+
391+
Def 456.
392+
"
393+
`);
394+
});
251395
});

0 commit comments

Comments
 (0)