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

Categories

0 votes
1.5k 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...