33import path = require( "path" ) ;
44import shelljs = require( "shelljs" ) ;
55import semver = require( "semver" ) ;
6+ import Future = require( "fibers/future" ) ;
67import constants = require( "./../constants" ) ;
8+ let xmlmerge = require ( "xmlmerge-js" ) ;
79
810export class PluginsService implements IPluginsService {
911 private static INSTALL_COMMAND_NAME = "install" ;
@@ -38,7 +40,7 @@ export class PluginsService implements IPluginsService {
3840 return ( ( ) => {
3941 this . executeNpmCommand ( PluginsService . UNINSTALL_COMMAND_NAME , pluginName ) . wait ( ) ;
4042 let showMessage = true ;
41- let action = ( modulesDestinationPath : string , platform : string ) => {
43+ let action = ( modulesDestinationPath : string , platform : string , platformData : IPlatformData ) => {
4244 shelljs . rm ( "-rf" , path . join ( modulesDestinationPath , pluginName ) ) ;
4345 this . $logger . out ( `Successfully removed plugin ${ pluginName } for ${ platform } platform` ) ;
4446 showMessage = false ;
@@ -53,7 +55,7 @@ export class PluginsService implements IPluginsService {
5355
5456 public prepare ( pluginData : IPluginData ) : IFuture < void > {
5557 return ( ( ) => {
56- let action = ( pluginDestinationPath : string , platform : string ) => {
58+ let action = ( pluginDestinationPath : string , platform : string , platformData : IPlatformData ) => {
5759 let skipExecution = false ;
5860 // Process .js files
5961 let installedFrameworkVersion = this . getInstalledFrameworkVersion ( platform ) . wait ( ) ;
@@ -66,13 +68,20 @@ export class PluginsService implements IPluginsService {
6668 if ( ! skipExecution ) {
6769 this . $fs . ensureDirectoryExists ( pluginDestinationPath ) . wait ( ) ;
6870 shelljs . cp ( "-R" , pluginData . fullPath , pluginDestinationPath ) ;
69-
70- // TODO: Merge xmls - check if android.manifest or info.plist files exist and merge them
71+
7172 let pluginPlatformsFolderPath = path . join ( pluginDestinationPath , pluginData . name , "platforms" ) ;
72- if ( this . $fs . exists ( pluginPlatformsFolderPath ) . wait ( ) ) {
73- shelljs . rm ( "-rf" , pluginPlatformsFolderPath ) ;
73+ let pluginConfigurationFilePath = path . join ( pluginPlatformsFolderPath , platformData . configurationFileName ) ;
74+ if ( this . $fs . exists ( pluginConfigurationFilePath ) . wait ( ) ) {
75+ let pluginConfigurationFileContent = this . $fs . readFile ( pluginConfigurationFilePath ) . wait ( ) . toString ( ) ;
76+ let configurationFileContent = this . $fs . readFile ( platformData . configurationFilePath ) . wait ( ) . toString ( ) ;
77+ let resultXml = this . mergeXml ( pluginConfigurationFileContent , configurationFileContent ) . wait ( ) ;
78+ this . $fs . writeFile ( platformData . configurationFilePath , resultXml ) . wait ( ) ;
7479 }
7580
81+ if ( this . $fs . exists ( pluginPlatformsFolderPath ) . wait ( ) ) {
82+ shelljs . rm ( "-rf" , pluginPlatformsFolderPath ) ;
83+ }
84+
7685 // TODO: Add libraries
7786
7887 // Show message
@@ -120,14 +129,14 @@ export class PluginsService implements IPluginsService {
120129 return npmCommandResult . split ( "@" ) [ 0 ] ; // returns plugin name
121130 }
122131
123- private executeForAllInstalledPlatforms ( action : ( pluginDestinationPath : string , platform : string ) => void ) : void {
132+ private executeForAllInstalledPlatforms ( action : ( pluginDestinationPath : string , platform : string , platformData : IPlatformData ) => void ) : void {
124133 let availablePlatforms = _ . keys ( this . $platformsData . availablePlatforms ) ;
125134 _ . each ( availablePlatforms , platform => {
126135 let isPlatformInstalled = this . $fs . exists ( path . join ( this . $projectData . platformsDir , platform . toLowerCase ( ) ) ) . wait ( ) ;
127136 if ( isPlatformInstalled ) {
128137 let platformData = this . $platformsData . getPlatformData ( platform . toLowerCase ( ) ) ;
129138 let pluginDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , "tns_modules" ) ;
130- action ( pluginDestinationPath , platform . toLowerCase ( ) ) ;
139+ action ( pluginDestinationPath , platform . toLowerCase ( ) , platformData ) ;
131140 }
132141 } ) ;
133142 }
@@ -168,5 +177,14 @@ export class PluginsService implements IPluginsService {
168177 return frameworkData . version ;
169178 } ) . future < string > ( ) ( ) ;
170179 }
180+
181+ private mergeXml ( xml1 : string , xml2 : string ) : IFuture < string > {
182+ let future = new Future < string > ( ) ;
183+ xmlmerge . merge ( xml1 , xml2 , ( mergedXml : string ) => { // TODO: process errors
184+ future . return ( mergedXml ) ;
185+ } ) ;
186+
187+ return future ;
188+ }
171189}
172190$injector . register ( "pluginsService" , PluginsService ) ;
0 commit comments