Script to modify config.xml


Hey there,

I’m currently working on a series of apps which all share a base-app on which the other apps are sitting on top. There will be a subfolder in the base-apps ‘www’ directory named ‘app’ that will be exchanged with the content for each app. You could say the base-app is a kind of engine.
I got a git repository for the base-app and seperate repositories for each app which are only containing the ‘app’ directory. Every app has it’s own configuration file ‘www/app/appSettings.js’ that contains things like the app-id, name, description etc.
The base-apps ‘config.xml’ contains normal things like plugins etc. So, this file is the same for all apps. In the ‘config.xml’ I replaced the widget id with a placeholder string ‘{app-id}’. I planned to replace the placeholder with the ‘app-id’ from the ‘app/appSettings.js’ file using cordova hooks:

  1. backup config.xml file to ./.tmp/config.xml
  2. replace placeholder in ./config.xml
  3. after ionic has finished, restore the ./config.xml file with the one from ./.tmp/config.xml

The problem that I do have is, that at the time when the hook is executed, cordova/ionic already has read the config.xml file, so my the changes won’t be recognized and the compiler throws an error saying ‘{app-id}’ is not a valid id. Is there a possibility to execute a script earlier? Something like a wrapper around the ionic CLI maybe?



I do this using a gulp task I created and run it manually in the command line before I do a build.

For example, I run my command:

gulp replace --app app1

Which then reads the config.json file I made and replaces all the placeholder variables in my config_before.xml and outputs a new file, config.xml, with all the correct configuration.