-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_remote_config.js
More file actions
117 lines (97 loc) · 3.59 KB
/
deploy_remote_config.js
File metadata and controls
117 lines (97 loc) · 3.59 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
/**
* Firebase Remote Config Deployment Script (Node.js)
* Amazon Rewards ve Points sistemi için Remote Config parametrelerini yükler
*/
const admin = require('firebase-admin');
const fs = require('fs');
const path = require('path');
// Firebase Admin SDK başlat
async function initializeFirebase() {
try {
// Service account key dosyası var mı kontrol et
const serviceAccountPath = path.join(__dirname, 'firebase-service-account.json');
if (fs.existsSync(serviceAccountPath)) {
const serviceAccount = require(serviceAccountPath);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
console.log('✅ Firebase Admin SDK başlatıldı (Service Account)');
} else {
// Application Default Credentials kullan (gcloud veya Firebase CLI ile login)
admin.initializeApp();
console.log('✅ Firebase Admin SDK başlatıldı (Application Default Credentials)');
}
return true;
} catch (error) {
console.error('❌ Firebase Admin SDK başlatılamadı:', error.message);
console.log('\n💡 Çözüm:');
console.log(' 1. Firebase CLI ile login: firebase login');
console.log(' 2. Veya service account key ekle: firebase-service-account.json');
return false;
}
}
// Remote Config'i yükle
async function deployRemoteConfig(configPath) {
try {
// Config dosyasını oku
const configJson = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configJson);
// Remote Config template oluştur
const remoteConfig = admin.remoteConfig();
const template = remoteConfig.createTemplateFromJSON(configJson);
// Template'i yükle
console.log('📤 Remote Config yükleniyor...');
const updatedTemplate = await remoteConfig.publishTemplate(template);
console.log('✅ Remote Config başarıyla yüklendi!');
console.log(` Version: ${updatedTemplate.version.versionNumber}`);
console.log(` Update Time: ${updatedTemplate.version.updateTime}`);
return true;
} catch (error) {
console.error('❌ Remote Config yüklenemedi:', error.message);
if (error.code === 'permission-denied') {
console.log('\n💡 Çözüm:');
console.log(' Firebase projesine yazma yetkisine sahip olduğunuzdan emin olun');
console.log(' firebase login --reauth');
}
return false;
}
}
// Ana fonksiyon
async function main() {
console.log('🚀 Firebase Remote Config Deployment (Node.js)');
console.log('='.repeat(50));
console.log();
// Config dosyası yolu
const configPath = path.join(__dirname, 'remote_config_merged.json');
if (!fs.existsSync(configPath)) {
console.error(`❌ Config dosyası bulunamadı: ${configPath}`);
console.log(' Önce deploy_remote_config.py scriptini çalıştırın');
process.exit(1);
}
// Firebase'i başlat
const initialized = await initializeFirebase();
if (!initialized) {
process.exit(1);
}
console.log();
// Remote Config'i yükle
const deployed = await deployRemoteConfig(configPath);
if (deployed) {
console.log();
console.log('='.repeat(50));
console.log('🎉 Tamamlandı!');
console.log();
console.log('📋 Sonraki Adımlar:');
console.log(' 1. Firebase Console → Remote Config');
console.log(' 2. Yeni parametreleri kontrol edin');
console.log(' 3. Değişiklikler 1 saat içinde uygulamaya yansıyacak');
} else {
process.exit(1);
}
}
// Script'i çalıştır
main().catch((error) => {
console.error('❌ Beklenmeyen hata:', error);
process.exit(1);
});