@@ -30,7 +30,7 @@ export class PluginsService implements IPluginsService {
3030 return ( ( ) => {
3131 this . ensure ( ) . wait ( ) ;
3232 let dependencyData = this . $npm . cache ( plugin , undefined , PluginsService . NPM_CONFIG ) . wait ( ) ;
33- if ( dependencyData . nativescript ) {
33+ if ( dependencyData . nativescript ) {
3434 let pluginData = this . convertToPluginData ( dependencyData ) ;
3535
3636 // Validate
@@ -44,7 +44,7 @@ export class PluginsService implements IPluginsService {
4444 try {
4545 this . $pluginVariablesService . savePluginVariablesInProjectFile ( pluginData ) . wait ( ) ;
4646 this . executeNpmCommand ( PluginsService . INSTALL_COMMAND_NAME , plugin ) . wait ( ) ;
47- } catch ( err ) {
47+ } catch ( err ) {
4848 // Revert package.json
4949 this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
5050 this . $projectDataService . removeProperty ( this . $pluginVariablesService . getPluginVariablePropertyName ( pluginData . name ) ) . wait ( ) ;
@@ -87,7 +87,7 @@ export class PluginsService implements IPluginsService {
8787 } ;
8888 this . executeForAllInstalledPlatforms ( action ) . wait ( ) ;
8989
90- if ( showMessage ) {
90+ if ( showMessage ) {
9191 this . $logger . out ( `Succsessfully removed plugin ${ pluginName } ` ) ;
9292 }
9393 } ) . future < void > ( ) ( ) ;
@@ -100,11 +100,11 @@ export class PluginsService implements IPluginsService {
100100 let pluginDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , "tns_modules" ) ;
101101 let pluginData = this . convertToPluginData ( dependencyData ) ;
102102
103- if ( ! this . isPluginDataValidForPlatform ( pluginData , platform ) . wait ( ) ) {
103+ if ( ! this . isPluginDataValidForPlatform ( pluginData , platform ) . wait ( ) ) {
104104 return ;
105105 }
106106
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 ( ) ) {
108108 this . $fs . ensureDirectoryExists ( pluginDestinationPath ) . wait ( ) ;
109109 shelljs . cp ( "-Rf" , pluginData . fullPath , pluginDestinationPath ) ;
110110
@@ -126,7 +126,7 @@ export class PluginsService implements IPluginsService {
126126 let installedDependencies = this . $fs . exists ( this . nodeModulesPath ) . wait ( ) ? this . $fs . readDirectory ( this . nodeModulesPath ) . wait ( ) : [ ] ;
127127 let packageJsonContent = this . $fs . readJson ( this . getPackageJsonFilePath ( ) ) . wait ( ) ;
128128 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 ) {
130130 this . $npm . install ( this . $projectData . projectDir , this . $projectData . projectDir , { "ignore-scripts" : this . $options . ignoreScripts } ) . wait ( ) ;
131131 }
132132 } ) . future < void > ( ) ( ) ;
@@ -147,6 +147,33 @@ export class PluginsService implements IPluginsService {
147147 return this . executeForAllInstalledPlatforms ( action ) ;
148148 }
149149
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+
150177 private get nodeModulesPath ( ) : string {
151178 return path . join ( this . $projectData . projectDir , "node_modules" ) ;
152179 }
@@ -166,7 +193,7 @@ export class PluginsService implements IPluginsService {
166193
167194 private getNodeModuleData ( module : string ) : IFuture < INodeModuleData > { // module can be modulePath or moduleName
168195 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" ) {
170197 module = this . getPackageJsonFilePathForModule ( module ) ;
171198 }
172199
@@ -190,7 +217,7 @@ export class PluginsService implements IPluginsService {
190217 pluginData . pluginPlatformsFolderPath = ( platform : string ) => path . join ( pluginData . fullPath , "platforms" , platform ) ;
191218 let data = cacheData . nativescript || cacheData . moduleInfo ;
192219
193- if ( pluginData . isPlugin ) {
220+ if ( pluginData . isPlugin ) {
194221 pluginData . platformsData = data . platforms ;
195222 pluginData . pluginVariables = data . variables ;
196223 }
@@ -218,11 +245,11 @@ export class PluginsService implements IPluginsService {
218245 return ( ( ) => {
219246 let result = "" ;
220247
221- if ( npmCommandName === PluginsService . INSTALL_COMMAND_NAME ) {
248+ if ( npmCommandName === PluginsService . INSTALL_COMMAND_NAME ) {
222249 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 ) {
224251 result = this . $npm . uninstall ( npmCommandArguments , PluginsService . NPM_CONFIG , this . $projectData . projectDir ) . wait ( ) ;
225- if ( ! result || ! result . length ) {
252+ if ( ! result || ! result . length ) {
226253 // indicates something's wrong with the data in package.json, for example version of the plugin that we are trying to remove is invalid.
227254 return npmCommandArguments . toLowerCase ( ) ;
228255 }
@@ -241,7 +268,7 @@ export class PluginsService implements IPluginsService {
241268 let availablePlatforms = _ . keys ( this . $platformsData . availablePlatforms ) ;
242269 _ . each ( availablePlatforms , platform => {
243270 let isPlatformInstalled = this . $fs . exists ( path . join ( this . $projectData . platformsDir , platform . toLowerCase ( ) ) ) . wait ( ) ;
244- if ( isPlatformInstalled ) {
271+ if ( isPlatformInstalled ) {
245272 let platformData = this . $platformsData . getPlatformData ( platform . toLowerCase ( ) ) ;
246273 let pluginDestinationPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME , "tns_modules" ) ;
247274 action ( pluginDestinationPath , platform . toLowerCase ( ) , platformData ) . wait ( ) ;
@@ -265,12 +292,12 @@ export class PluginsService implements IPluginsService {
265292
266293 let installedFrameworkVersion = this . getInstalledFrameworkVersion ( platform ) . wait ( ) ;
267294 let pluginPlatformsData = pluginData . platformsData ;
268- if ( pluginPlatformsData ) {
295+ if ( pluginPlatformsData ) {
269296 let pluginVersion = ( < any > pluginPlatformsData ) [ platform ] ;
270- if ( ! pluginVersion ) {
297+ if ( ! pluginVersion ) {
271298 this . $logger . warn ( `${ pluginData . name } is not supported for ${ platform } .` ) ;
272299 isValid = false ;
273- } else if ( semver . gt ( pluginVersion , installedFrameworkVersion ) ) {
300+ } else if ( semver . gt ( pluginVersion , installedFrameworkVersion ) ) {
274301 this . $logger . warn ( `${ pluginData . name } ${ pluginVersion } for ${ platform } is not compatible with the currently installed framework version ${ installedFrameworkVersion } .` ) ;
275302 isValid = false ;
276303 }
0 commit comments