Skip to content

Commit

Permalink
Adding Asset Mapper support + new StimulusBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed May 22, 2023
1 parent ce1bcfb commit b8acf1a
Show file tree
Hide file tree
Showing 160 changed files with 3,718 additions and 882 deletions.
62 changes: 47 additions & 15 deletions .github/build-packages.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
<?php

$dir = __DIR__.'/../src/LiveComponent';
$flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
/**
* Updates the composer.json files to use the local version of the Symfony UX packages.
*/

$json = ltrim(file_get_contents($dir.'/composer.json'));
if (null === $package = json_decode($json)) {
passthru("composer validate $dir/composer.json");
exit(1);
}
require __DIR__.'/../vendor/autoload.php';

use Symfony\Component\Finder\Finder;

$finder = (new Finder())
->in(__DIR__.'/../src/*/')
->depth(0)
->name('composer.json')
;

$package->repositories[] = [
'type' => 'path',
'url' => '../TwigComponent',
];
foreach ($finder as $composerFile) {
$json = file_get_contents($composerFile->getPathname());
if (null === $packageData = json_decode($json, true)) {
passthru(sprintf('composer validate %s', $composerFile->getPathname()));
exit(1);
}

$json = preg_replace('/\n "repositories": \[\n.*?\n \],/s', '', $json);
$json = rtrim(json_encode(['repositories' => $package->repositories], $flags), "\n}").','.substr($json, 1);
$json = preg_replace('/"symfony\/ux-twig-component": "(\^[\d]+\.[\d]+)"/s', '"symfony/ux-twig-component": "@dev"', $json);
file_put_contents($dir.'/composer.json', $json);
$repositories = [];

if (isset($packageData['require']['symfony/ux-twig-component'])
|| isset($packageData['require-dev']['symfony/ux-twig-component'])
) {
$repositories[] = [
'type' => 'path',
'url' => '../TwigComponent',
];
$key = isset($packageData['require']['symfony/ux-twig-component']) ? 'require' : 'require-dev';
$packageData[$key]['symfony/ux-twig-component'] = '@dev';
}

if (isset($packageData['require']['symfony/stimulus-bundle'])
|| isset($packageData['require-dev']['symfony/stimulus-bundle'])
) {
$repositories[] = [
'type' => 'path',
'url' => '../StimulusBundle',
];
$key = isset($packageData['require']['symfony/stimulus-bundle']) ? 'require' : 'require-dev';
$packageData[$key]['symfony/stimulus-bundle'] = '@dev';
}
if ($repositories) {
$packageData['repositories'] = $repositories;
}

$json = json_encode($packageData, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
file_put_contents($composerFile->getPathname(), $json."\n");
}
8 changes: 4 additions & 4 deletions .github/workflows/test-turbo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: zip

- uses: ramsey/composer-install@v2
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']
php-versions: ['8.1']
fail-fast: false
name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest

Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:

tests-php-low-deps:
runs-on: ubuntu-latest
name: PHP 8.0 (lowest) Test on ubuntu-latest
name: PHP 8.1 (lowest) Test on ubuntu-latest

services:
mercure:
Expand All @@ -118,7 +118,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: zip, pdo_sqlite

- uses: ramsey/composer-install@v2
Expand Down
129 changes: 71 additions & 58 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ jobs:
with:
php-version: '7.2'

- name: Chartjs Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Chartjs
dependency-versions: lowest
- name: Chartjs Tests
run: php vendor/bin/simple-phpunit
working-directory: src/Chartjs

- name: Cropperjs Dependencies
uses: ramsey/composer-install@v2
with:
Expand Down Expand Up @@ -111,24 +102,6 @@ jobs:
run: php vendor/bin/simple-phpunit
working-directory: src/LazyImage

- name: React Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/React
dependency-versions: lowest
- name: React Tests
run: php vendor/bin/simple-phpunit
working-directory: src/React

- name: Svelte Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Svelte
dependency-versions: lowest
- name: Svelte Tests
run: php vendor/bin/simple-phpunit
working-directory: src/Svelte

tests-php8-low-deps:
runs-on: ubuntu-latest
steps:
Expand All @@ -142,6 +115,8 @@ jobs:
with:
working-directory: src/TwigComponent
dependency-versions: lowest
# needed for php 8.0 to skip symfony/stimulus-bundle
composer-options: "--ignore-platform-reqs"
- name: TwigComponent Tests
run: php vendor/bin/simple-phpunit
working-directory: src/TwigComponent
Expand Down Expand Up @@ -173,22 +148,28 @@ jobs:
run: php vendor/bin/simple-phpunit
working-directory: src/Translator

- name: StimulusBundle Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/StimulusBundle
dependency-versions: lowest
- name: StimulusBundle Tests
working-directory: src/StimulusBundle
run: php vendor/bin/simple-phpunit

tests-php-high-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- run: php .github/build-packages.php

- name: Chartjs Dependencies
- name: Install root Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Chartjs
- name: Chartjs Tests
run: php vendor/bin/simple-phpunit
working-directory: src/Chartjs

- run: php .github/build-packages.php

- name: Cropperjs Dependencies
uses: ramsey/composer-install@v2
Expand All @@ -214,14 +195,6 @@ jobs:
run: php vendor/bin/simple-phpunit
working-directory: src/LazyImage

- name: TwigComponent Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/TwigComponent
- name: TwigComponent Tests
run: php vendor/bin/simple-phpunit
working-directory: src/TwigComponent

- name: LiveComponent Dependencies
uses: ramsey/composer-install@v2
with:
Expand All @@ -230,14 +203,6 @@ jobs:
working-directory: src/LiveComponent
run: php vendor/bin/simple-phpunit

- name: React Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/React
- name: React Tests
working-directory: src/React
run: php vendor/bin/simple-phpunit

- name: Autocomplete Dependencies
uses: ramsey/composer-install@v2
with:
Expand All @@ -246,23 +211,28 @@ jobs:
working-directory: src/Autocomplete
run: php vendor/bin/simple-phpunit

- name: Svelte Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Svelte
- name: Svelte Tests
working-directory: src/Svelte
run: php vendor/bin/simple-phpunit

tests-php81-high-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Install root Dependencies
uses: ramsey/composer-install@v2

- run: php .github/build-packages.php

- name: Chartjs Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Chartjs
- name: Chartjs Tests
working-directory: src/Chartjs
run: php vendor/bin/simple-phpunit

- name: Notify Dependencies
uses: ramsey/composer-install@v2
with:
Expand All @@ -271,6 +241,32 @@ jobs:
working-directory: src/Notify
run: php vendor/bin/simple-phpunit

- name: React Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/React
dependency-versions: lowest
- name: React Tests
run: php vendor/bin/simple-phpunit
working-directory: src/React

- name: StimulusBundle Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/StimulusBundle
- name: StimulusBundle Tests
working-directory: src/StimulusBundle
run: php vendor/bin/simple-phpunit

- name: Svelte Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Svelte
dependency-versions: lowest
- name: Svelte Tests
run: php vendor/bin/simple-phpunit
working-directory: src/Svelte

- name: Translator Dependencies
uses: ramsey/composer-install@v2
with:
Expand All @@ -279,6 +275,23 @@ jobs:
working-directory: src/Translator
run: php vendor/bin/simple-phpunit

- name: TwigComponent Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/TwigComponent
- name: TwigComponent Tests
run: php vendor/bin/simple-phpunit
working-directory: src/TwigComponent

- name: Vue Dependencies
uses: ramsey/composer-install@v2
with:
working-directory: src/Vue
dependency-versions: lowest
- name: Vue Tests
run: php vendor/bin/simple-phpunit
working-directory: src/Vue

tests-js:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ to build the chart in PHP. The JavaScript is handled for you automatically.
**That's Symfony UX.**

Symfony UX leverages [Stimulus](https://stimulus.hotwired.dev/) for JavaScript
and the [Stimulus Bridge](https://github.com/symfony/stimulus-bridge) for
integrating it into [Webpack Encore](https://github.com/symfony/webpack-encore).
and can integrate with [Webpack Encore](https://github.com/symfony/webpack-encore)
(with the help of [Stimulus Bridge](https://github.com/symfony/stimulus-bridge))
or with [AssetMapper](https://symfony.com/doc/current/frontend/asset-mapper.html)

## Resources

Expand Down
32 changes: 32 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This file is used to compile the TypeScript files in the assets/src directory
* of each package.
*
* It allows each package to spawn its own rollup process, which is necessary
* to keep memory usage down.
*/
const { spawnSync } = require('child_process');
const glob = require('glob');

const files = [
// custom handling for StimulusBundle
'src/StimulusBundle/assets/src/loader.ts',
'src/StimulusBundle/assets/src/controllers.ts',
...glob.sync('src/*/assets/src/*controller.ts'),
];

files.forEach((file) => {
const result = spawnSync('node', [
'node_modules/.bin/rollup',
'-c',
'--environment',
`INPUT_FILE:${file}`,
], {
stdio: 'inherit',
shell: true
});

if (result.error) {
console.error(`Error compiling ${file}:`, result.error);
}
});
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"license": "MIT",
"require-dev": {
"symfony/filesystem": "^5.2|^6.0",
"symfony/finder": "^5.4|^6.0",
"php-cs-fixer/shim": "^3.13"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"src/*/assets"
],
"scripts": {
"build": "yarn rollup -c",
"build": "node build.js",
"test": "yarn workspaces run jest",
"lint": "yarn workspaces run eslint src test",
"format": "prettier src/*/assets/src/*.ts src/*/assets/test/*.js {,src/*/}*.{json,md} --write",
Expand Down
Loading

0 comments on commit b8acf1a

Please sign in to comment.