Improve link script with rollback when using symlink
This commit is contained in:
parent
7e24fc193a
commit
abf40ceb40
25
link
25
link
@ -18,19 +18,22 @@ require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php';
|
|||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Links dependencies to components to a local clone of the main symfony/symfony GitHub repository.
|
* Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.
|
||||||
*
|
*
|
||||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$copy = false !== $k = array_search('--copy', $argv, true);
|
$copy = false !== $k = array_search('--copy', $argv, true);
|
||||||
$copy && array_splice($argv, $k, 1);
|
$copy && array_splice($argv, $k, 1);
|
||||||
|
$rollback = false !== $k = array_search('--rollback', $argv, true);
|
||||||
|
$rollback && array_splice($argv, $k, 1);
|
||||||
$pathToProject = $argv[1] ?? getcwd();
|
$pathToProject = $argv[1] ?? getcwd();
|
||||||
|
|
||||||
if (!is_dir("$pathToProject/vendor/symfony")) {
|
if (!is_dir("$pathToProject/vendor/symfony")) {
|
||||||
echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
|
echo 'Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
|
||||||
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
|
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
|
||||||
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
|
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
|
||||||
|
echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL;
|
||||||
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
|
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -44,7 +47,6 @@ $directories = array_merge(...array_values(array_map(function ($part) {
|
|||||||
}, $braces)));
|
}, $braces)));
|
||||||
|
|
||||||
$directories[] = __DIR__.'/src/Symfony/Contracts';
|
$directories[] = __DIR__.'/src/Symfony/Contracts';
|
||||||
|
|
||||||
foreach ($directories as $dir) {
|
foreach ($directories as $dir) {
|
||||||
if ($filesystem->exists($composer = "$dir/composer.json")) {
|
if ($filesystem->exists($composer = "$dir/composer.json")) {
|
||||||
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
|
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
|
||||||
@ -53,12 +55,19 @@ foreach ($directories as $dir) {
|
|||||||
|
|
||||||
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
||||||
$package = 'symfony/'.basename($dir);
|
$package = 'symfony/'.basename($dir);
|
||||||
if (!$copy && is_link($dir)) {
|
|
||||||
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
|
if (!isset($sfPackages[$package])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($sfPackages[$package])) {
|
if ($rollback) {
|
||||||
|
$filesystem->remove($dir);
|
||||||
|
echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$copy && is_link($dir)) {
|
||||||
|
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,3 +87,7 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
|
|||||||
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
|
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
|
||||||
$filesystem->remove($cacheDir);
|
$filesystem->remove($cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($rollback) {
|
||||||
|
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user