Skip to content

feat(shared-utils): detect project layout instead of hardcoding web/app/themes and sage - #150

Closed
YvetteNikolov wants to merge 2 commits into
mainfrom
feat/project-layout-resolver
Closed

YvetteNikolov wants to merge 2 commits into
mainfrom
feat/project-layout-resolver

Conversation

@YvetteNikolov

Copy link
Copy Markdown
Contributor

Split from #144. Stacked on #149 (shares brave.js and the root vitest config); rebase onto main after that one merges.

De toolkit ging er altijd vanuit dat thema's in web/app/themes staan en dat het parent theme sage heet. Beide worden nu automatisch bepaald, zodat de tools ook buiten onze eigen Brave-projecten werken en meerdere parent themes naast elkaar kunnen draaien.

shared-utils

  • resolve-theme-context.cjs: themes directory from yard-toolkit.config.json / package.json#yardToolkit, YARD_THEMES_DIR, composer.json installer-paths, or a probe of known layouts (web/app/themes first, so existing projects resolve as before).
  • Parent/child relation read from each theme's style.css Template: header; default theme picked from config → only parent → sage → first parent (with a warning).
  • Asset base URL derived from the docroot (/app/themes for Bedrock, /wp-content/themes for classic).
  • tryResolveThemeContext (non-throwing), per-cwd cache, clearThemeContextCache for tests.
  • Dual CJS/ESM via exports, no build step. Tests with fixtures for every layout.

Consumers

  • toolkit: lint/format globs use the resolved themes dir; block theme name via themeForPath; new yard-toolkit info prints the resolved layout.
  • vite-config: build base from themesBaseUrl, blade watch glob from the themes dir, block output dir via themeForPath, @sage alias falls back to the default theme.

Follow-ups move eslint-config, prettier-config and postcss-config onto the resolver.

A single dev server means laravel-vite-plugin writes one hot file, into the
public directory of the theme hosting it. Standalone parent themes had no
public/hot of their own and ended up hardcoding the path to sage's.

The plugin copies the hot file into every theme's public directory on server
start and removes the copies on shutdown. A hard kill leaves them behind, so
the toolkit gains a clean command that removes leftovers.
…pp/themes and sage

The toolkit assumed themes live in web/app/themes and the parent theme is
named sage. Both are now resolved: the themes directory from config, env,
composer installer-paths or a probe of known layouts; the parent/child
relation from each theme's style.css header; the asset base URL from where
the themes directory sits relative to the docroot.

The resolver is authored as CommonJS with an ESM facade so the CJS configs
can share it without a build step. The toolkit gains an info command that
prints what was resolved.
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