getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.51k stars 1.4k forks source link

bin/grav new-project fails to create symlinks for plugins/themes #3740

Closed hugus777 closed 1 year ago

hugus777 commented 1 year ago

Trying to create a new project with the symlink option fails to create symlinks for plugins and themes. On a clean Grav install (Composer, Grav CLI Application 1.7.42.3), running bin/grav new-project -s ../grav-copy results in:

Symlinking Bits
===============

source for grav-plugin-problems does not exists, skipping...

source for grav-plugin-error does not exists, skipping...

source for grav-plugin-markdown-notices does not exists, skipping...

source for grav-theme-quark does not exists, skipping...

A local configuration file ~/.grav/config does exist and provides a symlink path of the type github_repos: /Users/your_user/Projects/Grav/, in line with the documentation.

Checking the source code the error seems to be in InstallCommand.php: https://github.com/getgrav/grav/blob/490bdd6ce7aaae315c033ca5af112a778a42455a/system/src/Grav/Console/Cli/InstallCommand.php#L225

Replacing $src by $path solves the problem.

Symlinking Bits
===============

Processing problems
SUCCESS

Processing error
SUCCESS

SUCCESS symlinked grav-plugin-markdown-notices -> user/plugins/markdown-notices

SUCCESS symlinked grav-theme-quark -> user/themes/quark
rhukster commented 1 year ago

This doesn't make any sense to me.. The $src is the 'source' where you are copying from, and the $path is the 'destination' where the file is going.

The line you modified:

$test = rtrim($location, '\\/') . DS . $src;

should build something like /Users/your_user/Projects/Grav/grav-plugin-markdown-notices .. This is your source of your cloned repo.. if you replaced this $src with $path you would get: /Users/your_user/Projects/Grav/user/plugins-markdown-notices. This is not going to be the name of your cloned repo unless you created a user subfolder manually and cloned the repos with a custom name of plugins-markdown-notices.

For me in my testing, it works out-of-the-box as intended. If i try to change $src to path, i get those ERROR messages you started wtih.

hugus777 commented 1 year ago

Thanks, I see now that I got the use case wrong. If I follow the steps in the documentation (slightly edited to account for the latest default plugins/theme)

cd
mkdir Projects
cd Projects
mkdir Grav
cd Grav
git clone https://github.com/getgrav/grav.git
git clone https://github.com/getgrav/grav-plugin-error.git
git clone https://github.com/getgrav/grav-plugin-problems.git
git clone https://github.com/getgrav/grav-plugin-markdown-notices.git
git clone https://github.com/getgrav/grav-theme-quark.git

followed by (with ~/.grav/config containing github_repos: /home/user/Projects/Grav/)

cd grav
bin/grav new-project -s ../grav-copy

it does work indeed.

My confusion came from the fact that when you do a fresh composer install, it also clones the plugins and theme in the user directory (e.g. SUCCESS cloned https://github.com/getgrav/grav-plugin-problems -> /home/user/Projects/Grav/grav/user/plugins/problems) so this is what I was trying to have symlinked...