tarekdj/composer-copy-file

Composer 脚本在安装后复制文件

0.2.0 2017-03-26 15:42 UTC

This package is not auto-updated.

Last update: 2024-09-19 04:34:46 UTC


README

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

例如复制字体文件

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

用例

使用时要注意最后一个斜杠。文件目标与目录目标有斜杠的区别。

源目录层次结构

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

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

    结果

    web/
        other/
            file1.txt
            file2.txt
            .hidden
    
  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/file1.txt": ["web/folder/file1.txt", "web/other/file1.txt"]
            }
        }
    }
    

    结果

    web/
        folder/
            file1.txt
        other/
            file1.txt
    

致谢

感谢 Slowprog 提供基础项目 - https://github.com/slowprog