feat(cli): add --public option for Vite publicDir#2968
Conversation
Adds `--public` (alias `--public-dir`) to `likec4 build` and `likec4 start` (`dev`/`serve`). Files in this directory are copied into the build output as-is via Vite's publicDir, and are preserved when `--output-single-file` is used so user assets (e.g. images referenced from views) are no longer deleted by the single-file cleanup step. Resolves likec4#1941
🦋 Changeset detectedLatest commit: 4b323e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Adds the --public / --public-dir flag to the CLI option tables in apps/docs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughThis PR adds a ChangesPublic Directory Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hey @farhan523! |
Checklist
mainbefore creating this PR.pnpm typecheckandpnpm test./changeset-generatorSKILL).Summary
Resolves #1941.
Adds
--public(alias--public-dir) tolikec4 buildandlikec4 start(dev/serve). Files in this directory are copied into the build output as-is via Vite'spublicDir— and, importantly, are preserved when--output-single-fileis used.Today the single-file build cleans up
outDirby deleting every file that isn'tindex.html. That step also wipes out user assets sitting inoutDir(the original report: PNGs linked from views disappearing). The new flag lets users keep a folder of static assets that the build copies through and the single-file cleanup leaves alone.Implementation approach matches the maintainer's hint in #1941 ("Setting the public dir may solve your issue. (to be implemented in CLI)").
Implementation
packages/likec4/src/cli/options.ts, wired into bothbuildandservecommands.viteBuild/viteDevcopy the user-provided directory's contents into the internal temppublicDirbefore invoking Vite, so all existing assets (favicon, robots.txt, webcomponent bundle) keep working unchanged.removeAllButPreserved(outDir, preserved)so the same deletion logic now also preserves the user's top-level entries (in addition toindex.html).Out of scope
This PR exposes the option as a CLI flag only, per the maintainer's note in #1941 ("to be implemented in CLI"). A
likec4.configschema entry could be a follow-up if there's interest.Test plan
New unit tests (run via
pnpm test):copyUserPublicDircopies all top-level entries and returns their names (packages/likec4/src/vite/utils.spec.ts)copyUserPublicDirreturns[]for an empty dircopyUserPublicDirthrows a clear error when the path is missing / not a dirremoveAllButPreservedkeepsindex.htmlonly when no user dir provided (packages/likec4/src/vite/vite-build.spec.ts)removeAllButPreservedkeepsindex.html+ user files (the actual Add--publicoption to set Vite public directory #1941 fix)removeAllButPreservedis a no-op when nothing to removeservehandler propagatesuserPublicDirtoviteDev(extendsserve.spec.ts)Local checks:
pnpm test— 11 / 11 new tests passingpnpm --filter likec4 typecheck— cleanpnpm lint:errors-only— clean (pre-existing warnings unchanged)pnpm fmt— applied