hooks/before_prepare/icon.js
function updateConfig(target) {
	try {
		var contents = fs.readFileSync(path.join(__dirname, '../../config.xml'), 'utf-8');
		if (contents) {
			// Windows is the BOM. Skip the Byte Order Mark.
			contents = contents.substring(contents.indexOf('<'));
		}

		var doc = new et.ElementTree(et.XML(contents));
		var root = doc.getroot();

		if (root.tag !== 'widget') {
			throw new Error('config.xml has incorrect root node name (expected "widget", was "' + root.tag + '")');
		}

		var platformElement = doc.find('./platform/[@name="' + target + '"]');

		if (platformElement) {
			var icons = platformElement.findall('./icon');

			for (var i=0; i<icons.length; i++) {
				platformElement.remove(icons[i]);
			}
		} else {
			platformElement = new et.Element('platform');
			platformElement.attrib.name = target;

			doc.getroot().append(platformElement);
		}

		// Add all the icons
		for(var i=0; i<platforms[target].icons.length; i++) {
			var iconElement = new et.Element('icon');
			iconElement.attrib = {
				...platforms[target].icons[i].attributes,
				src: 'res/' + target + '/' + platforms[target].icons[i].file
			};

			platformElement.append(iconElement);
		}

		fs.writeFileSync(path.join(__dirname, '../../config.xml'), doc.write({indent: 4}), 'utf-8');
	} catch (e) {
		console.error('Could not load config.xml');
		throw e;
	}
}
function updateConfig(target) {
	try {
		var contents = fs.readFileSync(path.join(__dirname, '../../config.xml'), 'utf-8');
		if (contents) {
			// Windows is the BOM. Skip the Byte Order Mark.
			contents = contents.substring(contents.indexOf('<'));
		}

		var doc = new et.ElementTree(et.XML(contents));
		var root = doc.getroot();

		if (root.tag !== 'widget') {
			throw new Error('config.xml has incorrect root node name (expected "widget", was "' + root.tag + '")');
		}

		var platformElement = doc.find('./platform/[@name="' + target + '"]');

		if (platformElement) {
			var icons = platformElement.findall('./icon');

			for (var i=0; i<icons.length; i++) {
				platformElement.remove(icons[i]);
			}
		} else {
			platformElement = new et.Element('platform');
			platformElement.attrib.name = target;

			doc.getroot().append(platformElement);
		}

		// Add all the icons
		for(var i=0; i<platforms[target].icons.length; i++) {
			var iconElement = new et.Element('icon');
			iconElement.attrib = {
				...platforms[target].icons[i].attributes,
				src: 'res/' + target + '/' + platforms[target].icons[i].file
			};

			platformElement.append(iconElement);
		}

		fs.writeFileSync(path.join(__dirname, '../../config.xml'), doc.write({indent: 4}), 'utf-8');
	} catch (e) {
		console.error('Could not load config.xml');
		throw e;
	}
}
function updateConfig ( target ) { try { var contents = fs . readFileSync ( path . join ( __dirname , '../../config.xml' ) , 'utf-8' ) ; if ( contents ) { // Windows is the BOM. Skip the Byte Order Mark. contents = contents . substring ( contents . indexOf ( '<' ) ) ; } var doc = new et . ElementTree ( et . XML ( contents ) ) ; var root = doc . getroot ( ) ; if ( root . tag !== 'widget' ) { throw new Error ( 'config.xml has incorrect root node name (expected "widget", was "' + root . tag + '")' ) ; } var platformElement = doc . find ( './platform/[@name="' + target + '"]' ) ; if ( platformElement ) { var icons = platformElement . findall ( './icon' ) ; for ( var i = 0 ; i < icons . length ; i ++ ) { platformElement . remove ( icons [ i ] ) ; } } else { platformElement = new et . Element ( 'platform' ) ; platformElement . attrib . name = target ; doc . getroot ( ) . append ( platformElement ) ; } // Add all the icons for ( var i = 0 ; i < platforms [ target ] . icons . length ; i ++ ) { var iconElement = new et . Element ( 'icon' ) ; iconElement . attrib = { ... platforms [ target ] . icons [ i ] . attributes , src : 'res/' + target + '/' + platforms [ target ] . icons [ i ] . file } ; platformElement . append ( iconElement ) ; } fs . writeFileSync ( path . join ( __dirname , '../../config.xml' ) , doc . write ( { indent : 4 } ) , 'utf-8' ) ; } catch ( e ) { console . error ( 'Could not load config.xml' ) ; throw e ; } }
This method will update the config.xml file for the target platform. It will
add the icon tags to the config file.
This method will update the config . xml file for the target platform . It will add the icon tags to the config file .