Skip to content

feat(cli): add --public option for Vite publicDir#2968

Merged
davydkov merged 2 commits into
likec4:mainfrom
farhan523:feat/cli-public-dir
May 21, 2026
Merged

feat(cli): add --public option for Vite publicDir#2968
davydkov merged 2 commits into
likec4:mainfrom
farhan523:feat/cli-public-dir

Conversation

@farhan523

@farhan523 farhan523 commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Checklist

  • I've thoroughly read the latest contribution guidelines.
  • I've rebased my branch onto main before creating this PR.
  • I've added tests to cover my changes (if applicable).
  • I've verified pnpm typecheck and pnpm test.
  • I've added changesets (you can use /changeset-generator SKILL).
  • My change requires documentation updates.
  • I've updated the documentation accordingly (or will do in follow-up PR).

Summary

Resolves #1941.

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, importantly, are preserved when --output-single-file is used.

Today the single-file build cleans up outDir by deleting every file that isn't index.html. That step also wipes out user assets sitting in outDir (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

  • New option in packages/likec4/src/cli/options.ts, wired into both build and serve commands.
  • viteBuild / viteDev copy the user-provided directory's contents into the internal temp publicDir before invoking Vite, so all existing assets (favicon, robots.txt, webcomponent bundle) keep working unchanged.
  • Extracted the single-file cleanup into removeAllButPreserved(outDir, preserved) so the same deletion logic now also preserves the user's top-level entries (in addition to index.html).
  • Errors early with a clear message if the path doesn't exist or isn't a directory.

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.config schema entry could be a follow-up if there's interest.

Test plan

