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
python3 scripts/sync-php-assets.py /path/to/CGWebFrameworkThe 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
| Output | Source and method |
|---|---|
resources/css/cg-component.css | Cut 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.json | The 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
| File | Purpose |
|---|---|
resources/js/site.js | The entry for server-rendered pages: imports translations, boot(), your own registerLinkerAction and event listeners |
resources/js/cg-translations.js | Exposes 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
cargo test --workspacephp_paritytells you whether the Rust components' output still matches the snapshots. If it fails → fix the builders incrates/cg-component/src/according to the diff.tests/runtime.rschecks 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_ACTIONSmust matchactions.js: see the action audit.
npm run buildChecks 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.phpand 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 asui.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.