example-run.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const path = require("path");
  2. const exec = require("./lib/shell");
  3. const globby = require("globby");
  4. const rootDir = path.resolve(__dirname, "..");
  5. const examplesDir = path.join(rootDir, "example-projects");
  6. const givenProjName = process.argv[2];
  7. const runCmd = process.argv[3];
  8. ///////////////////////////////////////////////////////
  9. // Project Settings
  10. const redirectProjects = [["parcel", "parcel-2"]];
  11. const disabledProjects = [
  12. ["next", "This example is disabled till the next major release"],
  13. ["next-scheduler", "This example is disabled till the next major release"],
  14. [
  15. "parcel-2",
  16. "There is currently a bug in parcel bundler which prevents this from working",
  17. ],
  18. ];
  19. const pnpSimulatedProjects = ["angular"];
  20. ///////////////////////////////////////////////////////
  21. if (!givenProjName) {
  22. console.error('Must specify an example-project name, or "all"');
  23. process.exit(1);
  24. }
  25. if (!runCmd) {
  26. console.error("Must specify a run command");
  27. process.exit(1);
  28. }
  29. const projNames =
  30. givenProjName === "all"
  31. ? globby.sync("*", { cwd: examplesDir, onlyDirectories: true })
  32. : [givenProjName];
  33. projNames.forEach((projName) => {
  34. // Rewrite projName to redirect directory
  35. const redirect = redirectProjects.find(([val]) => val === projName);
  36. if (redirect) {
  37. console.info(`Redirecting '${redirect[0]}' to '${redirect[1]}' directory`);
  38. projName = redirect[1];
  39. }
  40. // Don't run disabled projects
  41. const disabled = disabledProjects.find(([val]) => val === projName);
  42. if (disabled) {
  43. console.info(disabled[1]);
  44. return;
  45. }
  46. const projDir = path.join(examplesDir, projName);
  47. console.log();
  48. console.info("PROJECT:", projName);
  49. console.log(projDir);
  50. // Decide whether to simulate pnp or run normal yarn
  51. let execCmd = [runCmd];
  52. if (pnpSimulatedProjects.includes(projName)) {
  53. console.log("Using PnP simulation");
  54. execCmd = ["example:pnp", projName, runCmd];
  55. } else {
  56. console.log("Normal Yarn execution");
  57. }
  58. // Execute
  59. console.log();
  60. exec.sync(["yarn", "run", ...execCmd], {
  61. cwd: projDir,
  62. exitOnError: true,
  63. live: true,
  64. });
  65. console.log();
  66. });