Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

eslint.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env node
  2. /**
  3. * @fileoverview Main CLI that is run via the eslint command.
  4. * @author Nicholas C. Zakas
  5. */
  6. /* eslint no-console:off */
  7. "use strict";
  8. // to use V8's code cache to speed up instantiation time
  9. require("v8-compile-cache");
  10. // must do this initialization *before* other requires in order to work
  11. if (process.argv.includes("--debug")) {
  12. require("debug").enable("eslint:*,-eslint:code-path,eslintrc:*");
  13. }
  14. //------------------------------------------------------------------------------
  15. // Helpers
  16. //------------------------------------------------------------------------------
  17. /**
  18. * Read data from stdin til the end.
  19. *
  20. * Note: See
  21. * - https://github.com/nodejs/node/blob/master/doc/api/process.md#processstdin
  22. * - https://github.com/nodejs/node/blob/master/doc/api/process.md#a-note-on-process-io
  23. * - https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-01/msg00419.html
  24. * - https://github.com/nodejs/node/issues/7439 (historical)
  25. *
  26. * On Windows using `fs.readFileSync(STDIN_FILE_DESCRIPTOR, "utf8")` seems
  27. * to read 4096 bytes before blocking and never drains to read further data.
  28. *
  29. * The investigation on the Emacs thread indicates:
  30. *
  31. * > Emacs on MS-Windows uses pipes to communicate with subprocesses; a
  32. * > pipe on Windows has a 4K buffer. So as soon as Emacs writes more than
  33. * > 4096 bytes to the pipe, the pipe becomes full, and Emacs then waits for
  34. * > the subprocess to read its end of the pipe, at which time Emacs will
  35. * > write the rest of the stuff.
  36. * @returns {Promise<string>} The read text.
  37. */
  38. function readStdin() {
  39. return new Promise((resolve, reject) => {
  40. let content = "";
  41. let chunk = "";
  42. process.stdin
  43. .setEncoding("utf8")
  44. .on("readable", () => {
  45. while ((chunk = process.stdin.read()) !== null) {
  46. content += chunk;
  47. }
  48. })
  49. .on("end", () => resolve(content))
  50. .on("error", reject);
  51. });
  52. }
  53. /**
  54. * Get the error message of a given value.
  55. * @param {any} error The value to get.
  56. * @returns {string} The error message.
  57. */
  58. function getErrorMessage(error) {
  59. // Lazy loading because this is used only if an error happened.
  60. const util = require("util");
  61. // Foolproof -- thirdparty module might throw non-object.
  62. if (typeof error !== "object" || error === null) {
  63. return String(error);
  64. }
  65. // Use templates if `error.messageTemplate` is present.
  66. if (typeof error.messageTemplate === "string") {
  67. try {
  68. const template = require(`../messages/${error.messageTemplate}.js`);
  69. return template(error.messageData || {});
  70. } catch {
  71. // Ignore template error then fallback to use `error.stack`.
  72. }
  73. }
  74. // Use the stacktrace if it's an error object.
  75. if (typeof error.stack === "string") {
  76. return error.stack;
  77. }
  78. // Otherwise, dump the object.
  79. return util.format("%o", error);
  80. }
  81. /**
  82. * Catch and report unexpected error.
  83. * @param {any} error The thrown error object.
  84. * @returns {void}
  85. */
  86. function onFatalError(error) {
  87. process.exitCode = 2;
  88. const { version } = require("../package.json");
  89. const message = getErrorMessage(error);
  90. console.error(`
  91. Oops! Something went wrong! :(
  92. ESLint: ${version}
  93. ${message}`);
  94. }
  95. //------------------------------------------------------------------------------
  96. // Execution
  97. //------------------------------------------------------------------------------
  98. (async function main() {
  99. process.on("uncaughtException", onFatalError);
  100. process.on("unhandledRejection", onFatalError);
  101. // Call the config initializer if `--init` is present.
  102. if (process.argv.includes("--init")) {
  103. await require("../lib/init/config-initializer").initializeConfig();
  104. return;
  105. }
  106. // Otherwise, call the CLI.
  107. process.exitCode = await require("../lib/cli").execute(
  108. process.argv,
  109. process.argv.includes("--stdin") ? await readStdin() : null
  110. );
  111. }()).catch(onFatalError);