sweetchuck/robo-composer

Robo task wrapper for Composer

Installs: 84 581

Dependents: 5

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 3

Type:robo-tasks

v0.2.0 2020-07-05 13:25 UTC

This package is auto-updated.

Last update: 2022-11-30 21:30:04 UTC


README

CircleCI codecov

@todo

Install

Run composer require --dev sweetchuck/robo-composer

Task - taskComposerLockDiffer

<?php

declare(strict_types = 1);

class RoboFileExample extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Composer\ComposerTaskLoader;

    /**
     * @hook validate @validateArgumentFileName
     */
    public function validateArgumentFileName(\Consolidation\AnnotatedCommand\CommandData $commandData)
    {
        $argNames = $commandData->annotationData()->getList(__FUNCTION__);
        $input = $commandData->input();
        foreach ($argNames as $argName) {
            assert($input->hasArgument($argName), 'invalid argument name');
            $input->setArgument(
                $argName,
                $this->processFileName($input->getArgument($argName)),
            );
        }
    }

    /**
     * @command composer:lock-diff
     *
     * @validateArgumentFileName fileA,fileB
     */
    public function composerLockDiff(string $fileA, string $fileB)
    {
        $a = json_decode(file_get_contents($fileA), true);
        $b = json_decode(file_get_contents($fileB), true);

        return $this
            ->collectionBuilder()
            ->addTask(
                $this
                    ->taskComposerLockDiffer()
                    ->setLockA($a)
                    ->setLockB($b)
            )
            ->addCode(function (\Robo\State\Data $data): int {
                $this
                    ->output()
                    ->writeln(\Symfony\Component\Yaml\Yaml::dump($data['composer.lockDiff']));

                return 0;
            });
    }

    protected function processFileName(string $fileName): string
    {
        return preg_replace('@^/proc/self/fd/(\d+)$@', 'php://fd/$1', $fileName);
    }
}

Run: vendor/bin/robo composer:lock-diff <(git show 'HEAD^:composer.lock') ./composer.lock
Example output:

symfony/filesystem:
    name: symfony/filesystem
    version_old: v4.4.5
    version_new: v4.4.18
    required_as: null
symfony/finder:
    name: symfony/finder
    version_old: v4.4.5
    version_new: v5.2.1
    required_as: null

Task - taskComposerPackagePaths

<?php

declare(strict_types = 1);

class RoboFileExample extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Composer\ComposerTaskLoader;

    /**
     * @command composer:package-paths
     */
    public function composerPackagePaths()
    {
        return $this
            ->collectionBuilder()
            ->addTask($this->taskComposerPackagePaths())
            ->addCode(function (\Robo\State\Data $data): int {
                $output = $this->output();
                foreach ($data['composer.packagePaths'] as $name => $path) {
                    $output->writeln("$name => $path");
                }

                return 0;
            });
    }
}

Run: vendor/bin/robo composer:package-paths
Example output:

symfony/filesystem => /my_project_01/vendor/symfony/filesystem
symfony/finder => /my_project_01/vendor/symfony/finder