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 :
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?
config. xml is a global configuration file that controls many aspects of a cordova application's behavior. This platform-agnostic XML file is arranged based on the W3C's Packaged Web Apps (Widgets) specification, and extended to specify core Cordova API features, plugins, and platform-specific settings.
When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.
Each WebLogic Server domain contains a central configuration file called the config. xml, which is stored in the DOMAIN_HOME\config directory. Both the Admin Server and the Managed Servers derive their run-time configuration information from the config.
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With