Overview
The CLI tool needs to be able to build Tailwind CSS taking into account the markup for all "online" components combined with any local component(s).
→ See: #3525571: [Meta] CLI tool for code components
Here is an overview of how JavaScript and CSS are compiled for code components (copied from docs/react-codebase/code-editor.md):

Proposed resolution
The command needs to replicate the Tailwind CSS part of the flow above using the following steps:
- Download the JS source of all code components into a local temporary directory, e.g.,
~/.xb. -
Add the JS source of all selected components to the locally cached collection of all "online" components.
- Read the location for your local directory for components from an environment variable or
.envfile established in #3525579: Implement client credentials flow in CLI, centralize managing config. - Allow users to select components interactively or passed as a CLI argument. Make sure there is an option to select all.
- Read the location for your local directory for components from an environment variable or
-
Rebuild the class name candidates index maintained in the
globalxb_asset_library:-
Use
extractClassNameCandidates()frombalintbrews/tailwindcss-in-browser. -
Use code from
ui/src/features/code-editor/utils/classNameCandidates.ts. -
See the XB app's implementation in
ui/src/features/code-editor/hooks/useSourceCode.ts. - Ensure we can use code from
uiby movingcliinto a workspace. - Write the new class name candidate index to
dist/index.jsat the root of the local components directory.
-
Use
- Using the updated class name candidate index, compile a list that contains all class name candidates for all components.
-
Use
buildCss()frombalintbrews/tailwindcss-in-browser-
See the XB app's implementation in
ui/src/features/code-editor/hooks/useSourceCode.ts.
-
See the XB app's implementation in
- Write the generated CSS to
dist/index.cssat the root of the local components directory. -
Extend the upload command (#3525587: CLI command to upload code components) to run this compilation
- Upload the compiled CSS from
dist/index.cssto the global asset library's compiled CSS. - Upload the class name candidate index from
dist/index.jsto the global asset library's class name candidate index.
- Upload the compiled CSS from
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | xb-code-component-compilation.jpg | 449.27 KB | balintbrews |
Issue fork experience_builder-3525592
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- cli-tailwind
changes, plain diff MR !1188
- 3525592-cli-command-to
compare
Comments
Comment #2
balintbrewsComment #3
balintbrewsComment #4
balintbrewsComment #5
hooroomooComment #8
hooroomooComment #10
balintbrews