3
3
import * as path from "path" ;
4
4
import * as shelljs from "shelljs" ;
5
5
import * as semver from "semver" ;
6
- import Future = require( "fibers/future" ) ;
7
6
import * as constants from "../constants" ;
8
- let xmlmerge = require ( "xmlmerge-js" ) ;
9
- let DOMParser = require ( 'xmldom' ) . DOMParser ;
10
7
11
8
export class PluginsService implements IPluginsService {
12
9
private static INSTALL_COMMAND_NAME = "install" ;
@@ -72,12 +69,6 @@ export class PluginsService implements IPluginsService {
72
69
73
70
platformData . platformProjectService . removePluginNativeCode ( pluginData ) . wait ( ) ;
74
71
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
-
81
72
if ( pluginData . pluginVariables ) {
82
73
this . $pluginVariablesService . removePluginVariablesFromProjectFile ( pluginData ) . wait ( ) ;
83
74
}
@@ -104,24 +95,6 @@ export class PluginsService implements IPluginsService {
104
95
} ) . future < void > ( ) ( ) ;
105
96
}
106
97
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
-
125
98
public prepare ( dependencyData : IDependencyData , platform : string ) : IFuture < void > {
126
99
return ( ( ) => {
127
100
platform = platform . toLowerCase ( ) ;
@@ -137,12 +110,6 @@ export class PluginsService implements IPluginsService {
137
110
this . $fs . ensureDirectoryExists ( pluginDestinationPath ) . wait ( ) ;
138
111
shelljs . cp ( "-Rf" , pluginData . fullPath , pluginDestinationPath ) ;
139
112
140
- let pluginConfigurationFilePath = this . getPluginConfigurationFilePath ( pluginData , platformData ) ;
141
-
142
- if ( this . $fs . exists ( pluginConfigurationFilePath ) . wait ( ) ) {
143
- this . merge ( pluginData , platformData ) . wait ( ) ;
144
- }
145
-
146
113
this . $projectFilesManager . processPlatformSpecificFiles ( pluginDestinationPath , platform ) . wait ( ) ;
147
114
148
115
pluginData . pluginPlatformsFolderPath = ( _platform : string ) => path . join ( pluginData . fullPath , "platforms" , _platform ) ;
@@ -290,83 +257,6 @@ export class PluginsService implements IPluginsService {
290
257
} ) . future < string > ( ) ( ) ;
291
258
}
292
259
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
-
370
260
private isPluginDataValidForPlatform ( pluginData : IPluginData , platform : string ) : IFuture < boolean > {
371
261
return ( ( ) => {
372
262
let isValid = true ;
0 commit comments