forked from symfony/ux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Asset Mapper support + new StimulusBundle
- Loading branch information
1 parent
ce1bcfb
commit b8acf1a
Showing
160 changed files
with
3,718 additions
and
882 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.