-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.js
More file actions
25 lines (20 loc) · 845 Bytes
/
export.js
File metadata and controls
25 lines (20 loc) · 845 Bytes
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
/**
* Script to import-export collections accross firestore of firebase projects.
*
* - Mainly used in @italanta projects for moving translation files
*
* @see https://github.com/dalenguyen/firestore-backup-restore
*/
const { initializeApp, backup } = require('firestore-export-import');
const fs = require('fs');
// env type :: { sourcEnv: string (read from); targetEnv: string (send too); store?: boolean (store copy on disk) }
const env = require('./environments/environment.js');
const serviceAccount = require('./environments/source-key.json');
// Initiate Firebase App
initializeApp(serviceAccount);
// Export file
backup(env.sourceCollectionName).then((data) => {
const fileName = `output/${new Date().getTime()}_${env.sourceEnvName}.json`;
fs.writeFileSync(fileName, JSON.stringify(data));
console.log('Success!');
});