Skip to content

Instantly share code, notes, and snippets.

@jakubgg
Created May 30, 2014 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakubgg/8617fb9060fc63bae9f6 to your computer and use it in GitHub Desktop.
Save jakubgg/8617fb9060fc63bae9f6 to your computer and use it in GitHub Desktop.
Titanium automatic build version helper

Purpose

To add automatically incrementing build number into your Titanium app. So if you test it on multiple devices you always know, what exact version is installed where.

Deployment

  1. Save the build_version.sh in your Titanium project folder (same location as tiapp.xml).
  2. From terminal chmod +x build_version.sh to make it executable.
  3. Add the property line from tiapp.xml to your tiapp.xml
  4. Whenever you want to increase build numer - execute build_version.sh script (I have it in my build scripts, so it automatically updates on every build).

In your App

You can read the build number in your controllers using: Ti.App.Properties.getInt('build'); Tip: I am adding it on the home screen of my app while testing, and into settings.bundle while beta testing on different devices.

#!/usr/bin/env node
var fs = require('fs');
fs.readFile('./tiapp.xml', 'utf8', function (err, data) {
if (err) throw err;
incrementBuild(data);
});
function incrementBuild (data) {
var lastBuild = data.match(/(?!name="build">)[0-9]+(?=<\/property>)/);
var newBuild = Number(lastBuild) + 1;
var output = data.replace(/(?!>)[0-9]+(?=<\/property>)/, newBuild);
console.log('[INFO] Build: '+newBuild);
fs.writeFile('./tiapp.xml', output, function (err) {
if (err) throw err;
console.log('tiapp.xml saved!');
});
}
<!-- Add the following line to the tiapp.xml-->
<property name="build" type="string">0</property>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment