@@ -30,7 +30,7 @@ export class PluginsService implements IPluginsService {
30
30
return ( ( ) => {
31
31
this . ensure ( ) . wait ( ) ;
32
32
let dependencyData = this . $npm . cache ( plugin , undefined , PluginsService . NPM_CONFIG ) . wait ( ) ;
33
- if ( dependencyData . nativescript ) {
33
+ if ( dependencyData . nativescript ) {
34
34
let pluginData = this . convertToPluginData ( dependencyData ) ;
35
35
36
36
// Validate
@@ -44,7 +44,7 @@ export class PluginsService implements IPluginsService {
44
44
try {
45
45
this . $pluginVariablesService . savePluginVariablesInProjectFile ( pluginData ) . wait ( ) ;
46
46
this . executeNpmCommand ( PluginsService . INSTALL_COMMAND_NAME , plugin ) . wait ( ) ;
47
- } catch ( err ) {
47
+ } catch ( err ) {
48
48
// Revert package.json
49
49
this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
50
50
this . $projectDataService . removeProperty ( this . $pluginVariablesService . getPluginVariablePropertyName ( pluginData . name ) ) . wait ( ) ;
@@ -87,7 +87,7 @@ export class PluginsService implements IPluginsService {
87
87
} ;
88
88
this . executeForAllInstalledPlatforms ( action ) . wait ( ) ;
89
89
90
- if ( showMessage ) {
90
+ if ( showMessage ) {
91
91
this . $logger . out ( `Succsessfully removed plugin ${ pluginName } ` ) ;
92
92
}
93
93
} ) . future < void > ( ) ( ) ;
@@ -100,11 +100,11 @@ export class PluginsService implements IPluginsService {
100
100
let pluginDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , "tns_modules" ) ;
101
101
let pluginData = this . convertToPluginData ( dependencyData ) ;
102
102
103
- if ( ! this . isPluginDataValidForPlatform ( pluginData , platform ) . wait ( ) ) {
103
+ if ( ! this . isPluginDataValidForPlatform ( pluginData , platform ) . wait ( ) ) {
104
104
return ;
105
105
}
106
106
107
- if ( this . $fs . exists ( path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ) . wait ( ) ) {
107
+ if ( this . $fs . exists ( path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ) . wait ( ) ) {
108
108
this . $fs . ensureDirectoryExists ( pluginDestinationPath ) . wait ( ) ;
109
109
shelljs . cp ( "-Rf" , pluginData . fullPath , pluginDestinationPath ) ;
110
110
@@ -126,7 +126,7 @@ export class PluginsService implements IPluginsService {
126
126
let installedDependencies = this . $fs . exists ( this . nodeModulesPath ) . wait ( ) ? this . $fs . readDirectory ( this . nodeModulesPath ) . wait ( ) : [ ] ;
127
127
let packageJsonContent = this . $fs . readJson ( this . getPackageJsonFilePath ( ) ) . wait ( ) ;
128
128
let allDependencies = _ . keys ( packageJsonContent . dependencies ) . concat ( _ . keys ( packageJsonContent . devDependencies ) ) ;
129
- if ( this . $options . force || _ . difference ( allDependencies , installedDependencies ) . length ) {
129
+ if ( this . $options . force || _ . difference ( allDependencies , installedDependencies ) . length ) {
130
130
this . $npm . install ( this . $projectData . projectDir , this . $projectData . projectDir , { "ignore-scripts" : this . $options . ignoreScripts } ) . wait ( ) ;
131
131
}
132
132
} ) . future < void > ( ) ( ) ;
@@ -147,6 +147,33 @@ export class PluginsService implements IPluginsService {
147
147
return this . executeForAllInstalledPlatforms ( action ) ;
148
148
}
149
149
150
+ public getDependenciesFromPackageJson ( ) : IFuture < IPackageJsonDepedenciesResult > {
151
+ return ( ( ) => {
152
+ let packageJson = this . $fs . readJson ( this . getPackageJsonFilePath ( ) ) . wait ( ) ;
153
+ let dependencies : IBasePluginData [ ] = this . mapDependenciesToBaseIPluginData ( packageJson . dependencies ) ;
154
+
155
+ let devDependencies : IBasePluginData [ ] = this . mapDependenciesToBaseIPluginData ( packageJson . devDependencies ) ;
156
+
157
+ return {
158
+ dependencies,
159
+ devDependencies
160
+ } ;
161
+ } ) . future < IPackageJsonDepedenciesResult > ( ) ( ) ;
162
+ }
163
+
164
+ private mapDependenciesToBaseIPluginData ( dependencies : any ) : IBasePluginData [ ] {
165
+ let result : IBasePluginData [ ] = [ ] ;
166
+
167
+ _ . forEach ( _ . keys ( dependencies ) , ( key : string ) => {
168
+ result . push ( {
169
+ name : key ,
170
+ version : dependencies [ key ]
171
+ } ) ;
172
+ } ) ;
173
+
174
+ return result ;
175
+ }
176
+
150
177
private get nodeModulesPath ( ) : string {
151
178
return path . join ( this . $projectData . projectDir , "node_modules" ) ;
152
179
}
@@ -166,7 +193,7 @@ export class PluginsService implements IPluginsService {
166
193
167
194
private getNodeModuleData ( module : string ) : IFuture < INodeModuleData > { // module can be modulePath or moduleName
168
195
return ( ( ) => {
169
- if ( ! this . $fs . exists ( module ) . wait ( ) || path . basename ( module ) !== "package.json" ) {
196
+ if ( ! this . $fs . exists ( module ) . wait ( ) || path . basename ( module ) !== "package.json" ) {
170
197
module = this . getPackageJsonFilePathForModule ( module ) ;
171
198
}
172
199
@@ -190,7 +217,7 @@ export class PluginsService implements IPluginsService {
190
217
pluginData . pluginPlatformsFolderPath = ( platform : string ) => path . join ( pluginData . fullPath , "platforms" , platform ) ;
191
218
let data = cacheData . nativescript || cacheData . moduleInfo ;
192
219
193
- if ( pluginData . isPlugin ) {
220
+ if ( pluginData . isPlugin ) {
194
221
pluginData . platformsData = data . platforms ;
195
222
pluginData . pluginVariables = data . variables ;
196
223
}
@@ -218,11 +245,11 @@ export class PluginsService implements IPluginsService {
218
245
return ( ( ) => {
219
246
let result = "" ;
220
247
221
- if ( npmCommandName === PluginsService . INSTALL_COMMAND_NAME ) {
248
+ if ( npmCommandName === PluginsService . INSTALL_COMMAND_NAME ) {
222
249
result = this . $npm . install ( npmCommandArguments , this . $projectData . projectDir , PluginsService . NPM_CONFIG ) . wait ( ) ;
223
- } else if ( npmCommandName === PluginsService . UNINSTALL_COMMAND_NAME ) {
250
+ } else if ( npmCommandName === PluginsService . UNINSTALL_COMMAND_NAME ) {
224
251
result = this . $npm . uninstall ( npmCommandArguments , PluginsService . NPM_CONFIG , this . $projectData . projectDir ) . wait ( ) ;
225
- if ( ! result || ! result . length ) {
252
+ if ( ! result || ! result . length ) {
226
253
// indicates something's wrong with the data in package.json, for example version of the plugin that we are trying to remove is invalid.
227
254
return npmCommandArguments . toLowerCase ( ) ;
228
255
}
@@ -241,7 +268,7 @@ export class PluginsService implements IPluginsService {
241
268
let availablePlatforms = _ . keys ( this . $platformsData . availablePlatforms ) ;
242
269
_ . each ( availablePlatforms , platform => {
243
270
let isPlatformInstalled = this . $fs . exists ( path . join ( this . $projectData . platformsDir , platform . toLowerCase ( ) ) ) . wait ( ) ;
244
- if ( isPlatformInstalled ) {
271
+ if ( isPlatformInstalled ) {
245
272
let platformData = this . $platformsData . getPlatformData ( platform . toLowerCase ( ) ) ;
246
273
let pluginDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , "tns_modules" ) ;
247
274
action ( pluginDestinationPath , platform . toLowerCase ( ) , platformData ) . wait ( ) ;
@@ -265,12 +292,12 @@ export class PluginsService implements IPluginsService {
265
292
266
293
let installedFrameworkVersion = this . getInstalledFrameworkVersion ( platform ) . wait ( ) ;
267
294
let pluginPlatformsData = pluginData . platformsData ;
268
- if ( pluginPlatformsData ) {
295
+ if ( pluginPlatformsData ) {
269
296
let pluginVersion = ( < any > pluginPlatformsData ) [ platform ] ;
270
- if ( ! pluginVersion ) {
297
+ if ( ! pluginVersion ) {
271
298
this . $logger . warn ( `${ pluginData . name } is not supported for ${ platform } .` ) ;
272
299
isValid = false ;
273
- } else if ( semver . gt ( pluginVersion , installedFrameworkVersion ) ) {
300
+ } else if ( semver . gt ( pluginVersion , installedFrameworkVersion ) ) {
274
301
this . $logger . warn ( `${ pluginData . name } ${ pluginVersion } for ${ platform } is not compatible with the currently installed framework version ${ installedFrameworkVersion } .` ) ;
275
302
isValid = false ;
276
303
}
0 commit comments