From e9eba2b9a7747a229e5f772caa0e932b112efba6 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Mon, 18 Dec 2023 21:34:09 +0100 Subject: [PATCH] Add link script and update .gitattributes Added a script named 'link' to help automate linking project dependencies. .gitattributes has also been updated with new file paths. This enhancement will facilitate and streamline the project setup process by automating preparation tasks. --- .gitattributes | 11 ++++---- link | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 link diff --git a/.gitattributes b/.gitattributes index 90c4a5d..91d3c46 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,14 +1,15 @@ * text=auto /.github export-ignore -/doc export-ignore /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.php_cs.dist export-ignore -/.scrutinizer.yml export-ignore -/.travis.yml export-ignore /CODE_OF_CONDUCT.md export-ignore -/README.md export-ignore +/ecs.php export-ignore +/infection.json.dist export-ignore +/link export-ignore +/Makefile export-ignore /phpstan.neon export-ignore +/phpstan-baseline.neon export-ignore /phpunit.xml.dist export-ignore +/rector export-ignore diff --git a/link b/link new file mode 100644 index 0000000..e25523c --- /dev/null +++ b/link @@ -0,0 +1,68 @@ +#!/usr/bin/env php +exists($composer = "$dir/composer.json")) { + $packages[json_decode(file_get_contents($composer))->name] = $dir; + } +} + +if (is_dir("$pathToProject/vendor/spomky-labs/phpwa")) { + if ($filesystem->exists($composer = "$pathToProject/vendor/spomky-labs/phpwa/composer.json")) { + $packages[json_decode(file_get_contents($composer))->name] = realpath(__DIR__); + } +} + +foreach (glob("$pathToProject/vendor/spomky-labs/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { + $package = 'spomky-labs/'.basename($dir); + if (!$copy && is_link($dir)) { + echo "\"$package\" is already a symlink, skipping.".PHP_EOL; + continue; + } + + if (!isset($packages[$package])) { + continue; + } + + $packageDir = ('\\' === DIRECTORY_SEPARATOR || $copy) ? $packages[$package] : $filesystem->makePathRelative($packages[$package], dirname(realpath($dir))); + $filesystem->remove($dir); + + if ($copy) { + $filesystem->mirror($packageDir, $dir); + echo "\"$package\" has been copied from \"$packages[$package]\".".PHP_EOL; + } else { + $filesystem->symlink(rtrim($packageDir, '/'), $dir); + echo "\"$package\" has been linked to \"$packages[$package]\".".PHP_EOL; + } +}