Skip to content

Refactor NewProjectCommand to support standalone scaffolding - #24

Merged
antosubash merged 6 commits into
mainfrom
claude/test-cli-module-creation-NWAH8
Mar 28, 2026
Merged

antosubash merged 6 commits into
mainfrom
claude/test-cli-module-creation-NWAH8

Conversation

@antosubash

@antosubash antosubash commented Mar 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR refactors the NewProjectCommand to decouple project scaffolding from the CLI command execution, enabling standalone scaffolding without requiring a SimpleModule framework repository. It also introduces framework version resolution to use published NuGet/npm packages by default instead of local development versions.

Key Changes

  • Extracted scaffolding logic: Moved file creation from Execute() into a new public static ScaffoldProject() method, allowing programmatic project generation independent of CLI context
  • Removed solution requirement: Eliminated the mandatory .slnx file check, allowing projects to be created outside the framework repository
  • Framework version resolution: Added NuGetVersionResolver class that determines the framework version via:
    • Explicit --framework-version CLI option
    • Latest version from NuGet API (nuget.org)
    • version.json from framework repository (if available)
    • Hardcoded fallback version (0.0.15)
  • Embedded template resources: Converted HostTemplates to use embedded resources instead of file system paths, enabling distribution without external template files
  • Conditional package sources: Updated NugetConfig() and RootPackageJson() to use published packages when no solution context exists, and local packages when scaffolding within the framework repository
  • Refactored template classes:
    • ProjectTemplates now accepts frameworkVersion parameter
    • HostTemplates methods converted to static, using EmbeddedResourceReader
    • ModuleTemplates now accepts nullable SolutionContext
  • Separated concerns: Split Execute() into three phases: version resolution, dry-run planning, and actual scaffolding with status feedback
  • Added integration tests: New NewProjectScaffoldTests class validates standalone scaffolding, package version resolution, and successful dotnet build of generated projects

Notable Implementation Details

  • NuGetVersionResolver uses a shared HttpClient with 5-second timeout to avoid socket exhaustion
  • Embedded resources follow naming convention: Templates.Host.{path} with dots as path separators
  • HostTemplates.RoutesRazor() now strips AdditionalAssemblies references and properly closes the Router tag
  • ProgramCs() additionally strips Storage.Local and AddLocalStorage lines for standalone projects
  • Fallback .editorconfig provided when solution context unavailable
  • Tests include validation of NuGet/npm package versions and successful project compilation

The `sm new project` command can now create projects that reference
published SimpleModule packages from nuget.org and npmjs.org, instead
of requiring local package sources. Adds NuGet version auto-detection,
fallback templates for all host files, and an integration test that
verifies the scaffolded project builds successfully.
Build artifact from dotnet build — trailing newline normalization.
The template/SimpleModule.Host/ files are now embedded as resources in
the CLI assembly. HostTemplates reads from embedded resources instead of
the filesystem, eliminating both the filesystem dependency and all
hardcoded fallback templates. The CLI is now fully self-contained for
host project scaffolding.
- Use static HttpClient to avoid socket exhaustion
- Remove TOCTOU File.Exists check in NuGetVersionResolver
- Use ReadTemplateLines in RoutesRazor/AppCss instead of manual split
- Remove dead code in IntegrationTestSkeleton and KeepFirstTestMethod
- Add missing wwwroot/css/app.css to PlanFiles
- Extract test scaffold helper and version constant
- Rename FallbackRootPackageJson to GenerateRootPackageJson
@antosubash
antosubash force-pushed the claude/test-cli-module-creation-NWAH8 branch 2 times, most recently from ca34b7d to b430f86 Compare March 28, 2026 19:39
Use file-level exclusion instead of per-tool overrides so biome
completely skips auto-generated types.ts files.
@antosubash
antosubash force-pushed the claude/test-cli-module-creation-NWAH8 branch from b430f86 to e136483 Compare March 28, 2026 19:40
@antosubash
antosubash merged commit e6ebd40 into main Mar 28, 2026
2 checks passed
@antosubash
antosubash deleted the claude/test-cli-module-creation-NWAH8 branch April 1, 2026 15:15
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