index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const envinfo_1 = __importDefault(require("envinfo"));
  7. class InfoCommand {
  8. async apply(cli) {
  9. await cli.makeCommand({
  10. name: "info",
  11. alias: "i",
  12. description: "Outputs information about your system.",
  13. usage: "[options]",
  14. pkg: "@webpack-cli/info",
  15. }, [
  16. {
  17. name: "output",
  18. alias: "o",
  19. configs: [
  20. {
  21. type: "string",
  22. },
  23. ],
  24. description: "To get the output in a specified format ( accept json or markdown )",
  25. },
  26. {
  27. name: "additional-package",
  28. alias: "a",
  29. configs: [{ type: "string" }],
  30. multiple: true,
  31. description: "Adds additional packages to the output",
  32. },
  33. ], async (options) => {
  34. let { output } = options;
  35. const envinfoConfig = {};
  36. if (output) {
  37. // Remove quotes if exist
  38. output = output.replace(/['"]+/g, "");
  39. switch (output) {
  40. case "markdown":
  41. envinfoConfig["markdown"] = true;
  42. break;
  43. case "json":
  44. envinfoConfig["json"] = true;
  45. break;
  46. default:
  47. cli.logger.error(`'${output}' is not a valid value for output`);
  48. process.exit(2);
  49. }
  50. }
  51. const defaultInformation = {
  52. Binaries: ["Node", "Yarn", "npm"],
  53. Browsers: [
  54. "Brave Browser",
  55. "Chrome",
  56. "Chrome Canary",
  57. "Edge",
  58. "Firefox",
  59. "Firefox Developer Edition",
  60. "Firefox Nightly",
  61. "Internet Explorer",
  62. "Safari",
  63. "Safari Technology Preview",
  64. ],
  65. Monorepos: ["Yarn Workspaces", "Lerna"],
  66. System: ["OS", "CPU", "Memory"],
  67. npmGlobalPackages: ["webpack", "webpack-cli", "webpack-dev-server"],
  68. npmPackages: "{*webpack*,*loader*}",
  69. };
  70. let defaultPackages = ["webpack", "loader"];
  71. if (typeof options.additionalPackage !== "undefined") {
  72. defaultPackages = [...defaultPackages, ...options.additionalPackage];
  73. }
  74. defaultInformation.npmPackages = `{${defaultPackages
  75. .map((item) => `*${item}*`)
  76. .join(",")}}`;
  77. let info = await envinfo_1.default.run(defaultInformation, envinfoConfig);
  78. info = info.replace(/npmPackages/g, "Packages");
  79. info = info.replace(/npmGlobalPackages/g, "Global Packages");
  80. cli.logger.raw(info);
  81. });
  82. }
  83. }
  84. exports.default = InfoCommand;