@@ -32,7 +32,9 @@ export class PlatformService implements IPlatformService {
32
32
private $mobileHelper : Mobile . IMobileHelper ,
33
33
private $hostInfo : IHostInfo ,
34
34
private $xmlValidator : IXmlValidator ,
35
- private $npm : INodePackageManager ) { }
35
+ private $npm : INodePackageManager ,
36
+ private $sysInfo : ISysInfo ,
37
+ private $staticConfig : Config . IStaticConfig ) { }
36
38
37
39
public addPlatforms ( platforms : string [ ] ) : IFuture < void > {
38
40
return ( ( ) => {
@@ -47,7 +49,7 @@ export class PlatformService implements IPlatformService {
47
49
}
48
50
49
51
private addPlatform ( platformParam : string ) : IFuture < void > {
50
- return ( ( ) => {
52
+ return ( ( ) => {
51
53
let [ platform , version ] = platformParam . split ( "@" ) ;
52
54
53
55
this . validatePlatform ( platform ) ;
@@ -77,7 +79,7 @@ export class PlatformService implements IPlatformService {
77
79
pathToSave : path . join ( this . $projectData . platformsDir , platform )
78
80
} ;
79
81
80
- if ( this . $options . frameworkPath ) {
82
+ if ( this . $options . frameworkPath ) {
81
83
packageToInstall = this . $options . frameworkPath ;
82
84
} else {
83
85
packageToInstall = platformData . frameworkPackageName ;
@@ -92,7 +94,7 @@ export class PlatformService implements IPlatformService {
92
94
frameworkDir = path . resolve ( frameworkDir ) ;
93
95
94
96
this . addPlatformCore ( platformData , frameworkDir ) . wait ( ) ;
95
- } catch ( err ) {
97
+ } catch ( err ) {
96
98
this . $fs . deleteDirectory ( platformPath ) . wait ( ) ;
97
99
throw err ;
98
100
} finally {
@@ -110,7 +112,7 @@ export class PlatformService implements IPlatformService {
110
112
let isFrameworkPathDirectory = false ,
111
113
isFrameworkPathNotSymlinkedFile = false ;
112
114
113
- if ( this . $options . frameworkPath ) {
115
+ if ( this . $options . frameworkPath ) {
114
116
let frameworkPathStats = this . $fs . getFsStats ( this . $options . frameworkPath ) . wait ( ) ;
115
117
isFrameworkPathDirectory = frameworkPathStats . isDirectory ( ) ;
116
118
isFrameworkPathNotSymlinkedFile = ! this . $options . symlink && frameworkPathStats . isFile ( ) ;
@@ -122,7 +124,7 @@ export class PlatformService implements IPlatformService {
122
124
let pathToTemplate = customTemplateOptions && customTemplateOptions . pathToTemplate ;
123
125
platformData . platformProjectService . createProject ( path . resolve ( sourceFrameworkDir ) , installedVersion , pathToTemplate ) . wait ( ) ;
124
126
125
- if ( isFrameworkPathDirectory || isFrameworkPathNotSymlinkedFile ) {
127
+ if ( isFrameworkPathDirectory || isFrameworkPathNotSymlinkedFile ) {
126
128
// Need to remove unneeded node_modules folder
127
129
// One level up is the runtime module and one above is the node_modules folder.
128
130
this . $fs . deleteDirectory ( path . join ( frameworkDir , "../../" ) ) . wait ( ) ;
@@ -134,8 +136,8 @@ export class PlatformService implements IPlatformService {
134
136
135
137
this . applyBaseConfigOption ( platformData ) . wait ( ) ;
136
138
137
- let frameworkPackageNameData : any = { version : installedVersion } ;
138
- if ( customTemplateOptions ) {
139
+ let frameworkPackageNameData : any = { version : installedVersion } ;
140
+ if ( customTemplateOptions ) {
139
141
frameworkPackageNameData . template = customTemplateOptions . selectedTemplate ;
140
142
}
141
143
this . $projectDataService . setValue ( platformData . frameworkPackageName , frameworkPackageNameData ) . wait ( ) ;
@@ -145,14 +147,14 @@ export class PlatformService implements IPlatformService {
145
147
146
148
private getPathToPlatformTemplate ( selectedTemplate : string , frameworkPackageName : string ) : IFuture < any > {
147
149
return ( ( ) => {
148
- if ( ! selectedTemplate ) {
150
+ if ( ! selectedTemplate ) {
149
151
// read data from package.json's nativescript key
150
152
// check the nativescript.tns-<platform>.template value
151
153
let nativescriptPlatformData = this . $projectDataService . getValue ( frameworkPackageName ) . wait ( ) ;
152
154
selectedTemplate = nativescriptPlatformData && nativescriptPlatformData . template ;
153
155
}
154
156
155
- if ( selectedTemplate ) {
157
+ if ( selectedTemplate ) {
156
158
let tempDir = temp . mkdirSync ( "platform-template" ) ;
157
159
try {
158
160
/*
@@ -166,7 +168,7 @@ export class PlatformService implements IPlatformService {
166
168
*/
167
169
let pathToTemplate = this . $npm . install ( selectedTemplate , tempDir ) . wait ( ) [ 0 ] [ 1 ] ;
168
170
return { selectedTemplate, pathToTemplate } ;
169
- } catch ( err ) {
171
+ } catch ( err ) {
170
172
this . $logger . trace ( "Error while trying to install specified template: " , err ) ;
171
173
this . $errors . failWithoutHelp ( `Unable to install platform template ${ selectedTemplate } . Make sure the specified value is valid.` ) ;
172
174
}
@@ -177,8 +179,8 @@ export class PlatformService implements IPlatformService {
177
179
}
178
180
179
181
public getInstalledPlatforms ( ) : IFuture < string [ ] > {
180
- return ( ( ) => {
181
- if ( ! this . $fs . exists ( this . $projectData . platformsDir ) . wait ( ) ) {
182
+ return ( ( ) => {
183
+ if ( ! this . $fs . exists ( this . $projectData . platformsDir ) . wait ( ) ) {
182
184
return [ ] ;
183
185
}
184
186
@@ -209,11 +211,21 @@ export class PlatformService implements IPlatformService {
209
211
//We need dev-dependencies here, so before-prepare hooks will be executed correctly.
210
212
try {
211
213
this . $pluginsService . ensureAllDependenciesAreInstalled ( ) . wait ( ) ;
212
- } catch ( err ) {
214
+ } catch ( err ) {
213
215
this . $logger . trace ( err ) ;
214
216
this . $errors . failWithoutHelp ( `Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: ${ err . message } ` ) ;
215
217
}
216
218
219
+ // Need to check if any plugin requires Cocoapods to be installed.
220
+ if ( platform === "ios" ) {
221
+ _ . each ( this . $pluginsService . getAllInstalledPlugins ( ) . wait ( ) , ( pluginData : IPluginData ) => {
222
+ if ( this . $fs . exists ( path . join ( pluginData . pluginPlatformsFolderPath ( platform ) , "Podfile" ) ) . wait ( ) &&
223
+ ! this . $sysInfo . getSysInfo ( this . $staticConfig . pathToPackageJson ) . wait ( ) . cocoapodVer ) {
224
+ this . $errors . failWithoutHelp ( `${ pluginData . name } has Podfile and you don't have Cocoapods installed or it is not configured correctly. Please install Cocoapods and configure it correctly.` ) ;
225
+ }
226
+ } ) ;
227
+ }
228
+
217
229
return this . preparePlatformCore ( platform ) . wait ( ) ;
218
230
} ) . future < boolean > ( ) ( ) ;
219
231
}
@@ -250,23 +262,23 @@ export class PlatformService implements IPlatformService {
250
262
}
251
263
252
264
let hasTnsModulesInAppFolder = this . $fs . exists ( path . join ( appSourceDirectoryPath , constants . TNS_MODULES_FOLDER_NAME ) ) . wait ( ) ;
253
- if ( hasTnsModulesInAppFolder && this . $projectData . dependencies && this . $projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] ) {
265
+ if ( hasTnsModulesInAppFolder && this . $projectData . dependencies && this . $projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] ) {
254
266
this . $logger . warn ( "You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it." ) ;
255
- sourceFiles = sourceFiles . filter ( source => ! minimatch ( source , `**/${ constants . TNS_MODULES_FOLDER_NAME } /**` , { nocase : true } ) ) ;
267
+ sourceFiles = sourceFiles . filter ( source => ! minimatch ( source , `**/${ constants . TNS_MODULES_FOLDER_NAME } /**` , { nocase : true } ) ) ;
256
268
}
257
269
258
270
// verify .xml files are well-formed
259
271
this . $xmlValidator . validateXmlFiles ( sourceFiles ) . wait ( ) ;
260
272
261
273
// Remove .ts and .js.map files
262
- constants . LIVESYNC_EXCLUDED_FILE_PATTERNS . forEach ( pattern => sourceFiles = sourceFiles . filter ( file => ! minimatch ( file , pattern , { nocase : true } ) ) ) ;
274
+ constants . LIVESYNC_EXCLUDED_FILE_PATTERNS . forEach ( pattern => sourceFiles = sourceFiles . filter ( file => ! minimatch ( file , pattern , { nocase : true } ) ) ) ;
263
275
let copyFileFutures = sourceFiles . map ( source => {
264
- let destinationPath = path . join ( appDestinationDirectoryPath , path . relative ( appSourceDirectoryPath , source ) ) ;
265
- if ( this . $fs . getFsStats ( source ) . wait ( ) . isDirectory ( ) ) {
266
- return this . $fs . createDirectory ( destinationPath ) ;
267
- }
268
- return this . $fs . copyFile ( source , destinationPath ) ;
269
- } ) ;
276
+ let destinationPath = path . join ( appDestinationDirectoryPath , path . relative ( appSourceDirectoryPath , source ) ) ;
277
+ if ( this . $fs . getFsStats ( source ) . wait ( ) . isDirectory ( ) ) {
278
+ return this . $fs . createDirectory ( destinationPath ) ;
279
+ }
280
+ return this . $fs . copyFile ( source , destinationPath ) ;
281
+ } ) ;
270
282
Future . wait ( copyFileFutures ) ;
271
283
272
284
// Copy App_Resources to project root folder
@@ -290,7 +302,7 @@ export class PlatformService implements IPlatformService {
290
302
// Clean target node_modules folder. Not needed when bundling.
291
303
this . $broccoliBuilder . cleanNodeModules ( tnsModulesDestinationPath , platform ) ;
292
304
}
293
- } catch ( error ) {
305
+ } catch ( error ) {
294
306
this . $logger . debug ( error ) ;
295
307
shell . rm ( "-rf" , appDir ) ;
296
308
this . $errors . failWithoutHelp ( `Processing node_modules failed. ${ error } ` ) ;
@@ -340,7 +352,7 @@ export class PlatformService implements IPlatformService {
340
352
} ) . future < void > ( ) ( ) ;
341
353
}
342
354
343
- public copyLastOutput ( platform : string , targetPath : string , settings : { isForDevice : boolean } ) : IFuture < void > {
355
+ public copyLastOutput ( platform : string , targetPath : string , settings : { isForDevice : boolean } ) : IFuture < void > {
344
356
return ( ( ) => {
345
357
let packageFile : string ;
346
358
platform = platform . toLowerCase ( ) ;
@@ -351,13 +363,13 @@ export class PlatformService implements IPlatformService {
351
363
} else {
352
364
packageFile = this . getLatestApplicationPackageForEmulator ( platformData ) . wait ( ) . packageName ;
353
365
}
354
- if ( ! packageFile || ! this . $fs . exists ( packageFile ) . wait ( ) ) {
366
+ if ( ! packageFile || ! this . $fs . exists ( packageFile ) . wait ( ) ) {
355
367
this . $errors . failWithoutHelp ( "Unable to find built application. Try 'tns build %s'." , platform ) ;
356
368
}
357
369
358
370
this . $fs . ensureDirectoryExists ( path . dirname ( targetPath ) ) . wait ( ) ;
359
371
360
- if ( this . $fs . exists ( targetPath ) . wait ( ) && this . $fs . getFsStats ( targetPath ) . wait ( ) . isDirectory ( ) ) {
372
+ if ( this . $fs . exists ( targetPath ) . wait ( ) && this . $fs . getFsStats ( targetPath ) . wait ( ) . isDirectory ( ) ) {
361
373
let sourceFileName = path . basename ( packageFile ) ;
362
374
this . $logger . trace ( `Specified target path: '${ targetPath } ' is directory. Same filename will be used: '${ sourceFileName } '.` ) ;
363
375
targetPath = path . join ( targetPath , sourceFileName ) ;
@@ -389,7 +401,7 @@ export class PlatformService implements IPlatformService {
389
401
return ( ( ) => {
390
402
_ . each ( platforms , platformParam => {
391
403
let [ platform , version ] = platformParam . split ( "@" ) ;
392
- if ( this . isPlatformInstalled ( platform ) . wait ( ) ) {
404
+ if ( this . isPlatformInstalled ( platform ) . wait ( ) ) {
393
405
this . updatePlatform ( platform , version ) . wait ( ) ;
394
406
} else {
395
407
this . addPlatform ( platformParam ) . wait ( ) ;
@@ -414,7 +426,7 @@ export class PlatformService implements IPlatformService {
414
426
this . ensurePlatformInstalled ( platform ) . wait ( ) ;
415
427
let platformData = this . $platformsData . getPlatformData ( platform ) ;
416
428
417
- this . $devicesService . initialize ( { platform : platform , deviceId : this . $options . device } ) . wait ( ) ;
429
+ this . $devicesService . initialize ( { platform : platform , deviceId : this . $options . device } ) . wait ( ) ;
418
430
let packageFile : string = null ;
419
431
420
432
let action = ( device : Mobile . IDevice ) : IFuture < void > => {
@@ -494,7 +506,7 @@ export class PlatformService implements IPlatformService {
494
506
}
495
507
496
508
public validatePlatform ( platform : string ) : void {
497
- if ( ! platform ) {
509
+ if ( ! platform ) {
498
510
this . $errors . fail ( "No platform specified." ) ;
499
511
}
500
512
@@ -519,7 +531,7 @@ export class PlatformService implements IPlatformService {
519
531
520
532
public ensurePlatformInstalled ( platform : string ) : IFuture < void > {
521
533
return ( ( ) => {
522
- if ( ! this . isPlatformInstalled ( platform ) . wait ( ) ) {
534
+ if ( ! this . isPlatformInstalled ( platform ) . wait ( ) ) {
523
535
this . addPlatform ( platform ) . wait ( ) ;
524
536
}
525
537
} ) . future < void > ( ) ( ) ;
@@ -551,13 +563,13 @@ export class PlatformService implements IPlatformService {
551
563
let packages = _ . filter ( candidates , candidate => {
552
564
return _ . contains ( validPackageNames , candidate ) ;
553
565
} ) . map ( currentPackage => {
554
- currentPackage = path . join ( buildOutputPath , currentPackage ) ;
566
+ currentPackage = path . join ( buildOutputPath , currentPackage ) ;
555
567
556
- return {
557
- packageName : currentPackage ,
558
- time : this . $fs . getFsStats ( currentPackage ) . wait ( ) . mtime
559
- } ;
560
- } ) ;
568
+ return {
569
+ packageName : currentPackage ,
570
+ time : this . $fs . getFsStats ( currentPackage ) . wait ( ) . mtime
571
+ } ;
572
+ } ) ;
561
573
562
574
return packages ;
563
575
} ) . future < IApplicationPackage [ ] > ( ) ( ) ;
@@ -598,17 +610,17 @@ export class PlatformService implements IPlatformService {
598
610
newVersion = ( cachedPackageData && cachedPackageData . version ) || newVersion ;
599
611
600
612
let canUpdate = platformData . platformProjectService . canUpdatePlatform ( currentVersion , newVersion ) . wait ( ) ;
601
- if ( canUpdate ) {
602
- if ( ! semver . valid ( newVersion ) ) {
613
+ if ( canUpdate ) {
614
+ if ( ! semver . valid ( newVersion ) ) {
603
615
this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts separated by dot." , newVersion ) ;
604
616
}
605
617
606
- if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
618
+ if ( semver . gt ( currentVersion , newVersion ) ) { // Downgrade
607
619
let isUpdateConfirmed = this . $prompter . confirm ( `You are going to downgrade to runtime v.${ newVersion } . Are you sure?` , ( ) => false ) . wait ( ) ;
608
- if ( isUpdateConfirmed ) {
620
+ if ( isUpdateConfirmed ) {
609
621
this . updatePlatformCore ( platformData , currentVersion , newVersion , canUpdate ) . wait ( ) ;
610
622
}
611
- } else if ( semver . eq ( currentVersion , newVersion ) ) {
623
+ } else if ( semver . eq ( currentVersion , newVersion ) ) {
612
624
this . $errors . fail ( "Current and new version are the same." ) ;
613
625
} else {
614
626
this . updatePlatformCore ( platformData , currentVersion , newVersion , canUpdate ) . wait ( ) ;
@@ -623,9 +635,9 @@ export class PlatformService implements IPlatformService {
623
635
private updatePlatformCore ( platformData : IPlatformData , currentVersion : string , newVersion : string , canUpdate : boolean ) : IFuture < void > {
624
636
return ( ( ) => {
625
637
let update = platformData . platformProjectService . updatePlatform ( currentVersion , newVersion , canUpdate , this . addPlatform . bind ( this ) , this . removePlatforms . bind ( this ) ) . wait ( ) ;
626
- if ( update ) {
638
+ if ( update ) {
627
639
// Remove old framework files
628
- let oldFrameworkData = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
640
+ let oldFrameworkData = this . getFrameworkFiles ( platformData , currentVersion ) . wait ( ) ;
629
641
630
642
_ . each ( oldFrameworkData . frameworkFiles , file => {
631
643
let fileToDelete = path . join ( platformData . projectRoot , file ) ;
@@ -659,7 +671,7 @@ export class PlatformService implements IPlatformService {
659
671
660
672
// Update .tnsproject file
661
673
this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
662
- this . $projectDataService . setValue ( platformData . frameworkPackageName , { version : newVersion } ) . wait ( ) ;
674
+ this . $projectDataService . setValue ( platformData . frameworkPackageName , { version : newVersion } ) . wait ( ) ;
663
675
664
676
this . $logger . out ( "Successfully updated to version " , newVersion ) ;
665
677
}
@@ -690,7 +702,7 @@ export class PlatformService implements IPlatformService {
690
702
691
703
private applyBaseConfigOption ( platformData : IPlatformData ) : IFuture < void > {
692
704
return ( ( ) => {
693
- if ( this . $options . baseConfig ) {
705
+ if ( this . $options . baseConfig ) {
694
706
let newConfigFile = path . resolve ( this . $options . baseConfig ) ;
695
707
this . $logger . trace ( `Replacing '${ platformData . configurationFilePath } ' with '${ newConfigFile } '.` ) ;
696
708
this . $fs . copyFile ( newConfigFile , platformData . configurationFilePath ) . wait ( ) ;
0 commit comments