Skip to content

feat: shelldocs init - scaffold ShellDocs into a Blazor project - #7

Merged
Shewart merged 4 commits into
mainfrom
feat/cli-init
Jul 17, 2026
Merged

feat: shelldocs init - scaffold ShellDocs into a Blazor project#7
Shewart merged 4 commits into
mainfrom
feat/cli-init

Conversation

@Shewart

@Shewart Shewart commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the first real CLI command: shelldocs init. Detects a Blazor project in the target directory, adds ShellDocs.Components + ShellDocs.Tokens package references, drops in content/docs/ starter markdown + a routed DocsPage.razor, and writes a SHELLDOCS_SETUP.md with copy-paste snippets for Program.cs and App.razor. Idempotent — every write is skip-if-present.

What's in it

src/ShellDocs.Templates/ScaffoldTemplates.cs — raw-string constants for everything the CLI emits: introduction.md, meta.json, DocsPage.razor, and a parameterised SHELLDOCS_SETUP.md (takes siteName + githubRepo). Zero I/O beyond the string constants — the templates ARE the payload.

src/ShellDocs.CLI/Commands/InitCommand.cs — the orchestrator:

  • Locates the .csproj in --dir (default cwd), errors cleanly if missing.
  • Verifies it's a Blazor project (checks for Microsoft.NET.Sdk.Web / Microsoft.NET.Sdk.Razor / Microsoft.NET.Sdk.BlazorWebAssembly SDK, or an AspNetCore.Components package reference). Errors if not.
  • Adds ShellDocs.Components + ShellDocs.Tokens package refs — inserts into an existing <ItemGroup> that already holds PackageReferences if possible, else appends a new <ItemGroup> before </Project>. Regex-guarded so it never duplicates.
  • Ensures content/docs/ exists, writes introduction.md + meta.json if missing.
  • Locates a Pages dir — prefers Components/Pages (modern Blazor Web App), falls back to Pages (classic Server / WASM). Creates Components/Pages if neither exists. Writes DocsPage.razor if missing.
  • Writes SHELLDOCS_SETUP.md at the project root with the exact Program.cs and App.razor snippets to paste. Deliberately doesn't patch those files directly — users' Program.cses have auth, custom middleware, etc. we can't safely rewrite around.
  • Prints a Spectre summary table + change list + next-steps footer.
  • Interactive prompt for GitHub repo unless --yes is passed (which also silently accepts non-TTY stdin).

src/ShellDocs.CLI/Program.cs — swaps the placeholder init handler for InitCommand.Run(dir, yes, theme). Added a --dir option (defaults to cwd).

tests/ShellDocs.Tests/InitCommandTests.cs — 7 integration tests. Each spins up a temp dir with a minimal Blazor csproj, invokes InitCommand.Run via reflection, and asserts the outcome. Covers:

  • Missing csproj returns error
  • Non-Blazor csproj returns error
  • Valid Blazor project scaffolds all expected files
  • Package references get added to csproj
  • Second run is a true no-op (byte-for-byte identical csproj + content)
  • User modifications to scaffolded files are preserved on re-run
  • Falls back to Pages/ when Components/Pages/ doesn't exist and Pages/ does

Test project now ProjectReferences ShellDocs.CLI for reflection access. Full suite: 78 passing (was 71, +7).

Smoke test (verified locally)

mkdir SmokeApp && cd SmokeApp
cat > SmokeApp.csproj <<'EOF'
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup><TargetFramework>net10.0</TargetFramework></PropertyGroup>
  <ItemGroup><PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="10.0.0" /></ItemGroup>
</Project>
EOF
shelldocs init --yes

Shewart added 4 commits July 17, 2026 17:36
…s with ShellDocs scaffolding and package references
…e `shelldocs init` command functionality for Blazor WASM projects
…Blazor project scaffolding and idempotency
@Shewart
Shewart merged commit 1c85058 into main Jul 17, 2026
1 check passed
@Shewart
Shewart deleted the feat/cli-init branch July 17, 2026 15:49
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