@@ -11,95 +11,61 @@ var fs = require('fs');
11
11
var path = require ( "path" ) ;
12
12
var Utilities = require ( "./lib/utilities" ) ;
13
13
14
- var appName = Utilities . getAppName ( ) ;
14
+ var appName ;
15
15
var pluginVariables = { } ;
16
16
17
17
var IOS_DIR = 'platforms/ios' ;
18
18
var ANDROID_DIR = 'platforms/android' ;
19
- var PLUGIN_ID = 'cordova-plugin-firebasex' ;
20
-
21
- var PLATFORM = {
22
- IOS : {
23
- dest : IOS_DIR + '/' + appName + '/Resources/GoogleService-Info.plist' ,
24
- src : [
25
- 'GoogleService-Info.plist' ,
26
- IOS_DIR + '/www/GoogleService-Info.plist' ,
27
- 'www/GoogleService-Info.plist'
28
- ] ,
29
- appPlist : IOS_DIR + '/' + appName + '/' + appName + '-Info.plist' ,
30
- entitlementsDebugPlist : IOS_DIR + '/' + appName + '/Entitlements-Debug.plist' ,
31
- entitlementsReleasePlist : IOS_DIR + '/' + appName + '/Entitlements-Release.plist' ,
32
- } ,
33
- ANDROID : {
34
- dest : ANDROID_DIR + '/app/google-services.json' ,
35
- src : [
36
- 'google-services.json' ,
37
- ANDROID_DIR + '/assets/www/google-services.json' ,
38
- 'www/google-services.json' ,
39
- ANDROID_DIR + '/app/src/main/google-services.json'
40
- ] ,
41
- colorsXml :{
42
- src : './plugins/' + Utilities . getPluginId ( ) + '/src/android/colors.xml' ,
43
- target : ANDROID_DIR + '/app/src/main/res/values/colors.xml'
19
+ var PLUGIN_ID ;
20
+
21
+ var PLATFORM ;
22
+
23
+ var setupEnv = function ( ) {
24
+ appName = Utilities . getAppName ( ) ;
25
+ PLUGIN_ID = Utilities . getPluginId ( ) ;
26
+ PLATFORM = {
27
+ IOS : {
28
+ dest : IOS_DIR + '/' + appName + '/Resources/GoogleService-Info.plist' ,
29
+ src : [
30
+ 'GoogleService-Info.plist' ,
31
+ IOS_DIR + '/www/GoogleService-Info.plist' ,
32
+ 'www/GoogleService-Info.plist'
33
+ ] ,
34
+ appPlist : IOS_DIR + '/' + appName + '/' + appName + '-Info.plist' ,
35
+ entitlementsDebugPlist : IOS_DIR + '/' + appName + '/Entitlements-Debug.plist' ,
36
+ entitlementsReleasePlist : IOS_DIR + '/' + appName + '/Entitlements-Release.plist' ,
37
+ } ,
38
+ ANDROID : {
39
+ dest : ANDROID_DIR + '/app/google-services.json' ,
40
+ src : [
41
+ 'google-services.json' ,
42
+ ANDROID_DIR + '/assets/www/google-services.json' ,
43
+ 'www/google-services.json' ,
44
+ ANDROID_DIR + '/app/src/main/google-services.json'
45
+ ] ,
46
+ colorsXml : {
47
+ src : './plugins/' + Utilities . getPluginId ( ) + '/src/android/colors.xml' ,
48
+ target : ANDROID_DIR + '/app/src/main/res/values/colors.xml'
49
+ }
44
50
}
45
- }
46
- } ;
51
+ } ;
52
+ }
47
53
54
+ module . exports = function ( context ) {
55
+ //get platform from the context supplied by cordova
56
+ var platforms = context . opts . platforms ;
57
+ Utilities . setContext ( context ) ;
58
+ setupEnv ( ) ;
48
59
49
- var parsePluginVariables = function ( ) {
50
- // Parse plugin.xml
51
- var plugin = Utilities . parsePluginXml ( ) ;
52
- var prefs = [ ] ;
53
- if ( plugin . plugin . preference ) {
54
- prefs = prefs . concat ( plugin . plugin . preference ) ;
55
- }
56
- plugin . plugin . platform . forEach ( function ( platform ) {
57
- if ( platform . preference ) {
58
- prefs = prefs . concat ( platform . preference ) ;
59
- }
60
- } ) ;
61
- prefs . forEach ( function ( pref ) {
62
- if ( pref . _attributes ) {
63
- pluginVariables [ pref . _attributes . name ] = pref . _attributes . default ;
64
- }
65
- } ) ;
66
-
67
- // Parse config.xml
68
- var config = Utilities . parseConfigXml ( ) ;
69
- ( config . widget . plugin ? [ ] . concat ( config . widget . plugin ) : [ ] ) . forEach ( function ( plugin ) {
70
- ( plugin . variable ? [ ] . concat ( plugin . variable ) : [ ] ) . forEach ( function ( variable ) {
71
- if ( ( plugin . _attributes . name === PLUGIN_ID || plugin . _attributes . id === PLUGIN_ID ) && variable . _attributes . name && variable . _attributes . value ) {
72
- pluginVariables [ variable . _attributes . name ] = variable . _attributes . value ;
73
- }
74
- } ) ;
75
- } ) ;
76
-
77
- // Parse package.json
78
- var packageJSON = Utilities . parsePackageJson ( ) ;
79
- if ( packageJSON . cordova && packageJSON . cordova . plugins ) {
80
- for ( const pluginId in packageJSON . cordova . plugins ) {
81
- if ( pluginId === PLUGIN_ID ) {
82
- for ( const varName in packageJSON . cordova . plugins [ pluginId ] ) {
83
- var varValue = packageJSON . cordova . plugins [ pluginId ] [ varName ] ;
84
- pluginVariables [ varName ] = varValue ;
85
- }
86
- }
87
- }
88
- }
60
+ pluginVariables = Utilities . parsePluginVariables ( ) ;
89
61
90
62
// set platform key path from plugin variable
91
- if ( pluginVariables . ANDROID_FIREBASE_CONFIG_FILEPATH ) PLATFORM . ANDROID . src = [ pluginVariables . ANDROID_FIREBASE_CONFIG_FILEPATH ] ;
92
- if ( pluginVariables . IOS_FIREBASE_CONFIG_FILEPATH ) PLATFORM . IOS . src = [ pluginVariables . IOS_FIREBASE_CONFIG_FILEPATH ] ;
93
- } ;
94
-
95
- module . exports = function ( context ) {
63
+ if ( pluginVariables . ANDROID_FIREBASE_CONFIG_FILEPATH ) PLATFORM . ANDROID . src = [ pluginVariables . ANDROID_FIREBASE_CONFIG_FILEPATH ] ;
64
+ if ( pluginVariables . IOS_FIREBASE_CONFIG_FILEPATH ) PLATFORM . IOS . src = [ pluginVariables . IOS_FIREBASE_CONFIG_FILEPATH ] ;
96
65
97
- //get platform from the context supplied by cordova
98
- var platforms = context . opts . platforms ;
99
- parsePluginVariables ( ) ;
100
66
101
67
// Copy key files to their platform specific folders
102
- if ( platforms . indexOf ( 'android' ) !== - 1 && Utilities . directoryExists ( ANDROID_DIR ) ) {
68
+ if ( platforms . indexOf ( 'android' ) !== - 1 && Utilities . directoryExists ( ANDROID_DIR ) ) {
103
69
Utilities . log ( 'Preparing Firebase on Android' ) ;
104
70
Utilities . copyKey ( PLATFORM . ANDROID ) ;
105
71
@@ -152,7 +118,7 @@ module.exports = function (context) {
152
118
}
153
119
}
154
120
155
- if ( platforms . indexOf ( 'ios' ) !== - 1 && Utilities . directoryExists ( IOS_DIR ) ) {
121
+ if ( platforms . indexOf ( 'ios' ) !== - 1 && Utilities . directoryExists ( IOS_DIR ) ) {
156
122
Utilities . log ( 'Preparing Firebase on iOS' ) ;
157
123
Utilities . copyKey ( PLATFORM . IOS ) ;
158
124
0 commit comments