diff --git a/package-lock.json b/package-lock.json index 3dfe097347..65fe8b17dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14188,6 +14188,15 @@ } } }, + "firestore-export-import": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/firestore-export-import/-/firestore-export-import-0.8.0.tgz", + "integrity": "sha512-pYIouhcOWbQv5MEZ4EOrUizC2ZZ8Idqeh3eGuPnnBam9NCqJ+7WcPU4WkeFv51gznCaNx8TRFftEabOD2WDA4Q==", + "dev": true, + "requires": { + "firebase-admin": "^9.2.0" + } + }, "flat-arguments": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/flat-arguments/-/flat-arguments-1.0.2.tgz", diff --git a/package.json b/package.json index d045851589..4cb2f2778d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "clean": "rimraf dist out-tsc", "deploy": "npm run build && NODE_ENV=production firebase deploy", "firestore:copy": "ts-node-script ./scripts/firestore-copy", + "firestore:export": "ts-node-script ./scripts/firestore-export", "firestore:init": "firebase functions:config:set schedule.enabled=true && firebase deploy --except hosting && ts-node-script ./scripts/firestore-copy", "fix": "concurrently npm:fix:*", "fix:eslint": "eslint . --ext .ts --ext .js --fix", @@ -93,6 +94,7 @@ "eslint-plugin-testing-library": "^3.9.0", "firebase-admin": "^9.2.0", "firebase-tools": "^8.11.2", + "firestore-export-import": "^0.8.0", "jest": "^26.4.2", "jest-dev-server": "^4.4.0", "jest-runner-eslint": "^0.10.0", diff --git a/scripts/firebase-config.ts b/scripts/firebase-config.ts index 44b4301053..7a383bb4c9 100644 --- a/scripts/firebase-config.ts +++ b/scripts/firebase-config.ts @@ -1,8 +1,15 @@ import admin, { ServiceAccount } from 'firebase-admin'; -import serviceAccount from '../serviceAccount.json'; +import firestoreService from 'firestore-export-import'; +import serviceAccountJson from '../serviceAccount.json'; -const credential = admin.credential.cert(serviceAccount as ServiceAccount); +// TODO: replace +const databaseURL = 'https://hoverboard-dev.firebaseio.com'; +const serviceAccount = serviceAccountJson as ServiceAccount; +const credential = admin.credential.cert(serviceAccount); admin.initializeApp({ credential }); const firestore = admin.firestore(); +firestoreService.initializeApp(serviceAccount as string, databaseURL); -export { firestore }; +console.log(databaseURL); + +export { firestore, firestoreService }; diff --git a/scripts/firestore-export.ts b/scripts/firestore-export.ts new file mode 100644 index 0000000000..8fa1b4bece --- /dev/null +++ b/scripts/firestore-export.ts @@ -0,0 +1,9 @@ +import { firestoreService } from './firebase-config'; + +// const [, , fileName] = process.argv; + +firestoreService + .backup('team') + .then((data) => console.log(JSON.stringify(data))) + .then(() => console.log('Success! 🔥')) + .catch((error: Error) => console.log('Error! 💩', error));