Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

auth-export.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const fs = require("fs");
  6. const os = require("os");
  7. const command_1 = require("../command");
  8. const logger_1 = require("../logger");
  9. const projectUtils_1 = require("../projectUtils");
  10. const requirePermissions_1 = require("../requirePermissions");
  11. const accountExporter_1 = require("../accountExporter");
  12. const MAX_BATCH_SIZE = 1000;
  13. exports.command = new command_1.Command("auth:export [dataFile]")
  14. .description("Export accounts from your Firebase project into a data file")
  15. .option("--format <format>", "Format of exported data (csv, json). Ignored if <dataFile> has format extension.")
  16. .before(requirePermissions_1.requirePermissions, ["firebaseauth.users.get"])
  17. .action((dataFile, options) => {
  18. const projectId = (0, projectUtils_1.needProjectId)(options);
  19. const checkRes = (0, accountExporter_1.validateOptions)(options, dataFile);
  20. if (!checkRes.format) {
  21. return checkRes;
  22. }
  23. const writeStream = fs.createWriteStream(dataFile);
  24. if (checkRes.format === "json") {
  25. writeStream.write('{"users": [' + os.EOL);
  26. }
  27. const exportOptions = {
  28. format: checkRes.format,
  29. writeStream,
  30. batchSize: MAX_BATCH_SIZE,
  31. };
  32. logger_1.logger.info("Exporting accounts to " + clc.bold(dataFile));
  33. return (0, accountExporter_1.serialExportUsers)(projectId, exportOptions).then(() => {
  34. if (exportOptions.format === "json") {
  35. writeStream.write("]}");
  36. }
  37. writeStream.end();
  38. return new Promise((resolve, reject) => {
  39. writeStream.on("finish", resolve);
  40. writeStream.on("close", resolve);
  41. writeStream.on("error", reject);
  42. });
  43. });
  44. });