-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase-environment-generator.js
64 lines (64 loc) · 2.42 KB
/
firebase-environment-generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
exports.__esModule = true;
var fs = require("fs");
var path = require("path");
//DON'T MODIFY THOSE FILENAMES
var firebaseEnvAndroidFile = 'google-services';
var firebaseEnvIOSFile = 'GoogleService-Info';
//Helper function to get right fileName for iOS file
function getIOSEnvFile(env) {
if (env === 'main') {
return firebaseEnvIOSFile + ".plist";
}
else {
return firebaseEnvIOSFile + "-" + env + ".plist";
}
}
//Helper function to get right fileName for Android file
function getAndroidEnvFile(env) {
if (env === 'main') {
return firebaseEnvAndroidFile + ".json";
}
else {
return firebaseEnvAndroidFile + "-" + env + ".json";
}
}
function generateRightFirebaseEnvironmentFile(environment) {
console.log("*********************************************");
console.log("Generating firebase environment files. Environment: " + environment);
//Defining paths.
//Given `firebase-environment-generator.ts` is stored in `../projectName/tools/firebase-environment-generator`
var androidPath = path.join(__dirname, '..', '..', 'android', 'app');
var iosPath = path.join(__dirname, '..', '..', 'ios', 'Runner');
var androidEnvFile = getAndroidEnvFile(environment);
var androidMainFile = getAndroidEnvFile('main');
fs.copyFile("" + androidEnvFile, androidPath + "/" + androidMainFile, function (e) {
if (e === null) {
console.log(androidEnvFile + " file copied successfully.");
}
else {
console.log("Error while copying " + androidEnvFile + " file: " + e);
}
});
var IOSEnvFile = getIOSEnvFile(environment);
var IOSMainFile = getIOSEnvFile('main');
fs.copyFile("" + IOSEnvFile, iosPath + "/" + IOSMainFile, function (e) {
if (e === null) {
console.log(IOSEnvFile + " file copied successfully.");
}
else {
console.log("Error while copying " + IOSEnvFile + " file: " + e);
}
});
}
//Once file is running, it will execute [copyRightEnvironmentFile] function with given arguments
function generateEnvironmentFiles(environment) {
//If environment match, execute copying script
if (environment === 'prod' || environment === 'dev') {
generateRightFirebaseEnvironmentFile(environment);
}
}
//Example `node firebase-environment-generator.js prod`
process.argv.forEach(function (val, index, array) {
generateEnvironmentFiles(val);
});