test-dist.js 831 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env node
  2. "use strict";
  3. const path = require("path");
  4. const shell = require("shelljs");
  5. const tempy = require("tempy");
  6. shell.config.fatal = true;
  7. const rootDir = path.join(__dirname, "..");
  8. const distDir = path.join(rootDir, "dist");
  9. const file = shell.exec("npm pack", { cwd: distDir }).stdout.trim();
  10. const tarPath = path.join(distDir, file);
  11. const tmpDir = tempy.directory();
  12. shell.config.silent = true;
  13. shell.exec("npm init -y", { cwd: tmpDir });
  14. shell.exec(`npm install "${tarPath}"`, { cwd: tmpDir });
  15. shell.config.silent = false;
  16. const code = shell.exec("yarn test --color --runInBand", {
  17. cwd: rootDir,
  18. env: Object.assign({}, process.env, {
  19. NODE_ENV: "production",
  20. AST_COMPARE: "1",
  21. PRETTIER_DIR: path.join(tmpDir, "node_modules/prettier")
  22. }),
  23. shell: true
  24. }).code;
  25. process.exit(code);