Laravel 用户界面框架。由 Tailwind CSS 驱动。

18.0.0 2024-09-27 09:29 UTC

This package is auto-updated.

Last update: 2024-09-27 09:32:46 UTC


README

Laravel 框架的框架。由 Tailwind CSS 和 Livewire 驱动。

可用组件列表

先决条件

由于此包依赖于一些第三方包,您需要安装并配置以下内容到您的项目中

安装

使用 composer 需要: composer require arkecosystem/foundation

用法

示例

Composer 脚本

将以下脚本添加到 composer.json

"scripts": [
    "analyse": [
        "vendor/bin/phpstan analyse --configuration=vendor/arkecosystem/foundation/phpstan.neon --memory-limit=2G"
    ],
    "format": [
        "vendor/bin/php-cs-fixer fix --config=vendor/arkecosystem/foundation/.php-cs-fixer.php"
    ],
    "refactor": [
        "./vendor/bin/rector process --config=vendor/arkecosystem/foundation/rector.php"
    ],
    "test": [
        "./vendor/bin/pest"
    ],
    "test:fast": [
        "./vendor/bin/pest --parallel"
    ],
    "test:coverage": [
        "./vendor/bin/pest --coverage --min=100 --coverage-html=.coverage --coverage-clover=coverage.xml"
    ]
],

在本地工作于组件

此包包含大量前端组件,但没有自己的前端视图。因此,当您需要在此上工作时,您需要依赖于来自其他项目的客户端。通常,这可以通过在 composer 中创建此包的符号链接来实现,但在这种情况下还需要进行第二个步骤,以确保您可以运行 yarn watchyarn prod 等。

我将详细说明,并以 marketsquare.io 项目为例。假设 marketsquare.io 和 laravel-foundation git 仓库都安装在我们的本地开发机的 /Users/my-user/projects/ 文件夹中。

步骤 1 - Composer 符号链接

在 marketsquare.io 下的 composer.json 文件中,“repositories” 部分,添加 laravel-foundation 作为路径

"repositories": [
    {
        "type": "path",
        "url": "../laravel-foundation"
    }
]

之后运行 composer require arkecosystem/foundation --ignore-platform-reqs -W。现在 laravel-foundation 包已被符号链接,您可以在 laravel-foundation 仓库中通过 IDE 进行工作。

步骤 2 - 符号链接 node_modules

如果您从 marketsquare.io 仓库运行 yarn watch,您将遇到许多错误,因为依赖项还不够智能,无法知道它们位于符号链接的目录中。

  • 删除 laravel-foundation 上的 node_modules 目录。
  • 通过运行 ln -s /Users/my-user/projects/marketsquare.io/node_modules node_modules(在 laravel-foundation 仓库中执行)将 marketsquare.io 上的 node_modules 目录符号链接到 laravel-foundation。

现在,当您返回到 marketsquare.io 仓库时,您可以运行 yarn watch

完成工作后,别忘了删除符号链接。

将这些步骤转换为脚本

请注意:

这些脚本是为 Mac 用户编写的。如果您使用其他操作系统,可能需要相应地进行调整。

unlink:foundation 使用 git 命令恢复当前项目。

为了提高您的开发流程,您可以将其转换为脚本,并在命令行中直接使用它们,例如

$ link:foundation
$ unlink:foundation

您可以将它们复制粘贴到 .bashrc.aliases 或您设置的任何其他用于管理别名的文件中。

在深入研究代码之前,让我解释一下您可以使用它们做什么(跳到代码)。

对于这些示例,我们使用 marketsquare.iolaravel-foundation 仓库,假设它们都安装在我们的本地开发机的同一文件夹(/Users/my-user/projects)中。

将当前项目符号链接到 laravel-foundation

# move into marketsquare.io folder
$ cd /Users/my-user/projects/marketsquare.io

# symlink to laravel-foundation repo
$ link:foundation

就是这样!

该脚本会自动尝试猜测 laravel-foundation 仓库的位置,并将当前项目符号链接到它(在这种情况下为 marketsquare.io)。

如果当前项目和 laravel-foundation 仓库不在同一文件夹中,脚本会尝试回到上一级目录(../../)并再次尝试。如果找不到 laravel-foundation,脚本将退出并输出错误信息。

您始终可以通过传递参数来指定一个自定义路径。

$ link:foundation 'Users/john/repos/laravel-foundation'

从您的当前项目中删除符号链接

# move into marketsquare.io folder
$ cd /Users/my-user/projects/marketsquare.io

# remove symlink
$ unlink:foundation

再次强调,就是这样!

脚本会查找由 link:foundation 创建的 .symlink_foundation 临时文件,其中包含符号链接的路径。如果未找到,它将尝试猜测 laravel-foundation 仓库的位置,并从当前项目(在这种情况下是 marketsquare.io)中删除符号链接。

如果当前项目和 laravel-foundation 仓库不在同一文件夹中,脚本会尝试回到上一级目录(../../)并再次尝试。如果找不到 laravel-foundation,脚本将退出并输出错误信息。

您始终可以通过传递参数来指定一个自定义路径。

$ unlink:foundation 'Users/john/repos/laravel-foundation'

代码

脚本本身就很直观,并且每行都有注释哦。

function link:foundation() {

    # Check if already symlinked
    [ -f .symlink_foundation ] && { echo "already symlinked"; return; }

    # Get path from args or guess it
    if [ "$1" != "" ]; then
        FOUNDATION="$1"
    elif [ -d ../laravel-foundation ]; then
        FOUNDATION="../laravel-foundation"
    elif [ -d ../../laravel-foundation ]; then
        FOUNDATION="../../laravel-foundation"
    else
        echo "Unable to find `laravel-foundation`"
        return
    fi

    # Generate random string
    RANDOM_STRING=$(base64 /dev/urandom | tr -d '/+' | dd bs=6 count=1 2>/dev/null)

    # Set Composer repo
    composer config repositories.${RANDOM_STRING} '{"type": "path", "url": "'${FOUNDATION}'"}'

    # Require arkecosystem/foundation
    composer require arkecosystem/foundation --ignore-platform-reqs -W

    # Remove node_modules folder
    rm -rf ${FOUNDATION}/node_modules

    # Symlink to arkecosystem/foundation node_modules folder
    ln -s $(pwd)/node_modules ${FOUNDATION}/node_modules

    # Create .symlink_foundation temp file
    echo ${FOUNDATION} >> .symlink_foundation

    # Inform user that all went ok
    echo "${FOUNDATION} has been symlinked"
}

function unlink:foundation() {

    # Get path from .symlink_foundation file or from args or guess it
    if [ -f .symlink_foundation ]; then
        FOUNDATION=$(cat .symlink_foundation)
    elif [ "$1" != "" ]; then
        FOUNDATION="$1"
    elif [ -d ../laravel-foundation ]; then
        FOUNDATION="../laravel-foundation"
    elif [ -d ../../laravel-foundation ]; then
        FOUNDATION="../../laravel-foundation"
    else
        echo "Unable to find `laravel-foundation`"
        return
    fi

    # Remove symlink
    unlink ${FOUNDATION}/node_modules

    # Remove temp file
    rm -rf .symlink_foundation

    # Clean up repo
    git reset --hard
    git clean -df

    # Inform user that all went ok
    echo "${FOUNDATION} symlink has been removed"
}