Timo Ernst
Timo Ernst

Reputation: 15993

How to build + run cordova app in 1 step on Mac OS X?

I use Cordova/PhoneGap to create an iOS app. During development, I do changes to HTML/CSS/JS files in www folder and thus have to rebuild regularly. I usually do this on my Mac:

  1. In terminal, I type: cordova prepare
  2. I press CMD + tab to switch to Xcode
  3. I hit CMD + 'R' to run the app on my attached iPhone

This works but it's a little annoying to repeat these steps all the time. Is there a way to speed this up, e.g. by creating a shell script that automagically does all these steps?

Upvotes: 1

Views: 1233

Answers (2)

Timo Ernst
Timo Ernst

Reputation: 15993

I found the best solution for me. First, I installed ios-deploy via npm:

$ npm install -g ios-deploy --unsafe-perm=true

Then I simply run this for iOS for example:

$ cordova run ios --device

The run command will internally automatically call prepare and thus copy the content of www and then launch the app on the device.

Upvotes: 0

jcesarmobile
jcesarmobile

Reputation: 53341

Sure, on xcode go to "Build Phases", press the + button and select "New Run Script Phase".

Move it to be over the "Copy www directory"

And use this code:

cordova prepare ios

EDIT: Is for some reason you can't move the new script over the "Copy www directory" one, I've found another way that will work.

Just open the "Copy www directory" (it's a build script too) and add the cordova prepare ios before the existing code

Upvotes: 1

Related Questions