Answer the question
In order to leave comments, you need to log in
How to create a directory when installing a package from Github?
Good afternoon!
I can't figure it out, I need to programmatically create directories when installing a particular package. There are some modules and there is one base module (vendor/username/core), inside of which in the folder (..repo../modules) there should be those very few modules.
I have a custom installer, it works great (installs packages in certain directories like this package), but the problem is that all these some modules go in dependencies in the base module and must be stored INSIDE it and therefore during installation: composer require username/core
they go to inconsistency, i.e. they can be installed before the base module:
- installing module1
- installing module2
- installing core
- installing moduleN
Accordingly, those that were installed before the base module will not be installed, how to solve this, I added a new class to the installer:
/**
* <code>
* "extra": {
* "encore-composer-mkdir": [
* "vendor/username/core/modules",
* "folder2/folde22"
* ]
* }
* </code>
*
*/
class ScriptHandlerHelper
{
public static function mkdirs(Event $event)
{
$extras = $event->getComposer()->getPackage()->getExtra();
if (! isset($extras['composer-mkdir'])) {
$message = 'The mkdir handler needs to be configured through the extra.composer-mkdir setting.';
throw new InvalidArgumentException($message);
}
if (! is_array($extras['composer-mkdir'])) {
$message = 'The extra.composer-mkdir setting must be an array.';
throw new InvalidArgumentException($message);
}
$legacy = array_filter($extras['composer-mkdir'], function ($directory) {
return !is_string($directory);
});
if (!empty($legacy)) {
$message = 'Since 2.0, mode is no longer supported. See UPGRADE-2.0.md for further details.';
throw new InvalidArgumentException($message);
}
$directories = array_filter($extras['composer-mkdir'], function ($directory) {
return !file_exists($directory);
});
foreach ($directories as $directory) {
mkdir($directory, 0777, true);
}
}
}
"scripts": {
"post-package-install": [
//МБ это вариант?
],
"post-install-cmd": [
"username\\CustomInstaller\\ScriptHandlerHelper::mkdirs"
],
"post-update-cmd": [
"username\\CustomInstaller\\ScriptHandlerHelper::mkdirs"
]
},
"extra": {
"composer-mkdir": [
"vendor/username/core/modules" - данные пути должны создаться
]
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question