Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. const program = require("commander");
  3. const clc = require("colorette");
  4. const leven = require("leven");
  5. const logger_1 = require("./logger");
  6. const utils_1 = require("./utils");
  7. const pkg = require("../package.json");
  8. program.version(pkg.version);
  9. program.option("-P, --project <alias_or_project_id>", "the Firebase project to use for this command");
  10. program.option("--account <email>", "the Google account to use for authorization");
  11. program.option("-j, --json", "output JSON instead of text, also triggers non-interactive mode");
  12. program.option("--token <token>", "DEPRECATED - will be removed in a future major version - supply an auth token for this command");
  13. program.option("--non-interactive", "error out of the command instead of waiting for prompts");
  14. program.option("-i, --interactive", "force prompts to be displayed");
  15. program.option("--debug", "print verbose debug output and keep a debug log file");
  16. program.option("-c, --config <path>", "path to the firebase.json file to use for configuration");
  17. const client = {
  18. cli: program,
  19. logger: require("./logger"),
  20. errorOut: require("./errorOut").errorOut,
  21. getCommand: (name) => {
  22. for (let i = 0; i < client.cli.commands.length; i++) {
  23. if (client.cli.commands[i]._name === name) {
  24. return client.cli.commands[i];
  25. }
  26. }
  27. return;
  28. },
  29. };
  30. require("./commands").load(client);
  31. function suggestCommands(cmd, cmdList) {
  32. const suggestion = cmdList.find((c) => {
  33. return leven(c, cmd) < c.length * 0.4;
  34. });
  35. if (suggestion) {
  36. logger_1.logger.error();
  37. logger_1.logger.error("Did you mean " + clc.bold(suggestion) + "?");
  38. return suggestion;
  39. }
  40. }
  41. const commandNames = program.commands.map((cmd) => {
  42. return cmd._name;
  43. });
  44. const RENAMED_COMMANDS = {
  45. "delete-site": "hosting:disable",
  46. "disable:hosting": "hosting:disable",
  47. "data:get": "database:get",
  48. "data:push": "database:push",
  49. "data:remove": "database:remove",
  50. "data:set": "database:set",
  51. "data:update": "database:update",
  52. "deploy:hosting": "deploy --only hosting",
  53. "deploy:database": "deploy --only database",
  54. "prefs:token": "login:ci",
  55. };
  56. program.action((_, args) => {
  57. (0, utils_1.setupLoggers)();
  58. const cmd = args[0];
  59. logger_1.logger.error(clc.bold(clc.red("Error:")), clc.bold(cmd), "is not a Firebase command");
  60. if (RENAMED_COMMANDS[cmd]) {
  61. logger_1.logger.error();
  62. logger_1.logger.error(clc.bold(cmd) + " has been renamed, please run", clc.bold("firebase " + RENAMED_COMMANDS[cmd]), "instead");
  63. }
  64. else {
  65. if (!suggestCommands(cmd, commandNames)) {
  66. suggestCommands(args.join(":"), commandNames);
  67. }
  68. }
  69. process.exit(1);
  70. });
  71. module.exports = client;