next-telemetry.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.nextTelemetry = void 0;
  7. var _chalk = _interopRequireDefault(require("next/dist/compiled/chalk"));
  8. var _indexJs = _interopRequireDefault(require("next/dist/compiled/arg/index.js"));
  9. var _utils = require("../server/lib/utils");
  10. var _storage = require("../telemetry/storage");
  11. var _isError = _interopRequireDefault(require("../lib/is-error"));
  12. function _interopRequireDefault(obj) {
  13. return obj && obj.__esModule ? obj : {
  14. default: obj
  15. };
  16. }
  17. const nextTelemetry = (argv)=>{
  18. const validArgs = {
  19. // Types
  20. "--help": Boolean,
  21. "--enable": Boolean,
  22. "--disable": Boolean,
  23. // Aliases
  24. "-h": "--help"
  25. };
  26. let args;
  27. try {
  28. args = (0, _indexJs).default(validArgs, {
  29. argv
  30. });
  31. } catch (error) {
  32. if ((0, _isError).default(error) && error.code === "ARG_UNKNOWN_OPTION") {
  33. return (0, _utils).printAndExit(error.message, 1);
  34. }
  35. throw error;
  36. }
  37. if (args["--help"]) {
  38. console.log(`
  39. Description
  40. Allows you to control Next.js' telemetry collection
  41. Usage
  42. $ next telemetry [enable/disable]
  43. You may pass the 'enable' or 'disable' argument to turn Next.js' telemetry collection on or off.
  44. Learn more: ${_chalk.default.cyan("https://nextjs.org/telemetry")}
  45. `);
  46. return;
  47. }
  48. const telemetry = new _storage.Telemetry({
  49. distDir: process.cwd()
  50. });
  51. let isEnabled = telemetry.isEnabled;
  52. if (args["--enable"] || args._[0] === "enable") {
  53. telemetry.setEnabled(true);
  54. console.log(_chalk.default.cyan("Success!"));
  55. console.log();
  56. isEnabled = true;
  57. } else if (args["--disable"] || args._[0] === "disable") {
  58. const path = telemetry.setEnabled(false);
  59. if (isEnabled) {
  60. console.log(_chalk.default.cyan(`Your preference has been saved${path ? ` to ${path}` : ""}.`));
  61. } else {
  62. console.log(_chalk.default.yellow(`Next.js' telemetry collection is already disabled.`));
  63. }
  64. console.log();
  65. isEnabled = false;
  66. } else {
  67. console.log(_chalk.default.bold("Next.js Telemetry"));
  68. console.log();
  69. }
  70. console.log(`Status: ${isEnabled ? _chalk.default.bold.green("Enabled") : _chalk.default.bold.red("Disabled")}`);
  71. console.log();
  72. if (isEnabled) {
  73. console.log(`Next.js telemetry is completely anonymous. Thank you for participating!`);
  74. } else {
  75. console.log(`You have opted-out of Next.js' anonymous telemetry program.`);
  76. console.log(`No data will be collected from your machine.`);
  77. }
  78. console.log(`Learn more: https://nextjs.org/telemetry`);
  79. console.log();
  80. };
  81. exports.nextTelemetry = nextTelemetry;
  82. //# sourceMappingURL=next-telemetry.js.map