example-run.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 disabledProjects = {
  11. next: 'This example is disabled till the next major release',
  12. 'next-scheduler': 'This example is disabled till the next major release',
  13. parcel: 'This example is being transitioned to a newer version',
  14. 'parcel-2':
  15. 'There is currently a bug in parcel which prevents this from working',
  16. // https://github.com/parcel-bundler/parcel/issues/4729
  17. // tries to load babel within each fc file and fails
  18. }
  19. const pnpSimulatedProjects = {
  20. angular: 'Angular CLI does not support Yarn PnP',
  21. }
  22. ///////////////////////////////////////////////////////
  23. if (!givenProjName) {
  24. console.error('Must specify an example-project name, or "all"')
  25. process.exit(1)
  26. }
  27. if (!runCmd) {
  28. console.error('Must specify a run command')
  29. process.exit(1)
  30. }
  31. const projNames =
  32. givenProjName === 'all'
  33. ? globby.sync('*', { cwd: examplesDir, onlyDirectories: true })
  34. : [givenProjName]
  35. projNames.forEach((projName) => {
  36. // Don't run disabled projects
  37. if (disabledProjects.hasOwnProperty(projName)) {
  38. console.info(disabledProjects[projName])
  39. return
  40. }
  41. const projDir = path.join(examplesDir, projName)
  42. console.log()
  43. console.info('PROJECT:', projName)
  44. console.log(projDir)
  45. // Decide whether to simulate pnp or run normal yarn
  46. if (pnpSimulatedProjects.hasOwnProperty(projName)) {
  47. console.log('Using PnP simulation')
  48. console.log()
  49. exec.sync(['yarn', 'run', 'example:pnp', projName, runCmd], {
  50. cwd: rootDir,
  51. exitOnError: true,
  52. live: true,
  53. })
  54. } else {
  55. console.log('Normal Yarn execution')
  56. console.log()
  57. exec.sync(['yarn', 'run', runCmd], {
  58. cwd: projDir,
  59. exitOnError: true,
  60. live: true,
  61. })
  62. }
  63. console.log()
  64. })