Allow copy instead of symlink for ./link script
This commit is contained in:
parent
7a13ea3efb
commit
b28fe66363
21
link
21
link
|
@ -23,11 +23,14 @@ use Symfony\Component\Filesystem\Filesystem;
|
||||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$copy = false !== $k = array_search('--copy', $argv, true);
|
||||||
|
$copy && 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 dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
|
echo 'Link (or copy) dependencies to components 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.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 "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);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +51,7 @@ 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 (is_link($dir)) {
|
if (!$copy && is_link($dir)) {
|
||||||
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
|
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -57,11 +60,17 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sfDir = '\\' === DIRECTORY_SEPARATOR ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir)));
|
$sfDir = ('\\' === DIRECTORY_SEPARATOR || $copy) ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir)));
|
||||||
|
|
||||||
$filesystem->remove($dir);
|
$filesystem->remove($dir);
|
||||||
$filesystem->symlink($sfDir, $dir);
|
|
||||||
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
|
if ($copy) {
|
||||||
|
$filesystem->mirror($sfDir, $dir);
|
||||||
|
echo "\"$package\" has been copied from \"$sfPackages[$package]\".".PHP_EOL;
|
||||||
|
} else {
|
||||||
|
$filesystem->symlink($sfDir, $dir);
|
||||||
|
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
|
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
|
||||||
|
|
Reference in New Issue