Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

bash - Composer unable to run post install script

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

> 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

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:

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

So my composer.json should be able to work as such:

Wanted composer.json

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

post-install.sh

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

#!/bin/bash

mkdir -p _libraries
cp -r vendor/twbs/bootstrap/dist _libraries/bootstrap/
...
...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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",
      ...
    ]
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...