Skip to content

Commit ead1c01

Browse files
committed
feature #894 Asset mapper integration part 2! (weaverryan)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Asset mapper integration part 2! | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Tickets | None | License | MIT Hi! Continued work to prep the UX bundles (and the new StimulusBundle) to support AssetMapper (support for WebpackEncoreBundle will not change). TODOS: * [X] React support * [X] autoimport support * [ ] Vue support * [ ] Svelte support * [ ] Translator support * [ ] add "excludes" to avoid controllers.json from being in the asset mapper * [ ] add "excludes" to avoid .d.ts files from being in the asset mapper * [ ] tests Cheers! Commits ------- 1b9f4d8 Asset mapper integration part 2!
2 parents 11de5cf + 1b9f4d8 commit ead1c01

File tree

138 files changed

+15145
-5837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+15145
-5837
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ jobs:
235235
uses: ramsey/composer-install@v2
236236
with:
237237
working-directory: src/React
238-
dependency-versions: lowest
239238
- name: React Tests
240239
run: php vendor/bin/simple-phpunit
241240
working-directory: src/React
@@ -252,7 +251,6 @@ jobs:
252251
uses: ramsey/composer-install@v2
253252
with:
254253
working-directory: src/Svelte
255-
dependency-versions: lowest
256254
- name: Svelte Tests
257255
run: php vendor/bin/simple-phpunit
258256
working-directory: src/Svelte
@@ -277,7 +275,6 @@ jobs:
277275
uses: ramsey/composer-install@v2
278276
with:
279277
working-directory: src/Vue
280-
dependency-versions: lowest
281278
- name: Vue Tests
282279
run: php vendor/bin/simple-phpunit
283280
working-directory: src/Vue

build.js renamed to bin/build_javascript.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const { spawnSync } = require('child_process');
99
const glob = require('glob');
1010

