@@ -8,24 +8,28 @@ import util = require("util");
8
8
import xcode = require( "xcode" ) ;
9
9
import constants = require( "./../constants" ) ;
10
10
import helpers = require( "./../common/helpers" ) ;
11
+ import projectServiceBaseLib = require( "./platform-project-service-base" ) ;
11
12
12
- class IOSProjectService implements IPlatformProjectService {
13
+ class IOSProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
13
14
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj" ;
14
15
private static XCODEBUILD_MIN_VERSION = "6.0" ;
15
16
private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__" ;
17
+ private static IOS_PLATFORM_NAME = "ios" ;
16
18
17
19
private get $npmInstallationManager ( ) : INpmInstallationManager {
18
20
return this . $injector . resolve ( "npmInstallationManager" ) ;
19
21
}
20
22
21
23
constructor ( private $projectData : IProjectData ,
22
- private $fs : IFileSystem ,
24
+ $fs : IFileSystem ,
23
25
private $childProcess : IChildProcess ,
24
26
private $errors : IErrors ,
25
27
private $logger : ILogger ,
26
28
private $iOSEmulatorServices : Mobile . IEmulatorPlatformServices ,
27
29
private $options : IOptions ,
28
- private $injector : IInjector ) { }
30
+ private $injector : IInjector ) {
31
+ super ( $fs ) ;
32
+ }
29
33
30
34
public get platformData ( ) : IPlatformData {
31
35
var projectRoot = path . join ( this . $projectData . platformsDir , "ios" ) ;
@@ -67,7 +71,7 @@ class IOSProjectService implements IPlatformProjectService {
67
71
var splitedXcodeBuildVersion = xcodeBuildVersion . split ( "." ) ;
68
72
if ( splitedXcodeBuildVersion . length === 3 ) {
69
73
xcodeBuildVersion = util . format ( "%s.%s" , splitedXcodeBuildVersion [ 0 ] , splitedXcodeBuildVersion [ 1 ] ) ;
70
- }
74
+ }
71
75
72
76
if ( helpers . versionCompare ( xcodeBuildVersion , IOSProjectService . XCODEBUILD_MIN_VERSION ) < 0 ) {
73
77
this . $errors . fail ( "NativeScript can only run in Xcode version %s or greater" , IOSProjectService . XCODEBUILD_MIN_VERSION ) ;
@@ -172,23 +176,23 @@ class IOSProjectService implements IPlatformProjectService {
172
176
return this . $fs . exists ( path . join ( projectRoot , this . $projectData . projectName , constants . APP_FOLDER_NAME ) ) ;
173
177
}
174
178
175
- public addLibrary ( platformData : IPlatformData , libraryPath : string ) : IFuture < void > {
176
- return ( ( ) => {
177
- this . validateDynamicFramework ( libraryPath ) . wait ( ) ;
178
- var umbrellaHeader = this . getUmbrellaHeaderFromDynamicFramework ( libraryPath ) . wait ( ) ;
179
+ public addLibrary ( libraryPath : string ) : IFuture < void > {
180
+ return ( ( ) => {
181
+ this . validateDynamicFramework ( libraryPath ) . wait ( ) ;
182
+ var umbrellaHeader = this . getUmbrellaHeaderFromDynamicFramework ( libraryPath ) . wait ( ) ;
179
183
180
- var frameworkName = path . basename ( libraryPath , path . extname ( libraryPath ) ) ;
181
- var targetPath = path . join ( this . $projectData . projectDir , "lib" , platformData . normalizedPlatformName , frameworkName ) ;
182
- this . $fs . ensureDirectoryExists ( targetPath ) . wait ( ) ;
183
- shell . cp ( "-R" , libraryPath , targetPath ) ;
184
+ var frameworkName = path . basename ( libraryPath , path . extname ( libraryPath ) ) ;
185
+ var targetPath = path . join ( this . $projectData . projectDir , "lib" , this . platformData . normalizedPlatformName , frameworkName ) ;
186
+ this . $fs . ensureDirectoryExists ( targetPath ) . wait ( ) ;
187
+ shell . cp ( "-R" , libraryPath , targetPath ) ;
184
188
185
- let project = this . createPbxProj ( ) ;
189
+ let project = this . createPbxProj ( ) ;
186
190
187
- project . addFramework ( path . join ( targetPath , frameworkName + ".framework" ) , { customFramework : true , embed : true } ) ;
188
- project . updateBuildProperty ( "IPHONEOS_DEPLOYMENT_TARGET" , "8.0" ) ;
189
- this . savePbxProj ( project ) . wait ( ) ;
190
- this . $logger . info ( "The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks." ) ;
191
- } ) . future < void > ( ) ( ) ;
191
+ project . addFramework ( path . join ( targetPath , frameworkName + ".framework" ) , { customFramework : true , embed : true } ) ;
192
+ project . updateBuildProperty ( "IPHONEOS_DEPLOYMENT_TARGET" , "8.0" ) ;
193
+ this . savePbxProj ( project ) . wait ( ) ;
194
+ this . $logger . info ( "The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks." ) ;
195
+ } ) . future < void > ( ) ( ) ;
192
196
}
193
197
194
198
public canUpdatePlatform ( currentVersion : string , newVersion : string ) : IFuture < boolean > {
@@ -282,48 +286,63 @@ class IOSProjectService implements IPlatformProjectService {
282
286
}
283
287
284
288
public preparePluginNativeCode ( pluginData : IPluginData ) : IFuture < void > {
285
- return Future . fromResult ( ) ;
289
+ return ( ( ) => {
290
+ let pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
291
+ _ . each ( this . getAllDynamicFrameworksForPlugin ( pluginData ) . wait ( ) , fileName => this . addLibrary ( path . join ( pluginPlatformsFolderPath , fileName ) ) . wait ( ) ) ;
292
+ } ) . future < void > ( ) ( ) ;
286
293
}
287
294
288
295
public removePluginNativeCode ( pluginData : IPluginData ) : IFuture < void > {
289
- return Future . fromResult ( ) ;
296
+ return ( ( ) => {
297
+ let pluginPlatformsFolderPath = pluginData . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
298
+ let project = this . createPbxProj ( ) ;
299
+
300
+ _ . each ( this . getAllDynamicFrameworksForPlugin ( pluginData ) . wait ( ) , fileName => project . removeFramework ( path . join ( pluginPlatformsFolderPath , fileName + ".framework" ) , { customFramework : true , embed : true } ) ) ;
301
+
302
+ this . savePbxProj ( project ) . wait ( ) ;
303
+ } ) . future < void > ( ) ( ) ;
304
+ }
305
+
306
+ private getAllDynamicFrameworksForPlugin ( pluginData : IPluginData ) : IFuture < string [ ] > {
307
+ let filterCallback = ( fileName : string , pluginPlatformsFolderPath : string ) => path . extname ( fileName ) === ".framework" ;
308
+ return this . getAllNativeLibrariesForPlugin ( pluginData , IOSProjectService . IOS_PLATFORM_NAME , filterCallback ) ;
290
309
}
291
310
292
311
private buildPathToXcodeProjectFile ( version : string ) : string {
293
312
return path . join ( this . $npmInstallationManager . getCachedPackagePath ( this . platformData . frameworkPackageName , version ) , constants . PROJECT_FRAMEWORK_FOLDER_NAME , util . format ( "%s.xcodeproj" , IOSProjectService . IOS_PROJECT_NAME_PLACEHOLDER ) , "project.pbxproj" ) ;
294
313
}
295
314
296
- private validateDynamicFramework ( libraryPath : string ) : IFuture < void > {
297
- return ( ( ) => {
298
- var infoPlistPath = path . join ( libraryPath , "Info.plist" ) ;
299
- if ( ! this . $fs . exists ( infoPlistPath ) . wait ( ) ) {
300
- this . $errors . failWithoutHelp ( "The bundle at %s does not contain an Info.plist file." , libraryPath ) ;
301
- }
302
-
303
- var packageType = this . $childProcess . exec ( `/usr/libexec/PlistBuddy -c "Print :CFBundlePackageType" "${ infoPlistPath } "` ) . wait ( ) . trim ( ) ;
304
- if ( packageType !== "FMWK" ) {
305
- this . $errors . failWithoutHelp ( "The bundle at %s does not appear to be a dynamic framework." , libraryPath ) ;
306
- }
307
- } ) . future < void > ( ) ( ) ;
308
- }
309
-
310
- private getUmbrellaHeaderFromDynamicFramework ( libraryPath : string ) : IFuture < string > {
311
- return ( ( ) => {
312
- var modulemapPath = path . join ( libraryPath , "Modules" , "module.modulemap" ) ;
313
- if ( ! this . $fs . exists ( modulemapPath ) . wait ( ) ) {
315
+ private validateDynamicFramework ( libraryPath : string ) : IFuture < void > {
316
+ return ( ( ) => {
317
+ var infoPlistPath = path . join ( libraryPath , "Info.plist" ) ;
318
+ if ( ! this . $fs . exists ( infoPlistPath ) . wait ( ) ) {
319
+ this . $errors . failWithoutHelp ( "The bundle at %s does not contain an Info.plist file." , libraryPath ) ;
320
+ }
321
+
322
+ var packageType = this . $childProcess . exec ( `/usr/libexec/PlistBuddy -c "Print :CFBundlePackageType" "${ infoPlistPath } "` ) . wait ( ) . trim ( ) ;
323
+ if ( packageType !== "FMWK" ) {
324
+ this . $errors . failWithoutHelp ( "The bundle at %s does not appear to be a dynamic framework." , libraryPath ) ;
325
+ }
326
+ } ) . future < void > ( ) ( ) ;
327
+ }
328
+
329
+ private getUmbrellaHeaderFromDynamicFramework ( libraryPath : string ) : IFuture < string > {
330
+ return ( ( ) => {
331
+ var modulemapPath = path . join ( libraryPath , "Modules" , "module.modulemap" ) ;
332
+ if ( ! this . $fs . exists ( modulemapPath ) . wait ( ) ) {
314
333
this . $errors . failWithoutHelp ( "The framework at %s does not contain a module.modulemap file." , modulemapPath ) ;
315
- }
316
-
317
- var modulemap = this . $fs . readText ( modulemapPath ) . wait ( ) ;
318
- var umbrellaRegex = / u m b r e l l a h e a d e r " ( .+ \. h ) " / g;
319
- var match = umbrellaRegex . exec ( modulemap ) ;
320
- if ( ! match ) {
321
- this . $errors . failWithoutHelp ( "The modulemap at %s does not specify an umbrella header." , modulemapPath ) ;
322
- }
323
-
324
- return match [ 1 ] ;
325
- } ) . future < string > ( ) ( ) ;
326
- }
334
+ }
335
+
336
+ var modulemap = this . $fs . readText ( modulemapPath ) . wait ( ) ;
337
+ var umbrellaRegex = / u m b r e l l a h e a d e r " ( .+ \. h ) " / g;
338
+ var match = umbrellaRegex . exec ( modulemap ) ;
339
+ if ( ! match ) {
340
+ this . $errors . failWithoutHelp ( "The modulemap at %s does not specify an umbrella header." , modulemapPath ) ;
341
+ }
342
+
343
+ return match [ 1 ] ;
344
+ } ) . future < string > ( ) ( ) ;
345
+ }
327
346
328
347
private replaceFileContent ( file : string ) : IFuture < void > {
329
348
return ( ( ) => {
0 commit comments