Skip to content

Commit

Permalink
Support for multiple project config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Stark committed Sep 7, 2020
1 parent 608ca46 commit d64f7aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Runs migrations automatically",
"keywords": ["composer", "development", "craftcms"],
"type": "composer-plugin",
"version": "2.0.0",
"version": "2.1.0",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
18 changes: 10 additions & 8 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public static function getSubscribedEvents()
/**
* Initialize Composer plugin
*
* @param Composer $composer
* @param Composer $composer
* @param IOInterface $io
*/
public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->io = $io;
$this->io = $io;
}

/**
Expand All @@ -64,7 +64,9 @@ public function activate(Composer $composer, IOInterface $io)
public function runCommands()
{
if (getenv('DISABLE_CRAFT_AUTOMIGRATE') == 1) {
$this->io->write(PHP_EOL . "▶ <info>Craft auto migrate</info> disabled by ENV var: DISABLE_CRAFT_AUTOMIGRATE");
$this->io->write(
PHP_EOL . "▶ <info>Craft auto migrate</info> disabled by ENV var: DISABLE_CRAFT_AUTOMIGRATE"
);
return true;
}

Expand All @@ -91,7 +93,6 @@ public function runCommands()


if ($this->hasProjectConfigFile()) {

$cmd = new CraftCommand(
["project-config/sync"],
new ProcessExecutor($this->io)
Expand All @@ -102,7 +103,7 @@ public function runCommands()
$this->io->write(PHP_EOL . $cmd->getOutput());
} else {
$this->io->writeError(PHP_EOL . "▶ <info>Craft auto migrate</info> [project-config/sync ERROR]");
$this->io->writeError(PHP_EOL .$cmd->getErrorOutput());
$this->io->writeError(PHP_EOL . $cmd->getErrorOutput());
return false;
}
}
Expand Down Expand Up @@ -139,10 +140,11 @@ protected function isCraftInstalled()
*/
protected function hasProjectConfigFile(): bool
{
$projectRoot = realpath(dirname(Factory::getComposerFile()));
$pathToConfig = $projectRoot . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'project.yaml';
$projectRoot = realpath(dirname(Factory::getComposerFile()));
$pathToConfigFile = $projectRoot . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'project.yaml';
$pathToConfigDir = $projectRoot . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'project';

return (file_exists($pathToConfig)) ? true : false;
return (file_exists($pathToConfigFile) || is_dir($pathToConfigDir)) ? true : false;
}

}

0 comments on commit d64f7aa

Please sign in to comment.