New unit tests (run via pnpm test):

  • copyUserPublicDir copies all top-level entries and returns their names (packages/likec4/src/vite/utils.spec.ts)
  • copyUserPublicDir returns [] for an empty dir
  • copyUserPublicDir throws a clear error when the path is missing / not a dir
  • removeAllButPreserved keeps index.html only when no user dir provided (packages/likec4/src/vite/vite-build.spec.ts)
  • removeAllButPreserved keeps index.html + user files (the actual Add --public option to set Vite public directory #1941 fix)
  • removeAllButPreserved is a no-op when nothing to remove
  • serve handler propagates userPublicDir to viteDev (extends serve.spec.ts)

Local checks:

  • pnpm test — 11 / 11 new tests passing
  • pnpm --filter likec4 typecheck — clean
  • pnpm lint:errors-only — clean (pre-existing warnings unchanged)
  • pnpm fmt — applied

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-bot

changeset-bot Bot commented May 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b323e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
likec4 Minor
@likec4/docs-astro Minor
likec4-vscode Minor
@likec4/playground Minor
@likec4/style-preset Minor
@likec4/styles Minor
@likec4/config Minor
@likec4/core Minor
@likec4/diagram Minor
@likec4/generators Minor
@likec4/language-server Minor
@likec4/language-services Minor
@likec4/layouts Minor
@likec4/leanix-bridge Minor
@likec4/spa Minor
@likec4/log Minor
@likec4/lsp Minor
@likec4/mcp Minor
@likec4/react Minor
@likec4/tsconfig Minor
@likec4/vite-plugin Minor
@likec4/vscode-preview Minor

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.
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 282c6d82-8bd9-44d7-b99c-6d564537734b

📥 Commits

Reviewing files that changed from the base of the PR and between 699f44c and 4b323e3.

📒 Files selected for processing (13)
  • .changeset/cli-public-dir-option.md
  • apps/docs/src/content/docs/tooling/cli.mdx
  • packages/likec4/src/cli/build/index.ts
  • packages/likec4/src/cli/options.ts
  • packages/likec4/src/cli/serve/index.ts
  • packages/likec4/src/cli/serve/serve.spec.ts
  • packages/likec4/src/cli/serve/serve.ts
  • packages/likec4/src/vite/config-app.ts
  • packages/likec4/src/vite/utils.spec.ts
  • packages/likec4/src/vite/utils.ts
  • packages/likec4/src/vite/vite-build.spec.ts
  • packages/likec4/src/vite/vite-build.ts
  • packages/likec4/src/vite/vite-dev.ts

📝 Walkthrough

Walkthrough

This PR adds a --public CLI option to likec4 build and likec4 start commands, allowing users to specify a directory of static assets copied into Vite's public directory. It introduces copy and removal utilities to preserve user-provided files even in --output-single-file mode, and wires the option through the build and serve pipelines with corresponding documentation.

Changes

Public Directory Feature

Layer / File(s) Summary
CLI Option Definition
packages/likec4/src/cli/options.ts
Exports publicDir yargs option with --public-dir alias, path resolution via resolve(), and documentation explaining the output-copy behavior.
Vite Configuration Contract
packages/likec4/src/vite/config-app.ts
Extends LikeC4ViteConfig type with optional userPublicDir field for static assets copied into Vite's public directory.
Copy User Public Directory Utility
packages/likec4/src/vite/utils.ts, packages/likec4/src/vite/utils.spec.ts
Implements copyUserPublicDir function that validates source directory existence, recursively copies contents while preserving structure, and returns top-level entry names for preservation tracking. Test suite covers successful copy with nested content, empty directories, and error cases.
Selective File Removal Utility
packages/likec4/src/vite/vite-build.ts, packages/likec4/src/vite/vite-build.spec.ts
Implements removeAllButPreserved helper that deletes all build output except specified preserve list. Used in --output-single-file mode to retain user-provided assets alongside index.html. Test suite validates selective deletion, nested directory preservation, and no-op behavior.
Build Command Integration
packages/likec4/src/cli/build/index.ts
Wires --public option into build command, adds usage example, and forwards selected directory to viteBuild via userPublicDir parameter.
Build Pipeline with User Public Preservation
packages/likec4/src/vite/vite-build.ts
Updates viteBuild to copy user public directory, track copied entries, and use removeAllButPreserved to preserve user assets alongside index.html in single-file mode.
Serve Command Integration
packages/likec4/src/cli/serve/index.ts
Adds --public option to serve command builder and forwards userPublicDir: args.public to handler invocation.
Serve Handler Implementation
packages/likec4/src/cli/serve/serve.ts, packages/likec4/src/cli/serve/serve.spec.ts
Extends HandlerParams type with optional userPublicDir, destructures and forwards parameter to viteDev call. Includes test verifying parameter propagation.
Dev Server Integration
packages/likec4/src/vite/vite-dev.ts
Updates viteDev to destructure userPublicDir and conditionally copy user-provided assets into temporary public directory before starting server.
Documentation and Release Notes
.changeset/cli-public-dir-option.md, apps/docs/src/content/docs/tooling/cli.mdx
Documents new --public/--public-dir option for both serve and build commands, including Vite integration and behavior in --output-single-file mode.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • likec4/likec4#2947: Both PRs update the likec4 CLI serve option/handler wiring to forward a new config field into viteDev, operating at the same serve-handler plumbing integration layer.

Suggested reviewers

  • davydkov
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a --public option to the CLI for Vite publicDir support, matching the primary focus of the changeset.
Description check ✅ Passed The PR description fully completes the repository template with all checklist items checked, provides comprehensive summary and implementation details, test plan, and out-of-scope considerations.
Linked Issues check ✅ Passed The PR fully addresses issue #1941 by implementing the requested --public CLI option to preserve user assets during --output-single-file builds, with comprehensive tests and proper error handling.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the --public option for CLI and Vite integration; no unrelated modifications detected. Documentation and changelog updates appropriately support the core feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@davydkov

Copy link
Copy Markdown
Member

Hey @farhan523!
Thank you for contribution

@davydkov davydkov enabled auto-merge (squash) May 21, 2026 19:05
@davydkov davydkov merged commit 590864d into likec4:main May 21, 2026
14 checks passed
@likec4-ci likec4-ci Bot mentioned this pull request May 21, 2026
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.

Add --public option to set Vite public directory

2 participants