如何在hook文件夹cordova中运行脚本? [英] how to run scripts in hook folder cordova?

查看:270
本文介绍了如何在hook文件夹cordova中运行脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在这里描述的hook文件夹中运行脚本; http://devgirl.org/2013/11/ 12 / three-hooks-your-cordovaphonegap-project-needs / 。我创建了一个cordova项目,并运行cordova平台add(ios)命令。然后我添加了两个不同的脚本(一个test.sh和一个test.js)。这是sh / bash的一个;

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

chmod a + x test.sh在hooks文件夹中,然后出去到cordova项目的根目录和写cordova准备。现在我会期望有一个插件添加在我的插件文件夹,但它似乎不像脚本已被执行。有什么别的东西我要做,以使它工作?当在hooks文件夹中显式地使用sh test.sh时,脚本工作正常。我发现了一个相关的问题,但是这仅涉及了的.js文件未在bash / sh脚本(的 cordova插件安装问题)。我找到了另一个相关问题( Cordova钩子,获取项目名称

解决方案

在Apache官方示例中



根据您的需要



列出支持的钩子类型目录: after_platform_add p>您也可以直接在config.xml中写入它们,例如< hook type =before_buildsrc =myScripts / myHook.js/> p>

我建议用Javascript写它们,但你可以明显地写为bash(.sh)或batch(.bat)。


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)

解决方案

Some examples are given in an Apache official example.

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

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

I would recommand to write them in Javascript but you can obviously write them is bash (.sh) or batch (.bat).

这篇关于如何在hook文件夹cordova中运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