@@ -8,24 +8,28 @@ import util = require("util");
88import xcode = require( "xcode" ) ;
99import constants = require( "./../constants" ) ;
1010import helpers = require( "./../common/helpers" ) ;
11+ import projectServiceBaseLib = require( "./platform-project-service-base" ) ;
1112
12- class IOSProjectService implements IPlatformProjectService {
13+ class IOSProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
1314 private static XCODE_PROJECT_EXT_NAME = ".xcodeproj" ;
1415 private static XCODEBUILD_MIN_VERSION = "6.0" ;
1516 private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__" ;
17+ private static IOS_PLATFORM_NAME = "ios" ;
1618
1719 private get $npmInstallationManager ( ) : INpmInstallationManager {
1820 return this . $injector . resolve ( "npmInstallationManager" ) ;
1921 }
2022
2123 constructor ( private $projectData : IProjectData ,
22- private $fs : IFileSystem ,
24+ $fs : IFileSystem ,
2325 private $childProcess : IChildProcess ,
2426 private $errors : IErrors ,
2527 private $logger : ILogger ,
2628 private $iOSEmulatorServices : Mobile . IEmulatorPlatformServices ,
2729 private $options : IOptions ,
28- private $injector : IInjector ) { }
30+ private $injector : IInjector ) {
31+ super ( $fs ) ;
32+ }
2933
3034 public get platformData ( ) : IPlatformData {
3135 var projectRoot = path . join ( this . $projectData . platformsDir , "ios" ) ;
@@ -67,7 +71,7 @@ class IOSProjectService implements IPlatformProjectService {
6771 var splitedXcodeBuildVersion = xcodeBuildVersion . split ( "." ) ;
6872 if ( splitedXcodeBuildVersion . length === 3 ) {
6973 xcodeBuildVersion = util . format ( "%s.%s" , splitedXcodeBuildVersion [ 0 ] , splitedXcodeBuildVersion [ 1 ] ) ;
70- }
74+ }
7175
7276 if ( helpers . versionCompare ( xcodeBuildVersion , IOSProjectService . XCODEBUILD_MIN_VERSION ) < 0 ) {
7377 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 {
172176 return this . $fs . exists ( path . join ( projectRoot , this . $projectData . projectName , constants . APP_FOLDER_NAME ) ) ;
173177 }
174178
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 ( ) ;
179183
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 ) ;
184188
185- let project = this . createPbxProj ( ) ;
189+ let project = this . createPbxProj ( ) ;
186190
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 > ( ) ( ) ;
192196 }
193197
194198 public canUpdatePlatform ( currentVersion : string , newVersion : string ) : IFuture < boolean > {
@@ -282,48 +286,63 @@ class IOSProjectService implements IPlatformProjectService {
282286 }
283287
284288 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 > ( ) ( ) ;
286293 }
287294
288295 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 ) ;
290309 }
291310
292311 private buildPathToXcodeProjectFile ( version : string ) : string {
293312 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" ) ;
294313 }
295314
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 ( ) ) {
314333 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+ }
327346
328347 private replaceFileContent ( file : string ) : IFuture < void > {
329348 return ( ( ) => {
0 commit comments