Skip to content

Syncing with the PHP project ​

The PHP project is the single source of HTML, CSS, JavaScript and translations. Don't edit any file in this repo that came from PHP: change PHP, then sync.

Running it ​

bash
python3 scripts/sync-php-assets.py /path/to/CGWebFramework

The path defaults to $CG_PHP_PATH, then ../CGWebFramework (with both repos side by side you don't need an argument). The PHP repo must have resources/css/app.css and tests/Snapshots/ComponentShowcase, or the script stops immediately.

What it does ​

OutputSource and method
resources/css/cg-component.cssCut from PHP's resources/css/app.css the same way PHP's ComponentPackageBuilder cuts components.css: the primary palette fallback, the shared sections the components depend on (notify, the centered popup), then everything after the component marker. The component rules are copied verbatim
resources/js/cg/Deleted entirely first, then the imports of components.js and runtime.js are traced (static and literal dynamic imports) and the whole dependency tree is copied; linker/actions.js is cut at // make:linker-action, keeping only the built-in actions. Importing an undeclared npm package fails immediately
resources/js/cg-lang.jsonThe translations the runtime uses: all of lang/<locale>/linker.php, plus notify and validation from view.php. Needs the php command
crates/cg-component/tests/fixtures/php/PHP's visual snapshots (HTML and manifest.json)

Finally the script checks whether the sha256 of the CSS component section appears in the snapshot manifest, printing matches or DOES NOT MATCH (regenerate the PHP snapshots). The latter means PHP's CSS changed without updating the snapshots; regenerate them in the PHP project first.

Files that aren't synced and are yours to edit ​

FilePurpose
resources/js/site.jsThe entry for server-rendered pages: imports translations, boot(), your own registerLinkerAction and event listeners
resources/js/cg-translations.jsExposes cg-lang.json as window.trans / window.__
crates/cg-component/src/**Rust components and runtime
src/cg/**Your fragments and Linker components

Don't put your own JS in resources/js/cg/; the next sync deletes it.

After syncing ​

bash
cargo test --workspace
  • php_parity tells you whether the Rust components' output still matches the snapshots. If it fails → fix the builders in crates/cg-component/src/ according to the diff.
  • tests/runtime.rs checks the server-side protocol. If PHP changed the protocol (fields, error shapes, actions) → it fails here or needs new tests, and the Rust runtime must follow.
  • BUILTIN_ACTIONS must match actions.js: see the action audit.
bash
npm run build

Checks that Vite can bundle the new JS (run npm install for new npm dependencies).

When to sync ​

  • The PHP project changed a component's HTML or CSS.
  • The PHP project changed modules in resources/js/ that the runtime uses (state.js, linker.js, renderBlade.js, component binders…).
  • The PHP project added a built-in action → after syncing, also add its spec to BUILTIN_ACTIONS.
  • The PHP project changed the runtime's translations (lang/*/linker.php and so on).
  • Before porting a new component (to be sure the snapshots are current).

What's outside the sync ​

  • The PHP project's own business JS (login, uploads and so on in resources/js/Events/*): only modules the runtime traces to are copied.
  • Actions after // make:linker-action (added by the PHP project itself, such as ui.test).
  • Blade views and PHP code: the Rust version ports these itself, with the snapshots as the reference.

npm packages

The runtime's chart modules import packages such as chart.js and @amcharts/amcharts5, so package.json carries the PHP version's npm peers. The script only allows packages on that list; they're loaded only when a page uses charts.