stian
stian

Reputation: 1987

how to run scripts in hook folder cordova?

I am trying to run scripts within the hook folder as described here; http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/. I have created a cordova project and ran the cordova platform add (ios) command. Then I added two different scripts (one test.sh and one test.js). Here is the sh/bash one;

#!/usr/bin/env bash
echo "yo"
mkdir t
cordova plugin add org.apache.cordova.device

I then chmod a+x test.sh within the hooks folder, before going out to the root of the cordova project and wrote cordova prepare. Now I would expect to have a plugin added in my plugins folder, but it does not seem like the script has been executed. Is there something else I have to do to get it to work? The script works fine when explicitly using sh test.sh in the hooks folder. I found a related question, but this deals only with the .js-file not the bash/sh script (cordova plugin installation issue when using node script in hooks folder). I found a second related question (Cordova hooks, Get projects name)

Upvotes: 1

Views: 5259

Answers (1)

Ivan Gabriele
Ivan Gabriele

Reputation: 6900

Some examples are given in the Apache official example.

You have to put them in one of the directories listed as Supported hook types, i.e. after_platform_add depending on your needs.

You may also write them directly within the config.xml, i.e. <hook type="before_build" src="myScripts/myHook.js" />

I would recommend to write them in JavaScript but you can obviously write them in Shell (.sh) or batch (.bat).

Upvotes: 2

Related Questions