BVB Source Codes

prettier Show run-external-typescript-tests.js Source code

Return Download prettier: download run-external-typescript-tests.js Source code - Download prettier Source code - Type:.js
  1. "use strict";
  2.  
  3. /**
  4.  * There's an issue with this script's assumption that each run of prettier
  5.  * will result in one output to stderr or stdout.
  6.  *
  7.  * On Mac this seems not to hold for stderr, where multiple errors are buffered
  8.  * into one emit on the stderr stream.
  9.  *
  10.  * If you have any ideas on how to fix this, please send a PR!
  11.  */
  12. if (process.platform !== "win32") {
  13.   console.error("Error: this script currently only works on windows.");
  14.   process.exit(1);
  15. }
  16.  
  17. const fs = require("fs");
  18. const path = require("path");
  19. const spawn = require("child_process").spawn;
  20. const rimraf = require("rimraf");
  21.  
  22. const tsRoot = path.resolve(__dirname, "../../TypeScript");
  23. const testsDir = path.relative(process.cwd(), path.join(tsRoot, "tests"));
  24. const errorsPath = "./errors/";
  25. const fileGlob = path.join(testsDir, "**/*.ts");
  26.  
  27. if (!fs.existsSync(tsRoot) || !fs.existsSync(testsDir)) {
  28.   console.error(`Error: TypeScript is not cloned at ../TypeScript`);
  29.   process.exit(1);
  30. }
  31.  
  32. const badFiles = [];
  33. const errorTypes = {};
  34. let good = 0;
  35. let skipped = 0;
  36.  
  37. rimraf.sync(errorsPath);
  38.  
  39. const cp = spawn("node", [
  40.   "./bin/prettier.js",
  41.   "--parser",
  42.   "typescript",
  43.   "--debug-check",
  44.   fileGlob
  45. ]);
  46.  
  47. cp.stdout.on("data", () => {
  48.   good++;
  49.   printStatus();
  50. });
  51.  
  52. cp.stderr.on("data", err => {
  53.   const error = err.toString();
  54.   const { file, errorType } = splitFileAndError(error);
  55.   if (errorType.startsWith("SyntaxError:")) {
  56.     skipped++;
  57.   } else {
  58.     badFiles.push({ file, errorType, error });
  59.     errorTypes[errorType] = (errorTypes[errorType] || 0) + 1;
  60.   }
  61.   printStatus();
  62. });
  63.  
  64. cp.on("close", () => {
  65.   const total = badFiles.length + good + skipped;
  66.   const percentNoError = (100 * (good + skipped) / total).toFixed(0);
  67.   console.log(
  68.     `\n${percentNoError}% of ${total} files processed without errors.\n`
  69.   );
  70.   Object.keys(errorTypes)
  71.     .sort((a, b) => errorTypes[b] - errorTypes[a])
  72.     .forEach(errorType => {
  73.       console.log(`${errorTypes[errorType]}\t${errorType}`);
  74.     });
  75.  
  76.   console.log(`\nWriting errors to '${errorsPath}' directory`);
  77.   writeErrorsToFiles();
  78. });
  79.  
  80. function printStatus() {
  81.   process.stdout.write(
  82.     `\r${good} good, ${skipped} skipped, ${badFiles.length} bad`
  83.   );
  84. }
  85.  
  86. function splitFileAndError(err) {
  87.   const lines = err.split("\n");
  88.   const [file, ...rest] = lines[0].split(":");
  89.   if (rest.length) {
  90.     return {
  91.       file,
  92.       errorType: rest
  93.         .join(":")
  94.         .replace(/\(\d+:\d+\)/, "")
  95.         .replace(/(Comment )".*"/, '$1"<omitted>"')
  96.         .trim()
  97.     };
  98.   } else {
  99.     console.error("Could not process error:", err);
  100.     return {
  101.       file: "?",
  102.       errorType: err
  103.     };
  104.   }
  105. }
  106.  
  107. function writeErrorsToFiles() {
  108.   const splitter = "@".repeat(80);
  109.   fs.mkdirSync(errorsPath);
  110.   Object.keys(errorTypes).forEach(errorType => {
  111.     const files = badFiles.filter(f => f.errorType === errorType);
  112.     const contents = files
  113.       .map(({ file, error }) => {
  114.         // Trim file name from error.
  115.         if (error.startsWith(file)) {
  116.           error = error.substring(file.length);
  117.         }
  118.         return `\n\n${file}\n${error}\n${splitter}\n`;
  119.       })
  120.       .join("\n");
  121.     fs.writeFileSync(
  122.       path.join(errorsPath, sanitize(errorType) + ".log"),
  123.       contents
  124.     );
  125.   });
  126. }
  127.  
  128. function sanitize(string) {
  129.   return string.replace(/[^A-Z0-9_.\(\) \-]/gi, "_").replace(/\.$/, "");
  130. }
  131.  
downloadrun-external-typescript-tests.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top