13

Inside my composer.json, there's a postinstall hook setup like the following:

"scripts" : {
    "dist" :        "node dist; node_modules/.bin/doccoh src/package.js",
    "postinstall" : "node_modules/.bin/grunt setup || true; node_modules/.bin/bower install",
    "start" :       "node server.js"
}

Whenever I run it (on Win from Git/Gnu Bash CLI), I end with

command not found. either the command was written wrong or couldn't be found

Rough translation from German CLI error.

I tried splitting it into multiple ;/semicolon separated parts and first cd into that directory, but it simply ends up with the same error message. Replacing the whole postinstall command set with a simple ls does work. So I guess the problem might be the semicolon separation or a wrong usage of commands. But overall I got no idea what's wrong.

Note: I got grunt-cli version 0.1.9 and grunt version 0.4.1 installed globally.

kaiser
  • 21,817
  • 17
  • 90
  • 110
  • 2
    This may be a bit late, but: You can install `grunt`, `grunt-cli` and `bower` locally (!) and then drop the path (`node_modules/.bin`) from your `package.json`. NPM will find `grunt` and `bower` if they are installed inside `node_modules`: https://npmjs.org/doc/misc/npm-scripts.html (section "ENVIRONMENT") – svckr Nov 06 '13 at 16:07
  • 1
    @svckr +1 dropping the `node_modules/.bin` part did the trick for me. – James Mar 04 '14 at 13:39
  • @svckr Do you want to add that as an answer? – kaiser Mar 04 '14 at 18:18

2 Answers2

33

I'm a bit late to answer, but if you're on Windows, multiple commands on a single line are executed with the use of &&

postinstall: "some command && some other -c"
Tucker Connelly
  • 865
  • 1
  • 8
  • 17
  • 5
    do you know of a way to do this with cross-platform support? – Plato Sep 10 '14 at 18:18
  • @Plato for future reference, the `&&` operator works both on windows and linux. still, the commands probably will not be compatible (a very few commands can be used with the same syntax on linux and windows). the safest way to run multiple instructions would be to create a JS script and run it with the node runtime, like this: `"postinstall": "node ./postinstallscript.js"` – aetonsi Jan 10 '20 at 12:50
  • Not working if you have multi command by adding &&, i do not know why! – Jamviet.com Aug 06 '22 at 17:07
2

I ran into this looking for something and thought this may help other people. I have found it easier to move to postinstall.js files as things get a little complicated. This makes it easier to deal with moving forward.

Doug
  • 47
  • 5