Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.0.1
=====

* (improvement) Disable automatically running janus, as it often fails.
* (improvement) Bump dependencies.


2.0.0
=====

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"php": ">= 8.4",
"composer-plugin-api": "^2.6",
"21torr/cli": "^1.2.3",
"symfony/console": "^7.3",
"symfony/process": "^7.3"
"symfony/console": "^7.4 || ^8.0",
"symfony/process": "^7.4 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"composer/composer": "^2.8.9",
"phpstan/phpstan": "^2.1.17",
"bamarni/composer-bin-plugin": "^1.8.3",
"composer/composer": "^2.9.4",
"phpstan/phpstan": "^2.1.36",
"roave/security-advisories": "dev-latest"
},
"autoload": {
Expand Down
100 changes: 6 additions & 94 deletions src/Composer/JanusPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Janus\Composer;

use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\EventDispatcher\EventSubscriberInterface;
Expand All @@ -13,9 +12,6 @@
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Janus\Command\InitializeCommand;
use Janus\Package\PackageType;
use Symfony\Component\Process\Process;

/**
* @final
Expand Down Expand Up @@ -68,11 +64,6 @@ public function checkForJanusOperations (PackageEvent $event) : void
*/
private function isJanusUpdate (OperationInterface $operation) : bool
{
if ($operation instanceof InstallOperation)
{
return "21torr/janus" === $operation->getPackage()->getName();
}

if ($operation instanceof UpdateOperation)
{
return "21torr/janus" === $operation->getTargetPackage()->getName();
Expand All @@ -94,91 +85,12 @@ public function afterAutoloadDump (Event $event) : void
$this->hadJanusOperation = false;

$io = $event->getIO();
$io->write("\n<fg=magenta>Janus update detected, running janus update</>\n");

// please note, that the detection can fail: composer defaults to "library", if it's not set
$packageType = PackageType::tryFromComposerType(
$event->getComposer()->getPackage()->getType(),
);

if (null === $packageType)
{
$selected = $io->select(
"What are you currently using?",
InitializeCommand::ALLOWED_TYPES,
"library",
);
$packageType = PackageType::tryFromComposerType(InitializeCommand::ALLOWED_TYPES[$selected] ?? null);
}
else
{
$io->write(\sprintf(
"Detected package type <fg=yellow>%s</>",
$packageType->value,
));
}

$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
\assert(\is_string($vendorDir));

$success = $this->runJanus($io, $vendorDir, $packageType);

if ($success)
{
$io->write("\n<fg=green>Janus installation complete.</>\n");
}
else
{
$io->writeError("\n<fg=red>Janus installation failed, please run it manually: `composer exec janus init`</>\n");
}
}

/**
* Runs Janus
*/
private function runJanus (
IOInterface $io,
string $vendorDir,
?PackageType $type,
) : bool
{
$command = [
$this->findJanusExecutable($vendorDir),
"init",
];

if (null !== $type)
{
$command[] = $type->value;
}

$command[] = "--no-auto-install";
$command[] = "--ansi";

$output = new Process($command);
$output->run(
static function ($type, $buffer) use ($io) : void
{
$io->write($buffer);
},
);

return $output->isSuccessful();
}

/**
* Finds the path to the janus executable
*/
private function findJanusExecutable (string $vendorDir) : string
{
// first check if it's installed in the project via composer
if (is_dir("{$vendorDir}/bin/janus"))
{
return "{$vendorDir}/bin/janus";
}

// otherwise just fetch the executable from the library and run it
return \dirname(__DIR__, 2) . "/bin/janus";
$io->write("\n<fg=red>Janus update detected, you need to run janus:</>\n");
$io->write("\n");
$io->write(" ╭───────────────────────────────────────────╮\n");
$io->write(" │ <fg=magenta>$ composer exec janus init</> │\n");
$io->write(" ╰───────────────────────────────────────────╯\n");
$io->write("\n");
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Package/PackageInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function initializeSymfony (ComposerJson $composerJson) : void

$composerJson->updateScripts("fix-lint", [
"normalize" => "@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --ansi",
"cs-fixer" => "PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi",
"cs-fixer" => "vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --allow-unsupported-php-version=yes --no-interaction --ansi",
]);

$composerJson->updateScripts("lint", [
"lint:yaml" => "bin/console lint:yaml config --parse-tags",
"lint:twig" => "bin/console lint:twig templates",
"normalize" => "@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --dry-run --ansi",
"cs-fixer" => "PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi",
"cs-fixer" => "vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --allow-unsupported-php-version=yes --no-interaction --ansi",
]);

$composerJson->updateScripts("test", [
Expand Down Expand Up @@ -77,12 +77,12 @@ public function initializeLibrary (ComposerJson $composerJson) : void

$composerJson->updateScripts("fix-lint", [
"normalize" => "@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --ansi",
"cs-fixer" => "PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi",
"cs-fixer" => "vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --allow-unsupported-php-version=yes --no-interaction --ansi",
]);

$composerJson->updateScripts("lint", [
"normalize" => "@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --dry-run --ansi",
"cs-fixer" => "PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi",
"cs-fixer" => "vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --allow-unsupported-php-version=yes --no-interaction --ansi",
]);

$composerJson->updateScripts("test", [
Expand Down