[ALOY-1118] Allow theming of tiapp.xml e.g. through Alloy themes
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Resolved |
Resolution | Won't Fix |
Resolution Date | 2015-02-04T14:39:51.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.7.0 |
Components | Styling |
Labels | themes, tiapp.xml |
Reporter | Fokke Zandbergen |
Assignee | Tim Poulsen |
Created | 2014-07-18T06:57:23.000+0000 |
Updated | 2015-02-04T14:39:52.000+0000 |
Description
Now Alloy supports theming of
app/config.json
and i18n
and platforms
on their way, the last thing to tackle for easily building branded apps of a white label codebase is "theming" tiapp.xml
.
This might me the most challenging one, since I guess the CLI already reads some information from tiapp.xml
before the first hook that Alloy uses is triggered. Also, it will require some serious smarts to know when to overwrite and when to append XML tags and attributes.
Thanks for your report [~fokke]! [~tlukasavage]: can you please set [~fokke] as the reporter? The system still switches it to mover.
This should be easily possible through the use of an Alloy JMK file. First-attempt resolution of this ticket should be the creation of a demonstration project using a JMK file to "theme" the tiapp.xml. Values to be changed per theme could be appid, guid, android map keys, and custom properties. (Incidentally, a grunt or gulp script could also easily accomplish the sorts of tiapp.xml customizations requested. As would https://github.com/jasonkneen/tich)
After playing with this for a bit, I've determined that neither the Alloy JMK or CLI hook is the solution to this. Alloy JMK files hook into the build process too late. By the time they run, the CLI has read and cached the tiapp.xml. Swapping out the file at that point has no effect on the resulting build process. The CLI hooks don't have access to the necessary Alloy configuration information. (Such as the active theme.) While I could probably create a hook that reads in the config.json file, parses it, determines the theme, environment, etc. I think the resulting script would be a bit fragile. A reasonably simple solution is to use a grunt script.
Step 1: Install grunt-cli
npm install -g grunt-cli
Step 2: In your project's directory, create a package.json file with contents like this:
Step 3: In your project's directory, run:
npm install
Step 4: Create a file named Gruntfile.js in your project's directory. Copy the code below into it.
Step 5: Use the grunt script:
First, put a copy of tiapp.xml into the app/themes/yourtheme folder and customize that copy as necessary. Then: {noformat} > grunt theme:active_theme_name // to swap in the theme's tiapp.xml > ti build -p ios ... // as needed to build your app > grunt reset // to restore the original tiapp.xml {noformat} An exercise left to the reader is to implement the grunt-titanium plug-in to automate the building of the app.[~skypanther] As I wrote in the original ticket description, I was expecting this to be a chicken-egg problem already and I agree it should be handled via Grunt or alike. Instead of your solution to replace the
tiapp.xml
I would rather read the theme'sconfig.json
and then use Tony'stiapp.xml
module to make specific changes, but that's just details. It might be a good subject for a blog post.Resolving as Won't Fix because we'll resolve this through a blog post describing how to use a build automation tool to accomplish the goal.