diff --git a/copy_google_services_config_files.js b/copy_google_services_config_files.js index 1c62972..566315c 100644 --- a/copy_google_services_config_files.js +++ b/copy_google_services_config_files.js @@ -6,8 +6,22 @@ * 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 fse = require('fs-extra'); -var config = fse.readFileSync('config.xml').toString(); +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'; @@ -16,8 +30,8 @@ var ANDROID_DIR = 'platforms/android'; var PLATFORM = { IOS: { dest: [ - IOS_DIR + name + '/Resources/GoogleService-Info.plist', - IOS_DIR + 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', @@ -41,13 +55,14 @@ var PLATFORM = { // Copy key files to their platform specific folders if (directoryExists(IOS_DIR)) { copyKey(PLATFORM.IOS); -} else if (directoryExists(ANDROID_DIR)) { +} +if (directoryExists(ANDROID_DIR)) { copyKey(PLATFORM.ANDROID, updateStringsXml) } function updateStringsXml(contents) { var json = JSON.parse(contents); - var strings = fse.readFileSync(PLATFORM.ANDROID.stringsXml).toString(); + var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString(); // strip non-default value strings = strings.replace(new RegExp('([^\@<]+?)', 'i'), ''); @@ -64,7 +79,7 @@ function updateStringsXml(contents) { // replace the default value strings = strings.replace(new RegExp('([^<]+?)', 'i'), '' + json.client[0].api_key[0].current_key + ''); - fse.writeFileSync(PLATFORM.ANDROID.stringsXml, strings); + fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings); } function copyKey(platform, callback) { @@ -72,13 +87,13 @@ function copyKey(platform, callback) { var file = platform.src[i]; if (fileExists(file)) { try { - var contents = fse.readFileSync(file).toString(); + var contents = fs.readFileSync(file).toString(); try { platform.dest.forEach(function (destinationPath) { var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/')); - fse.ensureDirSync(folder); - fse.writeFileSync(destinationPath, contents); + fs.ensureDirSync(folder); + fs.writeFileSync(destinationPath, contents); }); } catch (e) { // skip @@ -105,7 +120,7 @@ function getValue(config, name) { function fileExists(path) { try { - return fse.statSync(path).isFile(); + return fs.statSync(path).isFile(); } catch (e) { return false; } @@ -113,7 +128,7 @@ function fileExists(path) { function directoryExists(path) { try { - return fse.statSync(path).isDirectory(); + return fs.statSync(path).isDirectory(); } catch (e) { return false; } diff --git a/package.json b/package.json index 266b331..029e105 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ }, "homepage": "https://github.com/ionic-team/ionic-package-hooks#readme", "dependencies": { - "xcode": "^0.8.2", - "fs-extra": "3.0.1" + "xcode": "^0.8.2" } }