Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/expression-language": "^6.4 || ^7.0",
"symfony/filesystem": "^6.4 || ^7.0",
"symfony/http-client": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/security-bundle": "^6.4 || ^7.0",
Expand Down
97 changes: 97 additions & 0 deletions link
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env php
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (!is_dir(__DIR__.'/vendor/')) {
echo "Missing composer dependencies. Please run \"composer install\"".PHP_EOL;
exit(1);
}

require __DIR__.'/vendor/symfony/filesystem/Exception/ExceptionInterface.php';
require __DIR__.'/vendor/symfony/filesystem/Exception/IOExceptionInterface.php';
require __DIR__.'/vendor/symfony/filesystem/Exception/IOException.php';
require __DIR__.'/vendor/symfony/filesystem/Filesystem.php';

use Symfony\Component\Filesystem\Filesystem;

/**
* Links dependencies of a project to a local clone of the main Sylius/Stack GitHub repository.
*
* Heavily inspired by the Symfony link script, original author is Kévin Dunglas <[email protected]>
* See https://github.com/symfony/symfony/blob/7.3/link
*
* (c) Fabien Potencier
*/

$copy = false !== $k = array_search('--copy', $argv, true);
$copy && array_splice($argv, $k, 1);
$rollback = false !== $k = array_search('--rollback', $argv, true);
$rollback && array_splice($argv, $k, 1);
$pathToProject = $argv[1] ?? getcwd();

if (!is_dir("$pathToProject/vendor/sylius")) {
echo 'Links dependencies of a project to a local clone of the main Sylius/Stack GitHub repository.'.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 ' 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;
exit(1);
}

$stackPackages = [];

$filesystem = new Filesystem();
$directories = glob(__DIR__.'/src/*', GLOB_ONLYDIR | GLOB_NOSORT);

foreach ($directories as $dir) {
if ($filesystem->exists($composer = "$dir/composer.json")) {
$stackPackages[json_decode($filesystem->readFile($composer), flags: JSON_THROW_ON_ERROR)->name] = $dir;
}
}

foreach (glob("$pathToProject/vendor/sylius/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$package = 'sylius/'.basename($dir);

if (!isset($stackPackages[$package])) {
continue;
}

if ($rollback) {
$filesystem->remove($dir);
echo "\"$package\" has been rollback from \"$stackPackages[$package]\".".PHP_EOL;
continue;
}

if (!$copy && is_link($dir)) {
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
continue;
}

$sfDir = ('\\' === DIRECTORY_SEPARATOR || $copy) ? $stackPackages[$package] : $filesystem->makePathRelative($stackPackages[$package], dirname(realpath($dir)));

$filesystem->remove($dir);

if ($copy) {
$filesystem->mirror($sfDir, $dir);
echo "\"$package\" has been copied from \"$stackPackages[$package]\".".PHP_EOL;
} else {
$filesystem->symlink($sfDir, $dir);
echo "\"$package\" has been linked to \"$stackPackages[$package]\".".PHP_EOL;
}
}

foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
$filesystem->remove($cacheDir);
}

if ($rollback) {
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
}