33import * as path from "path" ;
44import * as shelljs from "shelljs" ;
55import * as semver from "semver" ;
6- import Future = require( "fibers/future" ) ;
76import * as constants from "../constants" ;
8- let xmlmerge = require ( "xmlmerge-js" ) ;
9- let DOMParser = require ( 'xmldom' ) . DOMParser ;
107
118export class PluginsService implements IPluginsService {
129 private static INSTALL_COMMAND_NAME = "install" ;
@@ -72,12 +69,6 @@ export class PluginsService implements IPluginsService {
7269
7370 platformData . platformProjectService . removePluginNativeCode ( pluginData ) . wait ( ) ;
7471
75- // Remove the plugin and call merge for another plugins that have configuration file
76- let pluginConfigurationFilePath = this . getPluginConfigurationFilePath ( pluginData , platformData ) ;
77- if ( this . $fs . exists ( pluginConfigurationFilePath ) . wait ( ) ) {
78- this . merge ( pluginData , platformData , ( data : IPluginData ) => data . name !== pluginData . name ) . wait ( ) ;
79- }
80-
8172 if ( pluginData . pluginVariables ) {
8273 this . $pluginVariablesService . removePluginVariablesFromProjectFile ( pluginData ) . wait ( ) ;
8374 }
@@ -104,24 +95,6 @@ export class PluginsService implements IPluginsService {
10495 } ) . future < void > ( ) ( ) ;
10596 }
10697
107- private initializeConfigurationFileFromCache ( platformData : IPlatformData ) : IFuture < void > {
108- return ( ( ) => {
109- this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
110- let frameworkVersion = this . $projectDataService . getValue ( platformData . frameworkPackageName ) . wait ( ) . version ;
111-
112- // We need to resolve this manager here due to some restrictions from npm api and in order to load PluginsService.NPM_CONFIG config
113- let npmInstallationManager : INpmInstallationManager = this . $injector . resolve ( "npmInstallationManager" ) ;
114- npmInstallationManager . addToCache ( platformData . frameworkPackageName , frameworkVersion ) . wait ( ) ;
115-
116- let cachedPackagePath = npmInstallationManager . getCachedPackagePath ( platformData . frameworkPackageName , frameworkVersion ) ;
117- let cachedConfigurationFilePath = this . $options . baseConfig ? path . resolve ( this . $options . baseConfig ) : path . join ( cachedPackagePath , constants . PROJECT_FRAMEWORK_FOLDER_NAME , platformData . relativeToFrameworkConfigurationFilePath ) ;
118- let cachedConfigurationFileContent = this . $fs . readText ( cachedConfigurationFilePath ) . wait ( ) ;
119- this . $fs . writeFile ( platformData . configurationFilePath , cachedConfigurationFileContent ) . wait ( ) ;
120-
121- platformData . platformProjectService . interpolateConfigurationFile ( ) . wait ( ) ;
122- } ) . future < void > ( ) ( ) ;
123- }
124-
12598 public prepare ( dependencyData : IDependencyData , platform : string ) : IFuture < void > {
12699 return ( ( ) => {
127100 platform = platform . toLowerCase ( ) ;
@@ -137,12 +110,6 @@ export class PluginsService implements IPluginsService {
137110 this . $fs . ensureDirectoryExists ( pluginDestinationPath ) . wait ( ) ;
138111 shelljs . cp ( "-Rf" , pluginData . fullPath , pluginDestinationPath ) ;
139112
140- let pluginConfigurationFilePath = this . getPluginConfigurationFilePath ( pluginData , platformData ) ;
141-
142- if ( this . $fs . exists ( pluginConfigurationFilePath ) . wait ( ) ) {
143- this . merge ( pluginData , platformData ) . wait ( ) ;
144- }
145-
146113 this . $projectFilesManager . processPlatformSpecificFiles ( pluginDestinationPath , platform ) . wait ( ) ;
147114
148115 pluginData . pluginPlatformsFolderPath = ( _platform : string ) => path . join ( pluginData . fullPath , "platforms" , _platform ) ;
@@ -290,83 +257,6 @@ export class PluginsService implements IPluginsService {
290257 } ) . future < string > ( ) ( ) ;
291258 }
292259
293- private mergeXml ( xml1 : string , xml2 : string , config : any [ ] ) : IFuture < string > {
294- let future = new Future < string > ( ) ;
295-
296- try {
297- xmlmerge . merge ( xml1 , xml2 , config , ( mergedXml : string ) => {
298- future . return ( mergedXml ) ;
299- } ) ;
300- } catch ( err ) {
301- future . throw ( err ) ;
302- }
303-
304- return future ;
305- }
306-
307- private validateXml ( xml : string , xmlFilePath ?: string ) : void {
308- let doc = new DOMParser ( {
309- locator : { } ,
310- errorHandler : ( level : any , msg : string ) => {
311- let errorMessage = xmlFilePath ? `Invalid xml file ${ xmlFilePath } .` : `Invalid xml ${ xml } .` ;
312- this . $errors . fail ( errorMessage + ` Additional technical information: ${ msg } .` ) ;
313- }
314- } ) ;
315- doc . parseFromString ( xml , 'text/xml' ) ;
316- }
317-
318- private mergeCore ( pluginData : IPluginData , platformData : IPlatformData ) : IFuture < void > {
319- return ( ( ) => {
320- let pluginConfigurationFilePath = this . getPluginConfigurationFilePath ( pluginData , platformData ) ;
321- let configurationFilePath = platformData . configurationFilePath ;
322-
323- // Validate plugin configuration file
324- let pluginConfigurationFileContent = this . $fs . readText ( pluginConfigurationFilePath ) . wait ( ) ;
325- pluginConfigurationFileContent = this . $pluginVariablesService . interpolatePluginVariables ( pluginData , pluginConfigurationFileContent ) . wait ( ) ;
326- this . validateXml ( pluginConfigurationFileContent , pluginConfigurationFilePath ) ;
327-
328- // Validate configuration file
329- let configurationFileContent = this . $fs . readText ( configurationFilePath ) . wait ( ) ;
330- this . validateXml ( configurationFileContent , configurationFilePath ) ;
331-
332- // Merge xml
333- let resultXml = this . mergeXml ( configurationFileContent , pluginConfigurationFileContent , platformData . mergeXmlConfig || [ ] ) . wait ( ) ;
334- this . validateXml ( resultXml ) ;
335- this . $fs . writeFile ( configurationFilePath , resultXml ) . wait ( ) ;
336- } ) . future < void > ( ) ( ) ;
337- }
338-
339- private merge ( pluginData : IPluginData , platformData : IPlatformData , mergeCondition ?: ( _pluginData : IPluginData ) => boolean ) : IFuture < void > {
340- return ( ( ) => {
341- let tnsModulesDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , constants . TNS_MODULES_FOLDER_NAME ) ;
342- let nodeModules = this . $broccoliBuilder . getChangedNodeModules ( tnsModulesDestinationPath , platformData . normalizedPlatformName . toLowerCase ( ) ) . wait ( ) ;
343-
344- _ ( nodeModules )
345- . keys ( )
346- . filter ( nodeModule => this . $fs . exists ( path . join ( nodeModule , "package.json" ) ) . wait ( ) )
347- . map ( nodeModule => this . getNodeModuleData ( path . join ( nodeModule , "package.json" ) ) . wait ( ) )
348- . map ( nodeModuleData => this . convertToPluginData ( nodeModuleData ) )
349- . filter ( data => data . isPlugin && this . $fs . exists ( this . getPluginConfigurationFilePath ( data , platformData ) ) . wait ( ) )
350- . forEach ( ( data , index ) => {
351- if ( index === 0 ) {
352- this . initializeConfigurationFileFromCache ( platformData ) . wait ( ) ;
353- }
354-
355- if ( ! mergeCondition || ( mergeCondition && mergeCondition ( data ) ) ) {
356- this . mergeCore ( data , platformData ) . wait ( ) ;
357- }
358- } )
359- . value ( ) ;
360-
361- } ) . future < void > ( ) ( ) ;
362- }
363-
364- private getPluginConfigurationFilePath ( pluginData : IPluginData , platformData : IPlatformData ) : string {
365- let pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( platformData . normalizedPlatformName . toLowerCase ( ) ) ;
366- let pluginConfigurationFilePath = path . join ( pluginPlatformsFolderPath , platformData . configurationFileName ) ;
367- return pluginConfigurationFilePath ;
368- }
369-
370260 private isPluginDataValidForPlatform ( pluginData : IPluginData , platform : string ) : IFuture < boolean > {
371261 return ( ( ) => {
372262 let isValid = true ;
0 commit comments