-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_remote_config_bulk.js
More file actions
199 lines (170 loc) · 6.88 KB
/
deploy_remote_config_bulk.js
File metadata and controls
199 lines (170 loc) · 6.88 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env node
/**
* Firebase Remote Config Bulk Deployment Script
* Tüm parametreleri tek seferde yükler (REST API kullanarak)
*/
const admin = require('firebase-admin');
const fs = require('fs');
const path = require('path');
// Firebase Admin SDK başlat
async function initializeFirebase() {
try {
// Project ID'yi .firebaserc'den oku
const firebasercPath = path.join(__dirname, '..', '.firebaserc');
let projectId = null;
if (fs.existsSync(firebasercPath)) {
const firebaserc = JSON.parse(fs.readFileSync(firebasercPath, 'utf8'));
const projects = firebaserc.projects || {};
projectId = projects.default || projects.production || Object.values(projects)[0];
}
if (!projectId) {
console.error('❌ Project ID bulunamadı. .firebaserc dosyasını kontrol edin.');
return false;
}
// Application Default Credentials kullan
try {
admin.initializeApp({
projectId: projectId,
});
console.log(`✅ Firebase Admin SDK başlatıldı (Project ID: ${projectId})`);
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. Application Default Credentials ayarla:');
console.log(' gcloud auth application-default login');
console.log(' 3. Veya service account key kullan');
return false;
}
} catch (error) {
console.error('❌ Hata:', error.message);
return false;
}
}
// Remote Config'i toplu yükle
async function deployRemoteConfigBulk(configPath) {
try {
const remoteConfig = admin.remoteConfig();
// Mevcut template'i al
console.log('📥 Mevcut Remote Config template alınıyor...');
let template;
try {
template = await remoteConfig.getTemplate();
console.log('✅ Mevcut template alındı');
console.log(` Mevcut parametre sayısı: ${Object.keys(template.parameters || {}).length}`);
} catch (error) {
console.error('❌ Mevcut template alınamadı:', error.message);
console.log('\n💡 Çözüm:');
console.log(' Firebase Console → Remote Config');
console.log(' En az bir parametre manuel olarak ekleyin (ör: test_param)');
console.log(' Sonra tekrar çalıştırın');
return false;
}
// Yeni config'i oku
console.log('\n📖 Yeni config dosyası okunuyor...');
const configJson = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configJson);
const newParameters = config.parameters || {};
console.log(` Yeni parametre sayısı: ${Object.keys(newParameters).length}`);
// Parametreleri birleştir
console.log('\n🔀 Parametreler birleştiriliyor...');
let addedCount = 0;
let updatedCount = 0;
for (const [key, paramConfig] of Object.entries(newParameters)) {
const defaultValue = paramConfig.defaultValue?.value;
const valueType = paramConfig.valueType || 'STRING';
const description = paramConfig.description || '';
if (!defaultValue && defaultValue !== '0' && defaultValue !== '') {
console.log(`⚠️ Parametre atlandı (defaultValue yok): ${key}`);
continue;
}
// Parametreyi ekle veya güncelle
if (template.parameters[key]) {
template.parameters[key].defaultValue = { value: String(defaultValue) };
template.parameters[key].valueType = valueType;
if (description) template.parameters[key].description = description;
updatedCount++;
} else {
template.parameters[key] = {
defaultValue: { value: String(defaultValue) },
valueType: valueType,
};
if (description) {
template.parameters[key].description = description;
}
addedCount++;
}
}
console.log(`✅ ${addedCount} yeni parametre eklendi`);
console.log(`✅ ${updatedCount} parametre güncellendi`);
console.log(`📊 Toplam parametre sayısı: ${Object.keys(template.parameters).length}`);
// Template'i yükle
console.log('\n📤 Remote Config yükleniyor...');
const updatedTemplate = await remoteConfig.publishTemplate(template);
console.log('\n✅ Remote Config başarıyla yüklendi!');
console.log(` Version: ${updatedTemplate.version.versionNumber}`);
console.log(` Update Time: ${updatedTemplate.version.updateTime}`);
console.log(` Description: ${updatedTemplate.version.description || 'N/A'}`);
return true;
} catch (error) {
console.error('\n❌ Remote Config yüklenemedi:', error.message);
if (error.code === 'permission-denied' || error.codePrefix === 'remote-config') {
console.log('\n💡 Çözüm:');
console.log(' 1. Firebase projesine yazma yetkisine sahip olduğunuzdan emin olun');
console.log(' 2. firebase login --reauth');
console.log(' 3. gcloud auth application-default login');
}
if (error.message.includes('ETag')) {
console.log('\n💡 ETag hatası:');
console.log(' Mevcut template alınamadı. Firebase Console\'dan en az bir parametre ekleyin.');
}
return false;
}
}
// Ana fonksiyon
async function main() {
console.log('🚀 Firebase Remote Config Bulk Deployment');
console.log('='.repeat(60));
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 deployRemoteConfigBulk(configPath);
if (deployed) {
console.log();
console.log('='.repeat(60));
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. "Publish changes" butonuna tıklayın (gerekirse)');
console.log(' 4. Değişiklikler 1 saat içinde uygulamaya yansıyacak');
console.log();
} else {
console.log();
console.log('💡 Alternatif Yöntem:');
console.log(' Firebase Console → Remote Config');
console.log(' "Import from file" özelliğini kullanın (varsa)');
console.log(' Veya remote_config_merged.json dosyasındaki parametreleri');
console.log(' toplu olarak eklemek için Firebase Console API kullanın');
process.exit(1);
}
}
// Script'i çalıştır
main().catch((error) => {
console.error('\n❌ Beklenmeyen hata:', error);
process.exit(1);
});