From e20dac2b4d679dd6f10797e593da300c56d630da Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 4 May 2018 10:17:32 +0200 Subject: [PATCH] Some others format fixes. --- bump-version.js | 2 +- scripts/after_prepare.js | 282 +++++++++++++++++++-------------------- 2 files changed, 142 insertions(+), 142 deletions(-) diff --git a/bump-version.js b/bump-version.js index 449b9b98c..8e4d075f0 100644 --- a/bump-version.js +++ b/bump-version.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -var fs = require('fs'); +const fs = require('fs'); const version = require('./package.json').version; let data = fs.readFileSync('./plugin.xml', "utf8"); diff --git a/scripts/after_prepare.js b/scripts/after_prepare.js index 199042f8f..e295cc5b1 100755 --- a/scripts/after_prepare.js +++ b/scripts/after_prepare.js @@ -1,141 +1,141 @@ -#!/usr/bin/env node -'use strict'; - -/** - * This hook makes sure projects using [cordova-plugin-firebase](https://github.com/arnesson/cordova-plugin-firebase) - * will build properly and have the required key files copied to the proper destinations when the app is build on Ionic Cloud using the package command. - * Credits: https://github.com/arnesson. - */ -var fs = require('fs'); -var path = require('path'); - -fs.ensureDirSync = function (dir) { - if (!fs.existsSync(dir)) { - dir.split(path.sep).reduce(function (currentPath, folder) { - currentPath += folder + path.sep; - if (!fs.existsSync(currentPath)) { - fs.mkdirSync(currentPath); - } - return currentPath; - }, ''); - } -}; - -var config = fs.readFileSync('config.xml').toString(); -var name = getValue(config, 'name'); - -var IOS_DIR = 'platforms/ios'; -var ANDROID_DIR = 'platforms/android'; - -var PLATFORM = { - IOS: { - dest: [ - IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist', - IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist' - ], - src: [ - 'GoogleService-Info.plist', - IOS_DIR + '/www/GoogleService-Info.plist', - 'www/GoogleService-Info.plist' - ] - }, - ANDROID: { - dest: [ - ANDROID_DIR + '/google-services.json' - ], - src: [ - 'google-services.json', - ANDROID_DIR + '/assets/www/google-services.json', - 'www/google-services.json' - ], - stringsXml: fileExists(ANDROID_DIR + '/app/src/main/res/values/strings.xml') ? ANDROID_DIR + '/app/src/main/res/values/strings.xml' : ANDROID_DIR + '/res/values/strings.xml' - } -}; - -function updateStringsXml(contents) { - var json = JSON.parse(contents); - var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString(); - - // strip non-default value - strings = strings.replace(new RegExp('([^\@<]+?)', 'i'), ''); - - // strip non-default value - strings = strings.replace(new RegExp('([^\@<]+?)', 'i'), ''); - - // strip empty lines - strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1'); - - // replace the default value - strings = strings.replace(new RegExp('([^<]+?)', 'i'), '' + json.client[0].client_info.mobilesdk_app_id + ''); - - // replace the default value - strings = strings.replace(new RegExp('([^<]+?)', 'i'), '' + json.client[0].api_key[0].current_key + ''); - - fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings); -} - -function copyKey(platform, callback) { - for (var i = 0; i < platform.src.length; i++) { - var file = platform.src[i]; - if (fileExists(file)) { - try { - var contents = fs.readFileSync(file).toString(); - - try { - platform.dest.forEach(function (destinationPath) { - var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/')); - fs.ensureDirSync(folder); - fs.writeFileSync(destinationPath, contents); - }); - } catch (e) { - // skip - } - - callback && callback(contents); - } catch (err) { - console.log(err) - } - - break; - } - } -} - -function getValue(config, name) { - var value = config.match(new RegExp('<' + name + '>(.*?)', 'i')); - if (value && value[1]) { - return value[1] - } else { - return null - } -} - -function fileExists(path) { - try { - return fs.statSync(path).isFile(); - } catch (e) { - return false; - } -} - -function directoryExists(path) { - try { - return fs.statSync(path).isDirectory(); - } catch (e) { - return false; - } -} - -module.exports = function(context) { - //get platform from the context supplied by cordova - var platforms = context.opts.platforms; - // Copy key files to their platform specific folders - if (platforms.indexOf('ios') !== -1 && directoryExists(IOS_DIR)) { - console.log('Preparing Firebase on iOS'); - copyKey(PLATFORM.IOS); - } - if (platforms.indexOf('android') !== -1 && directoryExists(ANDROID_DIR)) { - console.log('Preparing Firebase on Android'); - copyKey(PLATFORM.ANDROID, updateStringsXml) - } -}; \ No newline at end of file +#!/usr/bin/env node +'use strict'; + +/** + * This hook makes sure projects using [cordova-plugin-firebase](https://github.com/arnesson/cordova-plugin-firebase) + * will build properly and have the required key files copied to the proper destinations when the app is build on Ionic Cloud using the package command. + * Credits: https://github.com/arnesson. + */ +var fs = require('fs'); +var path = require('path'); + +fs.ensureDirSync = function (dir) { + if (!fs.existsSync(dir)) { + dir.split(path.sep).reduce(function (currentPath, folder) { + currentPath += folder + path.sep; + if (!fs.existsSync(currentPath)) { + fs.mkdirSync(currentPath); + } + return currentPath; + }, ''); + } +}; + +var config = fs.readFileSync('config.xml').toString(); +var name = getValue(config, 'name'); + +var IOS_DIR = 'platforms/ios'; +var ANDROID_DIR = 'platforms/android'; + +var PLATFORM = { + IOS: { + dest: [ + IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist', + IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist' + ], + src: [ + 'GoogleService-Info.plist', + IOS_DIR + '/www/GoogleService-Info.plist', + 'www/GoogleService-Info.plist' + ] + }, + ANDROID: { + dest: [ + ANDROID_DIR + '/google-services.json' + ], + src: [ + 'google-services.json', + ANDROID_DIR + '/assets/www/google-services.json', + 'www/google-services.json' + ], + stringsXml: fileExists(ANDROID_DIR + '/app/src/main/res/values/strings.xml') ? ANDROID_DIR + '/app/src/main/res/values/strings.xml' : ANDROID_DIR + '/res/values/strings.xml' + } +}; + +function updateStringsXml(contents) { + var json = JSON.parse(contents); + var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString(); + + // strip non-default value + strings = strings.replace(new RegExp('([^\@<]+?)', 'i'), ''); + + // strip non-default value + strings = strings.replace(new RegExp('([^\@<]+?)', 'i'), ''); + + // strip empty lines + strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1'); + + // replace the default value + strings = strings.replace(new RegExp('([^<]+?)', 'i'), '' + json.client[0].client_info.mobilesdk_app_id + ''); + + // replace the default value + strings = strings.replace(new RegExp('([^<]+?)', 'i'), '' + json.client[0].api_key[0].current_key + ''); + + fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings); +} + +function copyKey(platform, callback) { + for (var i = 0; i < platform.src.length; i++) { + var file = platform.src[i]; + if (fileExists(file)) { + try { + var contents = fs.readFileSync(file).toString(); + + try { + platform.dest.forEach(function (destinationPath) { + var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/')); + fs.ensureDirSync(folder); + fs.writeFileSync(destinationPath, contents); + }); + } catch (e) { + // skip + } + + callback && callback(contents); + } catch (err) { + console.log(err) + } + + break; + } + } +} + +function getValue(config, name) { + var value = config.match(new RegExp('<' + name + '>(.*?)', 'i')); + if (value && value[1]) { + return value[1] + } else { + return null + } +} + +function fileExists(path) { + try { + return fs.statSync(path).isFile(); + } catch (e) { + return false; + } +} + +function directoryExists(path) { + try { + return fs.statSync(path).isDirectory(); + } catch (e) { + return false; + } +} + +module.exports = function(context) { + //get platform from the context supplied by cordova + var platforms = context.opts.platforms; + // Copy key files to their platform specific folders + if (platforms.indexOf('ios') !== -1 && directoryExists(IOS_DIR)) { + console.log('Preparing Firebase on iOS'); + copyKey(PLATFORM.IOS); + } + if (platforms.indexOf('android') !== -1 && directoryExists(ANDROID_DIR)) { + console.log('Preparing Firebase on Android'); + copyKey(PLATFORM.ANDROID, updateStringsXml) + } +};