cordova-config
Parse and edit the config.xml file of a cordova project.
Install
npm install --save cordova-config
Usage
const Config = require('cordova-config');
// Load and parse the config.xml
const config = new Config('config.xml');
config.setName('My application');
config.setDescription('This is the description of my application');
config.setAuthor('Sam Verschueren', 'sam.verschueren@gmail.com', 'https://github.com/SamVerschueren');
// Write the config file
config.writeSync();
API
Config(file)
Loads and parses the file.
file
RequiredType:
string
The path to the
config.xml
file.setName(name)
Sets the <name>name</name>
tag in the xml file.
name
RequiredType:
string
The name of the application.
Sets a <tag>text</tag>
tag in the xml file.
tag
RequiredType:
string
The name of the element.
text
Type:string
The element text.
attribs
Type:object
The element attributes
setDescription(description)
Sets the <description>description</description>
tag in the xml file.
description
RequiredType:
string
The description of the application.
Sets the <author email="email" href="website">name</author>
tag in the xml file.
name
RequiredType:
string
The name of the author.
string
The email address of the email.
website
Type:string
The website of the author.
setVersion(version)
Sets the version attribute of the widget
tag in the xml file.
version
RequiredType:
string
The version in the format
x.y.z
.setAndroidVersionCode(version)
Sets the android-versionCode attribute of the widget
tag in the xml file.
version
RequiredType:
number
The Android version code.
setAndroidPackageName(packageName)
Sets the Android package name of the config file.
packageName
RequiredType:
string
The android package name.
setIOSBundleVersion(version)
Sets the ios-CFBundleVersion attribute of the widget
tag in the xml file.
version
RequiredType:
string
The version in the format
x.y.z
.setIOSBundleIdentifier(identifier)
Sets the iOS CFBundleIdentifier of the config file.
identifier
RequiredType:
string
The iOS
CFBundleIdentifier
.setPreference(name, value)
Adds a <preference name="name" value="value" />
tag to the xml file.
name
RequiredType:
string
The name of the preference tag.
value
RequiredType:
string|boolean
The value of the preference.
removeAccessOrigins()
Removes all the <access />
tags in the xml file.
removeAccessOrigin(origin)
Removes the <access />
tag with the origin equal to the parameter.
origin
RequiredType:
string
The origin of the access tag you want to remove.
setAccessOrigin(origin , options)
Adds an <access />
tag to the xml file.
origin
RequiredType:
string
The origin of the access tag.
options
Type:object
A map with extra attributes that will be added to the access tag.
setID(id)
Sets the ID of the config file.
id
RequiredType:
string
The id of the widget tag.
addHook(type, src)
Adds the hook with type and src. see Apache Cordova API Documentation for more info.
type
RequiredType:
string
Cordova hook type. ex) 'afterbuild', 'aftercompile', 'afterclean'
src
RequiredType:
string
Src path of hook script
addRawXML(xml)
Adds a raw xml element to the root of the config file.
xml
RequiredType:
string
A raw xml element. You can only pass in one element with one root.
write()
Writes the config.xml
file async.
Resolves a promise when the file is written.
writeSync()
Writes the config.xml
file synchronously.
Related
- cordova-config-cli - CLI for this module