Skip to content

fix(docs): add overwriteExisting option for flexible README overwrite behaviour #6249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

smorrisods
Copy link

@smorrisods smorrisods commented May 2, 2025

The docs-readme output target has long supported writing README files to custom locations using the dir property, helping teams structure their documentation workflows to suit project needs.

As part of evolving those workflows, I've introduced the overwriteExisting property to give developers precise control over how README files are handled. This addition supports common scenarios like always overwriting, only writing when files are missing, or preserving existing content:

  • Always overwrite the full README (true),
  • Only write the full README if no file exists ('if-missing'), or
  • Preserve existing custom content (default false).

These options aim to better support workflows where documentation is closely tied to source code, while also offering flexibility for varied project structures.

What is the current behaviour?

By default, the docs-readme output target preserves any manually-entered content in destination README files, but it does not offer flexible controls for different overwrite behaviours. This made it difficult to manage workflows where documentation is expected to be tightly coupled with source code, while also needing different customisation strategies for various parts of a project.

Link to relevant issues/PRs: #5648 #6248

What is the new behaviour?

This PR introduces documentation for the new overwriteExisting property
on the docs-readme output target.

The documentation includes:

  • Clear description of the overwriteExisting configuration option.
  • Available modes (true, false, and 'if-missing').
  • Example usage in a stencil.config.ts file.
  • Real-world use case highlighting idempotent output and CI workflows.
  • Clarification that the component README beside the component is treated
    as the canonical source of truth for custom content.

Documentation

A documentation update has been made in stenciljs/site#1521.

Does this introduce a breaking change?

  • Yes
  • No

Testing

Other information

See #6248 for a detailed explanation of the use case this PR is covering.

smorrisods added 2 commits May 2, 2025 19:05
… behaviour

On the `docs-readme` output target, a new `overwriteExisting` option allows developers to
control how existing README files are handled when writing to a custom path.

This adds flexibility to either:

- Always overwrite the full README (`true`),
- Only write the full README if no file exists (`'if-missing'`), or
- Preserve existing custom content (**default** `false`).

Now, `docs-readme` treats the component `readme.md` files as the canonical source for
manually-entered custom content when overwriting READMEs. This ensures that custom content
is preserved unless explicitly overwritten.

For example, when using the `'if-missing'` flag, a project that writes component readmes
into a documentation library folder can maintain consistent, idempotent output across
local builds and CI environments. Custom edits to the destination files will be maintained,
while files without customisation will be fully exported.

Fixes stenciljs#6248
Adds tests covering all `overwriteExisting` modes on the `docs-readme` output target:

- Always overwrite (`true`)
- Overwrite if missing (`'if-missing'`) with and without a destination file
- Never overwrite (`false`)
- Default behaviour (`undefined`), which treats missing values as `false`

Tests confirm that manual content is preserved when appropriate, new files are correctly
generated when missing, and behaviour matches the original fix for stenciljs#5400.

Also validates idempotent output across multiple overwriting scenarios.

Related to the fix for stenciljs#6248.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant