14
votes

I am building a Cordova application that I am allowing different clients to brand. I was wondering if there was a way to have a default config.xml, and then have second file that overrides the default with the branded values. There are quite a few values I need to override, however some of the more obvious are :

  • The id and version attributes of widget
  • name
  • description
  • author
  • icon (how would I override multiple of the same tag?)
  • splash

If there is not a Cordova way of doing this, is there a linux tool that I could use for this purpose that would output my single config.xml file?

2
Cannot help. Looking for a solution myself. In the end it probably boils down to have small script that copies/merges client config files to/with config.xml and then run cordova with that config file. The client config file contains the paths to the client specific images, name and description. A simple node.js script could merge the two XML files via XSLT.philk
Did you find a solution? or did you just end up writing the scriptLuKenneth
I wrote the scriptphilk

2 Answers

1
votes

The best way to do this is to actually create a separate project for each instance of your application.

Here is how I would solve this:

1.Create a template for the config.xml file.

2.Create a www folder (containing the files of your application) in the same directory where you will create the project_folders for each instance of the application.

3.Create new instances of the application cordova create...

4.In each instance copy the template of config.xml over the existing one and modify for the specific instance.

5.Either copy the www folder from the directory above the project_root into it, or remove the www folder from the project_root and create a symlink to the www folder in the directory above the project_root.

Now you have separate instances of your application, all sharing the same www contents but with custom config.xml files.

Example Directory Structure:

App_Name
  \config.xml
  \www
  \{project_instance_1}
    \{config replaced}
    \www -> ../www
  \{project_instance_2}
    \{config replaced}
    \www -> ../www
1
votes

You can have a xlst file to update the specific property on the config.xml. For example I have two bundles id (one for testing and the original). So I need a different <widget id="<ID>"> for each.

My folder structure is:

App_Name
  \config.xml
  \configs
    \original
      \parser.xslt
    \test
      \parser.xslt

And each parser have its specific id, like:

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:widget="http://www.w3.org/ns/widgets"
  xmlns:cdv="http://cordova.apache.org/ns/1.0"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

  <xsl:template match="widget:widget/@id">
    <xsl:attribute name="id">
      <xsl:value-of select="'TEST_BUNDLE'"/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

Then I can do a simple unix command xsltproc to parse/change the file

xsltproc configs/test/parser.xslt ./config.xml > output_config.xml

Notice that the output file needs to be different from the original, after that you can mv the output to replace the config.

Hope it helps,

Cheers!