Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new import/export commands #1384

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 10 additions & 3 deletions scripts/firebase-config.ts
Original file line number Diff line number Diff line change
@@ -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 };
9 changes: 9 additions & 0 deletions scripts/firestore-export.ts
Original file line number Diff line number Diff line change
@@ -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));