1
1
const fs = require ( 'fs' ) ,
2
- path = require ( 'path' ) ;
2
+ path = require ( 'path' ) ,
3
+ prepareHooksHelper = require ( "../prepare-hooks-helper" ) ;
3
4
4
5
// inject some code into main.m
5
6
function patchUIApplicationMain ( iosProjectFolder ) {
@@ -17,20 +18,20 @@ function patchUIApplicationMain(iosProjectFolder) {
17
18
if ( tnsAppSyncFileDestContents . indexOf ( "TNSAppSync" ) === - 1 ) {
18
19
// let's first inject a header we need
19
20
replaceInFile (
20
- appSyncFileDest ,
21
- '#include <NativeScript/NativeScript.h>' ,
22
- '#include <NativeScript/NativeScript.h>\n#include <AppSync/TNSAppSync.h>'
21
+ appSyncFileDest ,
22
+ '#include <NativeScript/NativeScript.h>' ,
23
+ '#include <NativeScript/NativeScript.h>\n#include <AppSync/TNSAppSync.h>'
23
24
) ;
24
25
25
26
// now inject the function call that determines the correct application path (either default or appsync'ed)
26
27
replaceInFile (
27
- appSyncFileDest ,
28
- 'applicationPath = [NSBundle mainBundle].bundlePath;' ,
29
- 'applicationPath = [TNSAppSync applicationPathWithDefault:[NSBundle mainBundle].bundlePath];'
28
+ appSyncFileDest ,
29
+ 'applicationPath = [NSBundle mainBundle].bundlePath;' ,
30
+ 'applicationPath = [TNSAppSync applicationPathWithDefault:[NSBundle mainBundle].bundlePath];'
30
31
) ;
31
32
}
32
33
33
- } catch ( e ) {
34
+ } catch ( e ) {
34
35
console . log ( "AppSync iOS hook error: " + e ) ;
35
36
}
36
37
}
@@ -41,11 +42,11 @@ function replaceInFile(theFile, what, by) {
41
42
fs . writeFileSync ( theFile , result , 'utf8' ) ;
42
43
}
43
44
44
- module . exports = function ( logger , platformsData , projectData , hookArgs ) {
45
- const iosProjectFolder = path . join ( projectData . platformsDir , "ios" ) ;
45
+ module . exports = function ( $injector , hookArgs ) {
46
+ const platform = prepareHooksHelper . getPlatformFromPrepareHookArgs ( hookArgs ) ;
46
47
47
- return new Promise ( function ( resolve , reject ) {
48
+ if ( platform === 'ios' ) {
49
+ const iosProjectFolder = prepareHooksHelper . getNativeProjectDir ( $injector , platform , hookArgs ) ;
48
50
patchUIApplicationMain ( iosProjectFolder ) ;
49
- resolve ( ) ;
50
- } ) ;
51
+ }
51
52
} ;
0 commit comments