bash Composer 无法运行安装后脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33550138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:52:41  来源:igfitidea点击:

Composer unable to run post install script

bashcomposer-php

提问by grim

I'm getting the following error when trying to run a bash script in Composer post install/update hooks:

尝试在 Composer 安装/更新后挂钩中运行 bash 脚本时出现以下错误:

> post-install.sh
sh: 1: post-install.sh: not found
Script post-install.sh handling the post-install-cmd event returned with an error



  [RuntimeException]
  Error Output: sh: 1: post-install.sh: not found

Original composer.json

原作曲家.json

Works but it's just annoying to update the post install/update commands to run in two places.

有效,但更新安装/更新后命令以在两个地方运行只是很烦人。

{
  "require": {
    "twbs/bootstrap": "3.3.5"
    ...
    ...
  },
  "scripts": {
    "post-install-cmd": [
      "mkdir -p _libraries",
      "cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/",
      ...
      ...
    ],
    "post-update-cmd": [
      "mkdir -p _libraries",
      "cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/",
      ...
      ...
    ]
  }
}

According to the Composer documentation:

根据Composer 文档

A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command-line executable command.

在 Composer 的术语中,脚本可以是 PHP 回调(定义为静态方法)或任何命令行可执行命令。

So my composer.jsonshould be able to work as such:

所以我composer.json应该能够这样工作:

Wanted composer.json

想要 composer.json

{
  "require": {
    "twbs/bootstrap": "3.3.5"
    ...
    ...
  },
  "scripts": {
    "post-install-cmd": [
      "post-install.sh"
    ],
    "post-update-cmd": [
      "post-install.sh"
    ]
  }
}

post-install.sh

安装后.sh

Executable by everyone (0775) and located in the same directory as the composer.json

每个人都可以执行 ( 0775) 并与 composer.json 位于同一目录中

#!/bin/bash

mkdir -p _libraries
cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/
...
...

采纳答案by hek2mgl

In commentsI suggested to use

评论中我建议使用

bash post-install.sh

This seems working.

这似乎有效。

回答by Wirone

Other way to achieve single task definition is referencing scripts:

实现单个任务定义的其他方法是引用脚本

{
  "require": {
    "twbs/bootstrap": "3.3.5"
    ...
  },
  "scripts": {
    "your-cmd": [
      "mkdir -p _libraries",
      "cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/",
      ...
    ],
    "post-install-cmd": [
      "@your-cmd",
      ...
    ],
    "post-update-cmd": [
      "@your-cmd",
      ...
    ]
  }
}