Skip to content

Instantly share code, notes, and snippets.

@flibidi67
Created September 11, 2020 14:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flibidi67/7c2cfdc1ff1b977b48204be0bee5eb76 to your computer and use it in GitHub Desktop.
Save flibidi67/7c2cfdc1ff1b977b48204be0bee5eb76 to your computer and use it in GitHub Desktop.
Script for handle two vendor directory
#!/bin/bash
MY_VENDOR_DIRECTORY=my-vendor
VENDOR_DIRECTORY=vendor
if [ ! -d "$MY_VENDOR_DIRECTORY" ]
then
echo "Le dossier $MY_VENDOR_DIRECTORY n'existe pas : on le crée."
mkdir $MY_VENDOR_DIRECTORY
else
echo "Le dossier $MY_VENDOR_DIRECTORY existe : on le vide."
rm -rf $MY_VENDOR_DIRECTORY/*
fi
echo "Copie des fichiers autoload généré depuis $VENDOR_DIRECTORY vers $MY_VENDOR_DIRECTORY."
cp $VENDOR_DIRECTORY/autoload.php $MY_VENDOR_DIRECTORY
cp -R $VENDOR_DIRECTORY/composer $MY_VENDOR_DIRECTORY
cd $MY_VENDOR_DIRECTORY/composer
echo "Remplacement de 'require \$file' par \str_replace(\"my-vendor\/composer\/..\", \"vendor\", \$file)"
sed -i 's/require $file/require \\str_replace("my-vendor\/composer\/..", "vendor", $file)/' autoload_real.php
echo "Remplacement de 'include \$file' par \str_replace(\"my-vendor\/composer\/..\", \"vendor\", \$file) "
sed -i 's/include $file/require \\str_replace("my-vendor\/composer\/..", "vendor", $file)/' ClassLoader.php
@flibidi67
Copy link
Author

flibidi67 commented Sep 11, 2020

This script can be usefull when you want two Laravel projects to share the same vendor folder.

  1. Put this script at the root of your differents projects (dont forget to chmod +x)
  2. In public/index.php, replace require __DIR__.'/../vendor/autoload.php'; by require __DIR__.'/../my-vendor/autoload.php';
  3. Add ./my-vendor.sh in your composer.json in the post-autoload-dump
  4. (Optionnal) Add my-vendor directory in your .gitignore

I only try this shellscript in the context of two laravel projects which shares the same vendor folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment