Skip to content
Snippets Groups Projects
Commit 38777b90 authored by jurgenhaas's avatar jurgenhaas
Browse files

#17 Implement default settings for composer.json

parent 21948edf
No related branches found
No related tags found
1 merge request!230Merging develop into main
Pipeline #1255156 skipped
...@@ -30,6 +30,38 @@ class Plugin extends BasePlugin { ...@@ -30,6 +30,38 @@ class Plugin extends BasePlugin {
public function activate(Composer $composer, IOInterface $io): void { public function activate(Composer $composer, IOInterface $io): void {
parent::activate($composer, $io); parent::activate($composer, $io);
$this->scaffoldHandler = new DrupalScaffoldHandler($composer, $io); $this->scaffoldHandler = new DrupalScaffoldHandler($composer, $io);
$extra = $composer->getPackage()->getExtra();
if (isset($extra['lakedrops-config-file']) || isset($extra['lakedrops-curated-file'])) {
$config = $composer->getConfig()->all()['config'] ?? [];
if (isset($extra['lakedrops-config-file'])) {
$defaultConfig = $this->readJson('config', $extra['lakedrops-config-file'], $io);
$config = NestedArray::mergeDeep($defaultConfig, $config);
}
if (isset($extra['lakedrops-curated-file'])) {
$config['audit']['ignore'] = $this->readJson('audit ignore', $extra['lakedrops-curated-file'], $io);
}
$composerConfig = new Config();
$composerConfig->merge(['config' => $config]);
$composer->setConfig($composerConfig);
}
$extras = [
'drupal-libraries',
'drupal-scaffold',
'installer-types',
'installer-paths',
];
$changed = FALSE;
foreach ($extras as $item) {
$key = 'lakedrops-extra-' . $item . '-file';
if (isset($extra[$key])) {
$extra[$item] = $this->readJson($item, $extra[$key], $io);
$changed = TRUE;
}
}
if ($changed) {
$composer->getPackage()->setExtra($extra);
}
} }
/** /**
...@@ -53,54 +85,11 @@ class Plugin extends BasePlugin { ...@@ -53,54 +85,11 @@ class Plugin extends BasePlugin {
*/ */
public static function getSubscribedEvents(): array { public static function getSubscribedEvents(): array {
return [ return [
ScriptEvents::PRE_INSTALL_CMD => ['alterConfigAndExtras', 999],
ScriptEvents::PRE_UPDATE_CMD => ['alterConfigAndExtras', 999],
ScriptEvents::POST_CREATE_PROJECT_CMD => ['prepareProject', 1], ScriptEvents::POST_CREATE_PROJECT_CMD => ['prepareProject', 1],
ScriptEvents::POST_INSTALL_CMD => ['prepareProject', 1], ScriptEvents::POST_INSTALL_CMD => ['prepareProject', 1],
]; ];
} }
/**
* Post update project event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
*/
public function alterConfigAndExtras(Event $event): void {
$extra = $event->getComposer()->getPackage()->getExtra();
if (isset($extra['lakedrops-config-file']) || isset($extra['lakedrops-curated-file'])) {
$config = $event->getComposer()->getConfig()->all()['config'] ?? [];
if (isset($extra['lakedrops-config-file'])) {
$defaultConfig = $this->readJson('config', $extra['lakedrops-config-file'], $event->getIO());
$config = NestedArray::mergeDeep($defaultConfig, $config);
}
if (isset($extra['lakedrops-curated-file'])) {
$config['audit']['ignore'] = $this->readJson('audit ignore', $extra['lakedrops-curated-file'], $event->getIO());
}
$composerConfig = new Config();
$composerConfig->merge(['config' => $config]);
$event->getComposer()->setConfig($composerConfig);
}
$extras = [
'drupal-libraries',
'drupal-scaffold',
'installer-types',
'installer-paths',
];
$changed = FALSE;
foreach ($extras as $item) {
$key = 'lakedrops-extra-' . $item . '-file';
if (isset($extra[$key])) {
$extra[$item] = $this->readJson($item, $extra[$key], $event->getIO());
$changed = TRUE;
}
}
if ($changed) {
$event->getComposer()->getPackage()->setExtra($extra);
}
}
/** /**
* Post update project event callback. * Post update project event callback.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment