slowprog/composer-copy-file

Composer 脚本在安装后复制您的文件

0.3.3 2020-07-02 14:44 UTC

This package is auto-updated.

Last update: 2024-08-29 04:14:27 UTC


README

Build Status Latest Stable Version Total Downloads

Composer 复制文件

Composer 脚本在安装后复制您的文件。支持复制整个目录、单个文件以及复杂的嵌套目录。

例如复制字体文件

{
    "require":{
        "twbs/bootstrap": "~3.3",
        "slowprog/composer-copy-file": "~0.3"
    },
    "scripts": {
        "post-install-cmd": [
            "SlowProg\\CopyFile\\ScriptHandler::copy"
        ],
        "post-update-cmd": [
            "SlowProg\\CopyFile\\ScriptHandler::copy"
        ]
    },
    "extra": {
        "copy-file": {
            "vendor/twbs/bootstrap/fonts/": "web/fonts/"
        }
    }
}

在开发中,您可能使用 -dev 后缀。例如,在开发中复制未压缩文件,在生产中复制压缩文件。

{
    "require":{
        "twbs/bootstrap": "~3.3",
        "slowprog/composer-copy-file": "~0.3"
    },
    "scripts": {
        "post-install-cmd": [
            "SlowProg\\CopyFile\\ScriptHandler::copy"
        ],
        "post-update-cmd": [
            "SlowProg\\CopyFile\\ScriptHandler::copy"
        ]
    },
    "extra": {
        "copy-file": {
            "vendor/twbs/bootstrap/dist/js/bootstrap.min.js": "web/js/bootstrap.js"
        },
        "copy-file-dev": {
            "vendor/twbs/bootstrap/dist/js/bootstrap.js": "web/js/bootstrap.js"
        }
    }
}

用例

在使用最后一个斜杠时需要小心。文件目标与目录目标在斜杠的使用上不同。

如果在目标目录中已经存在文件的副本,则它将被覆盖。要仅覆盖较旧的文件,请将 ? 添加到目标路径的末尾。

源目录层次结构

dir/
    subdir/
        file1.txt
        file2.txt
  1. 目录到目录

    {
        "extra": {
            "copy-file": {
                "dir/subdir/": "web/other/"
            }
        }
    }
    

    结果

    web/
        other/
            file1.txt
            file2.txt
    
  2. 文件到目录

    {
        "extra": {
            "copy-file": {
                "dir/subdir/file1.txt": "web/other/",
                "dir/subdir/file2.txt": "web/other/file2.txt/"
            }
        }
    }
    

    结果

    web/
        other/
            file1.txt
            file2.txt/
                file2.txt
    
  3. 文件到文件

    {
        "extra": {
            "copy-file": {
                "dir/subdir/file1.txt": "web/other/file1.txt",
                "dir/subdir/file2.txt": "web/other/file_rename.txt"
            }
        }
    }
    

    结果

    web/
        other/
            file1.txt
            file_rename.txt
    
  4. 仅覆盖较旧的文件

    {
        "extra": {
            "copy-file": {
                "dir/subdir/": "web/other/?"
            }
        }
    }
    

    预设

    web/
        other/
            file1.txt - Recently modified
            file2.txt - Old rotten file
    

    结果

    web/
        other/
            file1.txt - Not changed
            file2.txt - Replaced
    
  5. 使用正则表达式模式过滤源文件

    {
        "extra": {
            "copy-file": {
                "dir/subdir#1\.\w{3}$": "web/other/"
            }
        }
    }
    

    结果

    web/
        other/
            file1.txt