Comments (3)
@Yura13 I was using xml2js https://www.npmjs.com/package/xml2js which doesn't preserve XML elements order. I switched to https://www.npmjs.com/package/fast-xml-parser.
Here's the code (quick and dirty js) :
// Parse config.xml, edit app & package name and save the changes
import { XMLBuilder, XMLParser } from "fast-xml-parser";
import { readFile, writeFile } from 'fs';
const configFile = "config.xml";
const commonOptions = {
preserveOrder: true,
ignoreAttributes: false,
allowBooleanAttributes: true,
commentPropName: "#comment",
unpairedTags: [
'content',
'access',
'allow-navigation',
'preference',
'allow-intent',
'param',
'hook',
'application',
'custom-preference',
'resource-file',
'icon',
'splash',
'true',
],
}
const parser = new XMLParser({
...commonOptions,
ignoreDeclaration: false,
});
const builder = new XMLBuilder({
...commonOptions,
suppressUnpairedNode: false,
format: true,
});
export function updateConfigFile(overrides) {
readFile(configFile, "utf-8", (err, data) => {
if (err) {
throw err;
}
const result = parser.parse(data);
/** Overrides */
if (overrides?.['android-packageName']) {
result[1][':@']['@_android-packageName'] = overrides['android-packageName'];
}
if (overrides?.['ios-CFBundleIdentifier']) {
result[1][':@']['@_ios-CFBundleIdentifier'] = overrides['ios-CFBundleIdentifier'];
}
if (overrides?.name) {
result[1].widget = result[1].widget.map((obj) => ((obj?.name != null) ? {...obj, name: [ { '#text': overrides.name } ] } : obj));
}
const xml = builder.build(result);
// write updated XML string to a file
writeFile(configFile, xml, { encoding: "utf-8" }, (err) => {
if (err) {
throw err;
}
console.log(`Updated XML is written to a new file.`);
});
});
}
You can adapt the overrides part to your usecase, the syntax is weirder than xml2js
but the order is preserved with the provided options :)
Saved this as a .mjs file so I could use import
syntax safely but you can use require
with .js files.
call it like this in your cordova hooks
updateConfigFile({
'android-packageName': 'com.your.package',
'ios-CFBundleIdentifier': 'com.your.package',
name: 'Your app name',
});
Sorry I let this up without providing a solution https://xkcd.com/979/ 😅
from cordova-ios.
Oops, I forgot that my app edits the config.xml with a cordova hook and that's the source of my problem. Sorry for the spam
from cordova-ios.
@shajz
I have the same problem. How do you resolve it?
from cordova-ios.
Related Issues (20)
- Please remove org_apache_cordova_UIView_Extension because it isn't necessary since iOS 8.
- SplashScreen not loading on [email protected] HOT 8
- Cannot run new iOS app since latest upgrade HOT 18
- Trouble to open Instagram App HOT 2
- Any alternative to CDVCommandDelegateImpl which is removed from public classes? HOT 6
- [Next Major] Delete bin/cordova_plist_to_config_xml script
- Several template project bin scripts are broken
- Add preferences to config.xml to control which are the "Supported Destinations"
- The CDVURLProtocol no longer exists, so how should we modify the interception? HOT 3
- The startURLSchemeTask method in CDVURLSchemeHandler was not executed HOT 2
- Copy deployment-target from root config.xml to platform-specific config.xml before usage in Podfile HOT 5
- WKWebViewConfiguration is always ignored
- Missing API declaration on iOS app submission to App Store HOT 5
- CDVPlugin's viewController should just be a CDVViewController
- CDVWebViewUIDelegate should take a CDVViewController
- Cordova ios 7.1.0 - Build failed with "Command failed with exit code 65" HOT 4
- Several version checks fail after cordova-ios platform add [email protected] HOT 2
- Target Identity info missing Display Name, Version, Build HOT 1
- plugin_not_installed errors after upgrading from 6.3.0 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-ios.