hgraca/composer-shell-plugin

一个用于管理shell依赖的composer插件。

v2.0.2 2023-08-20 19:28 UTC

This package is auto-updated.

Last update: 2024-09-20 22:07:11 UTC


README

build status coverage report

一个用于管理shell依赖的composer插件。

工作原理

该插件为shell包中的shell脚本生成自动加载器,然后在我们要使用依赖项的shell脚本的入口点中需要将其源(包含)。

这正是PHP包所发生的情况。

要生成shell自动加载器,它会遍历所有包,并为每个shell包搜索所有shell脚本,并将它们添加到shell自动加载器中。

如何使用

除了以下内容外,所有操作都与PHP项目相同。

在依赖于shell包的项目中

安装并允许插件

composer require "hgraca/composer-shell-plugin"
{
  "name": "hgraca/some-project",
  "type": "project",
  "require": {
    "hgraca/composer-shell-plugin": "dev-main"
  },
  "config": {
    "allow-plugins": {
      "hgraca/composer-shell-plugin": true
    }
  }
}

在脚本入口点中包含自动加载器

#!/usr/bin/env bash

# The "VENDOR_PATH" variable MUST be defined, as the autoloader depends on it,
# because there is no posix compliant way to infer this.
VENDOR_PATH="..."
. "${VENDOR_PATH}/autoload.sh"

# call the functions in the installed projects

在shell包中

标记项目为shell项目/库

在shell包的composer.json中,将包类型设置为shell-projectshell-library

例如

{
  "name": "hgraca/dummy-shell-project-2",
  "type": "shell-library",
  "description": "A project to manually test the composer-shell-plugin plugin by being installed in another project."
}

一个工作示例

要查看工作示例,请检查tests/PluginTestPlayground

请随意运行

composer -d tests/PluginTestPlayground/TestProject install
tests/PluginTestPlayground/TestProject/bin/run.sh

定义包含shell脚本的文件夹(可选)

在shell包的composer.json中,在extra.hgraca/composer-shell-plugin.source-folders中设置应添加到自动加载器的文件夹列表。

这是可选的,默认情况下将使用src文件夹。

例如

{
    "name": "hgraca/dummy-shell-project-1",
    "type": "shell-library",
    "description": "A project to manually test the composer-shell-plugin plugin by being installed in another project.",
    "extra": {
        "hgraca/composer-shell-plugin": {
            "source-folders": [
                "src",
                "lib"
            ]
        }
    }
}

如何运行

使用本地PHP(8.2)

  • 使用composer install安装依赖项;
  • 可以使用composer run-app运行食谱;
  • 可以使用composer test运行测试;
  • 要列出所有自定义脚本,请运行composer run-script --list

使用Docker

  • ./build中更改PHP和xdebug配置;
  • 使用docker compose -f ./build/docker-compose.yaml run app composer install安装依赖项;
  • 可以使用docker compose -f ./build/docker-compose.yaml run app composer run-app运行食谱;
  • 可以使用composer docker-test运行测试;
  • 要列出所有自定义脚本,请运行docker compose -f ./build/docker-compose.yaml run app composer run-script --list

其他命令

  • composer git-bundle:创建一个git bundle
  • git clone -b main composer-shell-plugin.gitbundle composer-shell-plugin:从git bundle重新创建存储库

作者

Herberto Graca