如何列出Laravel项目中安装的所有composer模块和GitHub URL



我正在构建一种分析软件。

如何在Laravel项目中找到已安装的composer/PHP模块的Github URL?

我希望看到所有这些URL,而不是像一个URL那样,而是像控制台中的列表一样。

类似这样的东西:

{ "type": "vcs", "url": "https://github.com/twigphp/Twig" },
{ "type": "vcs", "url": "https://github.com/sitepoint/Rauth" },
{ "type": "vcs", "url": "https://github.com/PHP-DI/PHP-DI" },
{ "type": "vcs", "url": "https://github.com/nikic/FastRoute" },
{ "type": "vcs", "url": "https://github.com/guzzle/guzzle" },
{ "type": "vcs", "url": "https://github.com/Respect/Validation" },
{ "type": "vcs", "url": "https://github.com/doctrine/annotations" },
{ "type": "vcs", "url": "https://github.com/thephpleague/glide" },
{ "type": "vcs", "url": "https://github.com/tamtamchik/simple-flash" },
{ "type": "vcs", "url": "https://github.com/Seldaek/monolog" },
{ "type": "vcs", "url": "https://github.com/cakephp/orm" },
{ "type": "vcs", "url": "https://github.com/Bee-Lab/bowerphp" },
{ "type": "vcs", "url": "https://github.com/markstory/mini-asset" },
{ "type": "vcs", "url": "https://github.com/natxet/CssMin" },
{ "type": "vcs", "url": "https://github.com/linkorb/jsmin-php" },
{ "type": "vcs", "url": "https://github.com/consolidation-org/Robo" },
{ "type": "vcs", "url": "https://github.com/symfony/var-dumper" },
{ "type": "vcs", "url": "https://github.com/consolidation-org/Robo" },

composer info不会为您提供这些信息。

最简单的方法是直接从composer.lock获得它。您可以使用像jq这样的现成工具,而不是编写自己的解析器。

下载后,你可以写一个这样的表达式:

jq -c ".packages[]|{url:.source.url, type: .source.type}" composer.lock

这将过滤composer.lockpackages属性,并将创建与您想要的输出非常相似的输出。例如:

{"url":"https://github.com/api-platform/api-pack.git","type":"git"}
{"url":"https://github.com/api-platform/core.git","type":"git"}
{"url":"https://github.com/aws/aws-sdk-php.git","type":"git"}
{"url":"https://github.com/aws/aws-sdk-php-symfony.git","type":"git"}
{"url":"https://github.com/beberlei/DoctrineExtensions.git","type":"git"}

另一个表达式将创建一个对象数组,已经像您的示例中那样以逗号分隔(但不太紧凑(:

jq "[.packages[]|{url:.source.url, type: .source.type}]" composer.lock

结果:

[
{
"url": "https://github.com/api-platform/api-pack.git",
"type": "git"
},
{
"url": "https://github.com/api-platform/core.git",
"type": "git"
},
{
"url": "https://github.com/aws/aws-sdk-php.git",
"type": "git"
},
{
"url": "https://github.com/aws/aws-sdk-php-symfony.git",
"type": "git"
},
{
"url": "https://github.com/beberlei/DoctrineExtensions.git",
"type": "git"
}
[...]
]

相关内容

  • 没有找到相关文章

最新更新