example-run.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  17. const pnpSimulatedProjects = {
  18. angular: 'Angular CLI does not support Yarn PnP',
  19. }
  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. // Don't run disabled projects
  35. if (disabledProjects.hasOwnProperty(projName)) {
  36. console.info(disabledProjects[projName])
  37. return
  38. }
  39. const projDir = path.join(examplesDir, projName)
  40. console.log()
  41. console.info('PROJECT:', projName)
  42. console.log(projDir)
  43. // Decide whether to simulate pnp or run normal yarn
  44. if (pnpSimulatedProjects.hasOwnProperty(projName)) {
  45. console.log('Using PnP simulation')
  46. console.log()
  47. exec.sync(['yarn', 'run', 'example:pnp', projName, runCmd], {
  48. cwd: rootDir,
  49. exitOnError: true,
  50. live: true,
  51. })
  52. } else {
  53. console.log('Normal Yarn execution')
  54. console.log()
  55. exec.sync(['yarn', 'run', runCmd], {
  56. cwd: projDir,
  57. exitOnError: true,
  58. live: true,
  59. })
  60. }
  61. console.log()
  62. })