55 * Though this script attempts to simplify, it borrows heavily from Symfony's approach.
66 *
77 * @see https://github.com/symfony/symfony/blob/7.2/.github/build-packages.php
8+ *
9+ * TODO: This script is not really optimized, because it runs on every unit test action.
810 */
911
1012$ tempestPackages = json_decode (
11- json: exec (__DIR__ . '/get-packages ' ),
12- associative: true
13+ json: exec (__DIR__ . '/get-packages ' ),
14+ associative: true
1315);
1416
15- $ composerPackages = [];
17+ $ composerPackages = [
18+ 'packages ' => [],
19+ ];
1620
1721foreach ($ tempestPackages as $ package ) {
1822 // Find out if there are changes in this package.
1923 $ diff = exec (sprintf ('git diff --name-only HEAD^ -- %s ' , $ package ['directory ' ]));
2024
21- // If there are not any changes, move on to the next package.
22- if (empty ($ diff )) {
23- continue ;
24- }
25-
26- // Bundle the current package as a tar file.
27- passthru (sprintf ("cd %s && tar -cf package.tar --exclude='package.tar' * " , $ package ['directory ' ]));
28-
2925 $ composerPath = sprintf ('%s/composer.json ' , $ package ['directory ' ]);
3026 $ composerFile = json_decode (file_get_contents ($ composerPath ), true );
3127
32- // TODO: Update this version.
33- $ composerFile ['version ' ] = 'dev-main ' ;
34- $ composerFile ['dist ' ]['type ' ] = 'tar ' ;
35- $ composerFile ['dist ' ]['source ' ] = $ package ['directory ' ] . '/package.tar ' ;
28+ // If there are changes, bundle the package and
29+ // add it to our root packages.json file.
30+ if (empty ($ diff ) === false ) {
31+ // Bundle the current package as a tar file.
32+ passthru (sprintf ("cd %s && tar -cf package.tar --exclude='package.tar' * " , $ package ['directory ' ]));
33+
34+ // TODO: Update the package version.
35+ $ composerFile ['version ' ] = 'dev-main ' ;
36+ $ composerFile ['dist ' ]['type ' ] = 'tar ' ;
37+ $ composerFile ['dist ' ]['url ' ] = 'file:// ' . $ package ['directory ' ] . '/package.tar ' ;
38+
39+ // Add the package details to the root "packages.json."
40+ $ composerPackages ['packages ' ][$ composerFile ['name ' ]][$ composerFile ['version ' ]] = $ composerFile ;
41+ }
3642
3743 // Load the packages from the root "packages.json" file we will write in a second.
3844 $ composerFile ['repositories ' ] = [
@@ -42,10 +48,9 @@ foreach ($tempestPackages as $package) {
4248 ]
4349 ];
4450
45- // Add the package details to the root "packages.json."
46- $ composerPackages [$ composerFile ['name ' ]][$ composerFile ['version ' ]] = $ composerFile ;
51+ file_put_contents ($ composerPath , json_encode ($ composerFile , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ));
4752}
4853
49- file_put_contents (__DIR__ . '/../packages.json ' , json_encode ($ composerPackages , JSON_PRETTY_PRINT ));
54+ file_put_contents (__DIR__ . '/../packages.json ' , json_encode ($ composerPackages , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ));
5055
5156var_dump (file_get_contents (__DIR__ . '/../packages.json ' ));
0 commit comments