1111
const files = [
12+
// custom handling for React
13+
'src/React/assets/src/loader.ts',
14+
'src/React/assets/src/components.ts',
15+
// custom handling for Svelte
16+
'src/Svelte/assets/src/loader.ts',
17+
'src/Svelte/assets/src/components.ts',
18+
// custom handling for Vue
19+
'src/Vue/assets/src/loader.ts',
20+
'src/Vue/assets/src/components.ts',
1221
// custom handling for StimulusBundle
1322
'src/StimulusBundle/assets/src/loader.ts',
1423
'src/StimulusBundle/assets/src/controllers.ts',

bin/build_styles.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Script to "build" the source CSS files to their final destination.
3+
*/
4+
5+
const glob = require('glob');
6+
const { exec } = require('child_process');
7+
const path = require('path');
8+
const fs = require('fs');
9+
10+
let pattern = 'src/*/assets/package.json';
11+
12+
// Use glob to find all matching package.json files
13+
glob(pattern, function (err, files) {
14+
if (err) {
15+
console.error('Error while finding package.json files:', err);
16+
process.exit(1);
17+
}
18+
19+
// Loop over all files
20+
files.forEach(file => {
21+
// Read the package.json file
22+
const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
23+
24+
// Get the css source
25+
const cssSourceRelative = pkg.config && pkg.config.css_source;
26+
27+
if (!cssSourceRelative) {
28+
return;
29+
}
30+
// Construct the output path
31+
const cssSource = path.join(path.dirname(file), cssSourceRelative);
32+
const outputDir = path.join(path.dirname(file), 'dist');
33+
const outputFilename = path.basename(cssSource, '.css') + '.min.css';
34+
const output = path.join(outputDir, outputFilename);
35+
36+
// Run the clean-css-cli command
37+
exec(`yarn run cleancss -o ${output} ${cssSource}`, function (err) {
38+
if (err) {
39+
console.error(`Error while minifying ${cssSource}:`, err);
40+
return;
41+
}
42+
43+
console.log(`Minified ${cssSource} to ${output}`);
44+
});
45+
});
46+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"src/*/assets"
55
],
66
"scripts": {
7-
"build": "node build.js",
7+
"build": "node bin/build_javascript.js && node bin/build_styles.js",
88
"test": "yarn workspaces run jest",
99
"lint": "yarn workspaces run eslint src test",
1010
"format": "prettier src/*/assets/src/*.ts src/*/assets/test/*.js {,src/*/}*.{json,md} --write",
@@ -23,6 +23,7 @@
2323
"@typescript-eslint/eslint-plugin": "^5.2.0",
2424
"@typescript-eslint/parser": "^5.2.0",
2525
"babel-jest": "^27.3.1",
26+
"clean-css-cli": "^5.6.2",
2627
"eslint": "^8.1.0",
2728
"eslint-config-prettier": "^8.0.0",
2829
"eslint-plugin-jest": "^25.2.2",

rollup.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ const peerDependencies = [
7474
if (file.includes('StimulusBundle/assets/src/loader.ts')) {
7575
peerDependencies.push('./controllers.js');
7676
}
77+
// React, Vue
78+
if (file.includes('assets/src/loader.ts')) {
79+
peerDependencies.push('./components.js');
80+
}
7781

7882
module.exports = {
7983
input: file,

src/Autocomplete/doc/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Then install the bundle using Composer and Symfony Flex:
2020
2121
$ composer require symfony/ux-autocomplete
2222
23+
If you're using WebpackEncore, install your assets and restart Encore. This is
24+
not needed if you're using AssetMapper:
25+
26+
.. code-block:: terminal
27+
2328
# Don't forget to install the JavaScript dependencies as well and compile
2429
$ npm install --force
2530
$ npm run watch

src/Chartjs/doc/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Then, install this bundle using Composer and Symfony Flex:
1616
1717
$ composer require symfony/ux-chartjs
1818
19+
If you're using WebpackEncore, install your assets and restart Encore. This is
20+
not needed if you're using AssetMapper:
21+
22+
.. code-block:: terminal
23+
1924
# Don't forget to install the JavaScript dependencies as well and compile
2025
$ npm install --force
2126
$ npm run watch
@@ -24,9 +29,6 @@ Then, install this bundle using Composer and Symfony Flex:
2429
$ yarn install --force
2530
$ yarn watch
2631
27-
Also make sure you have at least version 3.0 of `@symfony/stimulus-bridge`_
28-
in your ``package.json`` file.
29-
3032
Usage
3133
-----
3234

@@ -241,7 +243,6 @@ the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html
241243

242244
.. _`Chart.js`: https://www.chartjs.org
243245
.. _`the Symfony UX initiative`: https://symfony.com/ux
244-
.. _`@symfony/stimulus-bridge`: https://github.com/symfony/stimulus-bridge
245246
.. _`Chart.js documentation`: https://www.chartjs.org/docs/latest/
246247
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html
247248
.. _`a lot of plugins`: https://github.com/chartjs/awesome#plugins
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.cropperjs-image{max-width:100%}

src/Cropperjs/assets/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"version": "1.1.0",
66
"main": "dist/controller.js",
77
"types": "dist/controller.d.ts",
8+
"config": {
9+
"css_source": "src/style.css"
10+
},
811
"symfony": {
912
"controllers": {
1013
"cropper": {
@@ -14,7 +17,7 @@
1417
"enabled": true,
1518
"autoimport": {
1619
"cropperjs/dist/cropper.min.css": true,
17-
"@symfony/ux-cropperjs/src/style.css": true
20+
"@symfony/ux-cropperjs/dist/style.min.css": true
1821
}
1922
}
2023
},

src/Cropperjs/doc/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Then, install this bundle using Composer and Symfony Flex:
1616
1717
$ composer require symfony/ux-cropperjs
1818
19+
If you're using WebpackEncore, install your assets and restart Encore. This is
20+
not needed if you're using AssetMapper:
21+
22+
.. code-block:: terminal
23+
1924
# Don't forget to install the JavaScript dependencies as well and compile
2025
$ npm install --force
2126
$ npm run watch
@@ -24,9 +29,6 @@ Then, install this bundle using Composer and Symfony Flex:
2429
$ yarn install --force
2530
$ yarn watch
2631
27-
Also make sure you have at least version 3.0 of
28-
`@symfony/stimulus-bridge`_ in your ``package.json`` file.
29-
3032
Usage
3133
-----
3234

@@ -148,6 +150,5 @@ https://symfony.com/doc/current/contributing/code/bc.html
148150

149151
.. _`Cropper.js`: https://fengyuanchen.github.io/cropperjs/
150152
.. _`the Symfony UX initiative`: https://symfony.com/ux
151-
.. _`@symfony/stimulus-bridge`: https://github.com/symfony/stimulus-bridge
152153
.. _`the Cropper.js options`: https://github.com/fengyuanchen/cropperjs/blob/main/README.md#options
153154
.. _`Symfony UX configured in your app`: https://symfony.com/doc/current/frontend/ux.html

0 commit comments

Comments
 (0)