Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Erik Guzman
Erik Guzman

Posted on • Originally published atnotion.so

     

Stream 11/13/19 - npx is pretty cool

Check Out the Stream @https://twitch.tv/talk2megooseman

Today Objective

✅ Work on a fork of

GitHub logo talk2MeGooseman / firestore-backup-restore

NPM package for backup and restore Firebase Firestore

firestore-export-import

GitHub versionBuild StatusDavid badge

NPM package for backup and restore Firebase Firestore

You can export and import data from firestore with sub collection.

Installation

Install usingnpm.

npm install firestore-export-import

Get Google Cloud Account Credentials from Firebase

You canGenerate New Private Key from Project Settings fromFirebase Console.

After that you need to copy thedatabaseURL for initiating the App.

Usage

You have to import this package in a JavaScript file and work from there.

Export data from firestore

You can export collection and sub collection from your data. The sub collection is optional.

// In your index.jsconstfirestoreService=require('firestore-export-import')constserviceAccount=require('./serviceAccountKey.json')// Initiate Firebase AppfirestoreService.initializeApp(serviceAccount, databaseURL)// Start exporting your datafirestoreService  .backup('collection-name','sub-collection-optional')  .then(data=>console.log
to experiment addingnpx support to it

Notes

NPX

During off stream time I was looking for a good way to export Firestore data that I have for a couple of my extension s so that I can import into any other DB service of my choice.

Unfortunately Firebase does not offer a clean export tool, instead, you can only export to their propriety format. BUT I ended finding an NPM package that someone wrote to export data to JSON:firestore-export-import

I was lazy and didn't want to spend time integrating this package into any project I have. So instead I got the crazy idea, "What if I made this npx compatible?" And here we are now.

So I forked the repo and start laying the groundwork for creatingnpx compatible version of this package.

I got alot of my inspiration of how to do this from the cowsay package:

GitHub logo piuccio / cowsay

cowsay is a configurable talking cow

cowsay

 __________________< srsly dude, why? &gt ------------------        \   ^__^         \  (oo)\_______            (__)\       )\/\                ||----w |                ||     ||

cowsay is a configurable talking cow, originally written in Perl byTony Monroe

This project is a translation in JavaScript of the original program and an attempt to bring the same silliness to node.js.

Install

npm install -g cowsay

Usage

cowsay JavaScript FTW

or

cowthink node.js is cool

It acts in the same way as the original cowsay, so consultcowsay(1) or runcowsay -h

 ________< indeed &gt --------    \     \                                   .::!!!!!!!:.  .!!!!!:.                        .:!!!!!!!!!!!!  ~~~~!!!!!!.                 .:!!!!!!!!!UWWW$$$      :$$NWX!!:           .:!!!!!!XUWW$$$$$$$$$P      $$$$$##WX!:      .<!!!!UW$$$$"  $$$$$$$$#      $$$$$  $$$UX   :!!UW$$$$$$$$$   4$$$$$*      ^$$$B  $$$$\     $$$$$$$$$$$$   d$$R"        "*$bd$$$$      '*$$$$$$$$$$$o+#"             """"          """""""

Usage as a module

cowsay can be used as any other npm dependency

var cowsay = require("cowsay");console.log(cowsay.say({    text : "I'm a moooodule",    e : "oO",    T : "U "}));// or cowsay.think()
 _________________( I'm a

After completing the work and getting the MVP done for import and export, next came refactor phase. One thing that I realized needed a refactoring was the usage ofoptimist

It has been deprecated for a long time so I wanted to look for a better alternative. Luckily ABuffSeagull came flying in and recommendedcommander

The end result is the it worked out great and I feel like the command and options structure feels a lot better.

Shoutouts and Thanks

ABuffSeagull

  • Thanks for recommending commander.js and an alternative to optimist cli packagecommander

Kodder

  • 2 month resub!

Booperinos

  • Thanks for the 18 months of sub love!

Future action items

⬜ Wrap up doing a pull request for firestore-backup-restore. But its a done MVP <3

GitHub logo talk2MeGooseman / firestore-backup-restore

NPM package for backup and restore Firebase Firestore

firestore-export-import

GitHub versionBuild StatusDavid badge

NPM package for backup and restore Firebase Firestore

You can export and import data from firestore with sub collection.

Installation

Install usingnpm.

npm install firestore-export-import

Get Google Cloud Account Credentials from Firebase

You canGenerate New Private Key from Project Settings fromFirebase Console.

After that you need to copy thedatabaseURL for initiating the App.

Usage

You have to import this package in a JavaScript file and work from there.

Export data from firestore

You can export collection and sub collection from your data. The sub collection is optional.

// In your index.jsconstfirestoreService=require('firestore-export-import')constserviceAccount=require('./serviceAccountKey.json')// Initiate Firebase AppfirestoreService.initializeApp(serviceAccount, databaseURL)// Start exporting your datafirestoreService  .backup('collection-name','sub-collection-optional')  .then(data=>console.log

Top comments(5)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
pavelloz profile image
Paweł Kowalski
Performance, JavaScript, Serverless, and Testing enthusiast.
  • Location
    Earth, Milky Way
  • Work
    Senior Performance Engineer at platformOS
  • Joined

I wish we used yargs instead of commander for our company cli tool. It has been problematic over the years and it seems like it wants to do too much making it harder to introduce new devs into the project.

CollapseExpand
 
talk2megooseman profile image
Erik Guzman
Developer, streamer, Microsoft MVP and Twitch dev contributer. I love to code and share the knowledge. Check me out at https://www.twitch.tv/talk2megooseman
  • Location
    San Diego
  • Work
    Full Stack Engineer at Coding Zeal
  • Joined

Oh interesting! I am still new to libraries to use to make a good CLI interface. What would you say are the best reason to use yargs? Ill take a look at it since I am making another npx script for another project. Thanks for commenting and suggesting it.

CollapseExpand
 
pavelloz profile image
Paweł Kowalski
Performance, JavaScript, Serverless, and Testing enthusiast.
  • Location
    Earth, Milky Way
  • Work
    Senior Performance Engineer at platformOS
  • Joined

The best reason to use yargs for me is that i had a lot of issues with commander and a lot of serious tools are written using yargs. It also looks lighter/simpler/more focused on args parsing, which is nice.

Thread Thread
 
talk2megooseman profile image
Erik Guzman
Developer, streamer, Microsoft MVP and Twitch dev contributer. I love to code and share the knowledge. Check me out at https://www.twitch.tv/talk2megooseman
  • Location
    San Diego
  • Work
    Full Stack Engineer at Coding Zeal
  • Joined

Thanks a lot for the suggestion, Ill be switching to yargs on a new npx project since I like the offerings over commander.

CollapseExpand
 
talk2megooseman profile image
Erik Guzman
Developer, streamer, Microsoft MVP and Twitch dev contributer. I love to code and share the knowledge. Check me out at https://www.twitch.tv/talk2megooseman
  • Location
    San Diego
  • Work
    Full Stack Engineer at Coding Zeal
  • Joined

Took a quick look at yargs and HOT DAMN it looks good. Importing a directory full of command modules? Yes, please. Thanks for telling me about this.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Developer, streamer, Microsoft MVP and Twitch dev contributer. I love to code and share the knowledge. Check me out at https://www.twitch.tv/talk2megooseman
  • Location
    San Diego
  • Work
    Full Stack Engineer at Coding Zeal
  • Joined

More fromErik Guzman

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp