steadyequipment / node-firestore-backup

Google Firebase Firestore backup tool
190 stars 51 forks source link

sorting the keys before writing documents to file #22

Closed chaoranxie closed 6 years ago

chaoranxie commented 6 years ago

is there any way to sort the keys before writing the documents to file? Basically, I am committing the backup files to version control but every time I do a new backup it shows all the documents are changed.

From what I can tell, you might need to update this line https://github.com/steadyequipment/node-firestore-backup/blob/master/dist/firestore.js.flow#L117 to use something like https://www.npmjs.com/package/json-stable-stringify though I have not use the package myself and don't know if it is as simple as change one line of code.

Thanks

chaoranxie commented 6 years ago

I tested the following code which seems to be what's needed

var stringify = require('json-stable-stringify');
fileContents = stringify(documentDataToStore, { space: 2 });
yoiang commented 6 years ago

Great idea!