Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh Singh committed Jan 18, 2018
2 parents 622870b + eb7e2fe commit be12104
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"standard"
],
"env": {
"es6": true
"es6": true,
"node": true
},
"plugins": [
"flowtype"
Expand Down
3 changes: 3 additions & 0 deletions bin/firestore-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const prettyPrint = commander[prettyPrintParamKey] !== undefined && commander[pr
var firestoreBackup = require('../dist/index.js')
try {
firestoreBackup.default(accountCredentialsPath, backupPath, prettyPrint)
.then(() => {
console.log(colors.bold(colors.green('All done 💫')))
})
} catch (error) {
console.log(colors.red(error))
process.exit(1)
Expand Down
22 changes: 13 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ exports.default = function (accountCredentials, backupPath, prettyPrintJSON) {
throw new Error('Unable to create backup path for Collection \'' + collection.id + '\': ' + error);
}

return collection.get().then(function (snapshots) {
return collection.get().then(function (documentSnapshots) {
var backupFunctions = [];
snapshots.forEach(function (document) {
documentSnapshots.forEach(function (document) {
backupFunctions.push(function () {
return backupDocument(document, backupPath + '/' + document.id, logPath + collection.id + '/');
});
Expand All @@ -216,6 +216,16 @@ exports.default = function (accountCredentials, backupPath, prettyPrintJSON) {
});
};

var backupRootCollections = function backupRootCollections(database) {
return database.getCollections().then(function (collections) {
return promiseSerial(collections.map(function (collection) {
return function () {
return backupCollection(collection, backupPath + '/' + collection.id, '/');
};
}));
});
};

var accountCredentialsContents = void 0;
if (typeof accountCredentials === 'string') {
try {
Expand All @@ -241,13 +251,7 @@ exports.default = function (accountCredentials, backupPath, prettyPrintJSON) {
}

var database = _firebaseAdmin2.default.firestore();
database.getCollections().then(function (collections) {
return promiseSerial(collections.map(function (collection) {
return function () {
return backupCollection(collection, backupPath + '/' + collection.id, '/');
};
}));
});
return backupRootCollections(database);
};

var _firebaseAdmin = require('firebase-admin');
Expand Down
28 changes: 16 additions & 12 deletions dist/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function (accountCredentials: string | Object, backupPath: string
}, Promise.resolve([]))
}

const backupDocument = (document: Object, backupPath: string, logPath: string): Promise<void> => {
const backupDocument = (document: Object, backupPath: string, logPath: string) => {
console.log('Backing up Document \'' + logPath + document.id + '\'')
try {
mkdirp.sync(backupPath)
Expand Down Expand Up @@ -192,7 +192,7 @@ export default function (accountCredentials: string | Object, backupPath: string
})
}

const backupCollection = (collection: Object, backupPath: string, logPath: string): Promise<void> => {
const backupCollection = (collection: Object, backupPath: string, logPath: string) => {
console.log('Backing up Collection \'' + logPath + collection.id + '\'')
try {
mkdirp.sync(backupPath)
Expand All @@ -201,9 +201,9 @@ export default function (accountCredentials: string | Object, backupPath: string
}

return collection.get()
.then((snapshots) => {
.then((documentSnapshots) => {
const backupFunctions = []
snapshots.forEach((document) => {
documentSnapshots.forEach((document) => {
backupFunctions.push(() => {
return backupDocument(document, backupPath + '/' + document.id, logPath + collection.id + '/')
})
Expand All @@ -212,6 +212,17 @@ export default function (accountCredentials: string | Object, backupPath: string
})
}

const backupRootCollections = (database: Object) => {
return database.getCollections()
.then((collections) => {
return promiseSerial(collections.map((collection) => {
return () => {
return backupCollection(collection, backupPath + '/' + collection.id, '/')
}
}))
})
}

let accountCredentialsContents: Object
if (typeof accountCredentials === 'string') {
try {
Expand All @@ -237,12 +248,5 @@ export default function (accountCredentials: string | Object, backupPath: string
}

const database = Firebase.firestore()
database.getCollections()
.then((collections) => {
return promiseSerial(collections.map((collection) => {
return () => {
return backupCollection(collection, backupPath + '/' + collection.id, '/')
}
}))
})
return backupRootCollections(database)
}
28 changes: 16 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function (accountCredentials: string | Object, backupPath: string
}, Promise.resolve([]))
}

const backupDocument = (document: Object, backupPath: string, logPath: string): Promise<void> => {
const backupDocument = (document: Object, backupPath: string, logPath: string) => {
console.log('Backing up Document \'' + logPath + document.id + '\'')
try {
mkdirp.sync(backupPath)
Expand Down Expand Up @@ -192,7 +192,7 @@ export default function (accountCredentials: string | Object, backupPath: string
})
}

const backupCollection = (collection: Object, backupPath: string, logPath: string): Promise<void> => {
const backupCollection = (collection: Object, backupPath: string, logPath: string) => {
console.log('Backing up Collection \'' + logPath + collection.id + '\'')
try {
mkdirp.sync(backupPath)
Expand All @@ -201,9 +201,9 @@ export default function (accountCredentials: string | Object, backupPath: string
}

return collection.get()
.then((snapshots) => {
.then((documentSnapshots) => {
const backupFunctions = []
snapshots.forEach((document) => {
documentSnapshots.forEach((document) => {
backupFunctions.push(() => {
return backupDocument(document, backupPath + '/' + document.id, logPath + collection.id + '/')
})
Expand All @@ -212,6 +212,17 @@ export default function (accountCredentials: string | Object, backupPath: string
})
}

const backupRootCollections = (database: Object) => {
return database.getCollections()
.then((collections) => {
return promiseSerial(collections.map((collection) => {
return () => {
return backupCollection(collection, backupPath + '/' + collection.id, '/')
}
}))
})
}

let accountCredentialsContents: Object
if (typeof accountCredentials === 'string') {
try {
Expand All @@ -237,12 +248,5 @@ export default function (accountCredentials: string | Object, backupPath: string
}

const database = Firebase.firestore()
database.getCollections()
.then((collections) => {
return promiseSerial(collections.map((collection) => {
return () => {
return backupCollection(collection, backupPath + '/' + collection.id, '/')
}
}))
})
return backupRootCollections(database)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firestore-backup",
"version": "1.2.0",
"version": "1.2.1",
"description": "Google Firebase Firestore backup tool",
"homepage": "https://github.com/steadyequipment/node-firestore-backup",
"repository": "https://github.com/steadyequipment/node-firestore-backup.git",
Expand Down

0 comments on commit be12104

Please sign in to comment.