var path = require ( "path" ) ; var fs = require ( "fs" ) ; module . exports = { copyAndroidConfig : function ( appResourcesDirPath , projectDir , projectName , buildType , logger ) { copyFacebookResourceFileOpt = { appResourcesDirPath , projectDir , projectName , buildType , logger , originalFileName : "facebooklogin.xml" , prodFileName : "facebooklogin.prod.xml" , devFileName : "facebooklogin.dev.xml" } ; copyResourceFile ( copyFacebookResourceFileOpt ) ; copyStringResourceFileOpt = { appResourcesDirPath , projectDir , projectName , buildType , logger , originalFileName : "strings.xml" , prodFileName : "strings.prod.xml" , devFileName : "strings.dev.xml" } ; copyResourceFile ( copyStringResourceFileOpt ) ; } , copyIosConfig ( appResourcesDirPath , projectDir , projectName , buildType , logger , platform , platformsDir , isProdEnv ) { var appResourcesDirectoryPath = appResourcesDirPath ; var projectDirectoryPath = projectDir ; var forcePrepare = true ; var npfInfoPath = path . join ( platformsDir , platform , ".pluginfirebaseinfo" ) ; var nsPrepareInfoPath = path . join ( platformsDir , platform , ".nsprepareinfo" ) ; var project = projectName ; var copyPlistOpts = { platform , appResourcesDirectoryPath , projectDirectoryPath , buildType , isProdEnv , logger , project } ; if ( fs . existsSync ( npfInfoPath ) ) { try { npfInfo = JSON . parse ( fs . readFileSync ( npfInfoPath , 'utf8' ) ) ; } catch ( e ) { logger . info ( 'nativescript-plugin-firebase: error reading ' + npfInfoPath ) ; } } else { logger . info ( 'nativescript-plugin-firebase: 119' + npfInfoPath + ' not found, forcing prepare!' ) ; } logger . info ( 'nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!' ) ; if ( fs . existsSync ( npfInfoPath ) ) { fs . unlinkSync ( npfInfoPath ) ; } if ( fs . existsSync ( nsPrepareInfoPath ) ) { fs . unlinkSync ( nsPrepareInfoPath ) ; } copyPlist ( copyPlistOpts ) ; copyInfoPlist ( copyPlistOpts ) ; return true ; } } ; var copyPlist = function ( copyPlistOpts ) { if ( copyPlistOpts . platform === 'android' ) { return true ; } else if ( copyPlistOpts . platform === 'ios' ) { var sourceGooglePlistProd = path . join ( copyPlistOpts . projectDirectoryPath , "configurations" , `${ copyPlistOpts . project }/ios/GoogleService-Info.plist.prod` ) ; var sourceGooglePlistDev = path . join ( copyPlistOpts . projectDirectoryPath , "configurations" , `${ copyPlistOpts . project }/ios/GoogleService-Info.plist.dev` ) ; var destinationGooglePlist = path . join ( copyPlistOpts . appResourcesDirectoryPath , "iOS" , "GoogleService-Info.plist" ) ; if ( fs . existsSync ( sourceGooglePlistProd ) && fs . existsSync ( sourceGooglePlistDev ) ) { if ( copyPlistOpts . isProdEnv ) { copyPlistOpts . logger . info ( "nativescript-plugin-firebase: copy " + sourceGooglePlistProd + " to " + destinationGooglePlist + "." ) ; fs . writeFileSync ( destinationGooglePlist , fs . readFileSync ( sourceGooglePlistProd ) ) ; return true ; } else { copyPlistOpts . logger . info ( "nativescript-plugin-firebase: copy " + sourceGooglePlistDev + " to " + destinationGooglePlist + "." ) ; fs . writeFileSync ( destinationGooglePlist , fs . readFileSync ( sourceGooglePlistDev ) ) ; return true ; } } else if ( ! fs . existsSync ( destinationGooglePlist ) ) { copyPlistOpts . logger . warn ( "nativescript-plugin-firebase: 175" + destinationGooglePlist + " does not exist. Please follow the installation instructions from the documentation" ) ; return false ; } else { return true ; } } else { return true ; } } ; var copyInfoPlist = function ( copyPlistOpts ) { if ( copyPlistOpts . platform === 'android' ) { return true ; } else if ( copyPlistOpts . platform === 'ios' ) { var sourceInfoPlistProd = path . join ( copyPlistOpts . projectDirectoryPath , "configurations" , copyPlistOpts . project , "ios" , "Info.plist.prod" ) ; var sourceInfoPlistDev = path . join ( copyPlistOpts . projectDirectoryPath , "configurations" , copyPlistOpts . project , "ios" , "Info.plist.dev" ) ; var destinationInfoPlist = path . join ( copyPlistOpts . appResourcesDirectoryPath , "iOS" , "Info.plist" ) ; if ( fs . existsSync ( sourceInfoPlistProd ) && fs . existsSync ( sourceInfoPlistDev ) ) { if ( copyPlistOpts . isProdEnv ) { copyPlistOpts . logger . info ( "nativescript-plugin-firebase: copy " + sourceInfoPlistProd + " to " + destinationInfoPlist + "." ) ; fs . writeFileSync ( destinationInfoPlist , fs . readFileSync ( sourceInfoPlistProd ) ) ; return true ; } else { copyPlistOpts . logger . info ( "nativescript-plugin-firebase: copy " + sourceInfoPlistDev + " to " + destinationInfoPlist + "." ) ; fs . writeFileSync ( destinationInfoPlist , fs . readFileSync ( sourceInfoPlistDev ) ) ; return true ; } } else if ( ! fs . existsSync ( destinationInfoPlist ) ) { copyPlistOpts . logger . warn ( "nativescript-plugin-firebase: 206 " + destinationInfoPlist + " does not exist. Please follow the installation instructions from the documentation" ) ; return false ; } else { return true ; } } else { return true ; } } ; var copyResourceFile = function ( options ) { var destinationXml = path . join ( options . appResourcesDirPath , "Android" , "src" , "main" , "res" , "values" , options . originalFileName ) ; var destinationXmlAlt = path . join ( options . appResourcesDirPath , "Android" , "src" , "main" , "res" , "values" , options . originalFileName ) ; var sourceXml = path . join ( options . projectDir , "configurations" , "android" , options . originalFileName ) ; var sourceXmlProd = path . join ( options . projectDir , "configurations" , options . projectName , "android" , options . prodFileName ) ; var sourceXmlDev = path . join ( options . projectDir , "configurations" , options . projectName , "android" , options . devFileName ) ; if ( fs . existsSync ( sourceXmlProd ) && fs . existsSync ( sourceXmlDev ) ) { if ( options . buildType === 'production' ) { sourceXml = sourceXmlProd ; } else { sourceXml = sourceXmlDev ; } } if ( fs . existsSync ( sourceXml ) && fs . existsSync ( path . dirname ( destinationXml ) ) ) { options . logger . info ( "Copy " + sourceXml + " to " + destinationXml + "." ) ; fs . writeFileSync ( destinationXml , fs . readFileSync ( sourceXml ) ) ; facebookFileExist = true ; } else if ( fs . existsSync ( sourceXml ) && fs . existsSync ( path . dirname ( destinationXmlAlt ) ) ) { options . logger . info ( "Copy " + sourceXml + " to " + destinationXmlAlt + "." ) ; fs . writeFileSync ( destinationXmlAlt , fs . readFileSync ( sourceXml ) ) ; facebookFileExist = true ; } else { options . logger . warn ( `Unable to copy ${ options . originalFileName }.` ) ; facebookFileExist = false ; } } ;