From c5793cbac52100017b91e406509de57b49abda0f Mon Sep 17 00:00:00 2001 From: Volodymyr Lavrynovych Date: Thu, 13 Jul 2017 14:45:49 +0300 Subject: [PATCH] #30: refactoring --- copy_google_services_config_files.js | 37 ++++++++++++---------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/copy_google_services_config_files.js b/copy_google_services_config_files.js index 0e401d1..1c62972 100644 --- a/copy_google_services_config_files.js +++ b/copy_google_services_config_files.js @@ -10,41 +10,38 @@ var fse = require('fs-extra'); var config = fse.readFileSync('config.xml').toString(); var name = getValue(config, 'name'); +var IOS_DIR = 'platforms/ios'; +var ANDROID_DIR = 'platforms/android'; + var PLATFORM = { IOS: { dest: [ - 'platforms/ios/' + name + '/Resources/GoogleService-Info.plist', - 'platforms/ios/' + name + '/Resources/Resources/GoogleService-Info.plist' + IOS_DIR + name + '/Resources/GoogleService-Info.plist', + IOS_DIR + name + '/Resources/Resources/GoogleService-Info.plist' ], src: [ 'GoogleService-Info.plist', - 'platforms/ios/www/GoogleService-Info.plist', + IOS_DIR + '/www/GoogleService-Info.plist', 'www/GoogleService-Info.plist' ] }, ANDROID: { - dest: ['platforms/android/google-services.json'], + dest: [ + ANDROID_DIR + '/google-services.json' + ], src: [ 'google-services.json', - 'platforms/android/assets/www/google-services.json', + ANDROID_DIR + '/assets/www/google-services.json', 'www/google-services.json' ], - stringsXml: 'platforms/android/res/values/strings.xml' + stringsXml: ANDROID_DIR + '/res/values/strings.xml' } }; // Copy key files to their platform specific folders -if (directoryExists('platforms/ios')) { - copyIosKey(); -} else if (directoryExists('platforms/android')) { - copyAndroidKey(); -} - -function copyIosKey() { +if (directoryExists(IOS_DIR)) { copyKey(PLATFORM.IOS); -} - -function copyAndroidKey() { +} else if (directoryExists(ANDROID_DIR)) { copyKey(PLATFORM.ANDROID, updateStringsXml) } @@ -108,8 +105,7 @@ function getValue(config, name) { function fileExists(path) { try { - return fse.statSync(path) - .isFile(); + return fse.statSync(path).isFile(); } catch (e) { return false; } @@ -117,9 +113,8 @@ function fileExists(path) { function directoryExists(path) { try { - return fse.statSync(path) - .isDirectory(); + return fse.statSync(path).isDirectory(); } catch (e) { return false; } -} +} \ No newline at end of file