example-run.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const path = require('path')
  2. const exec = require('./lib/shell')
  3. const globby = require('globby')
  4. let rootDir = path.resolve(__dirname, '..')
  5. let examplesDir = path.join(rootDir, 'example-projects')
  6. let givenProjName = process.argv[2]
  7. let runCmd = process.argv[3]
  8. if (!givenProjName) {
  9. console.error('Must specify an example-project name, or "all"')
  10. process.exit(1)
  11. }
  12. if (!runCmd) {
  13. console.error('Must specify a run command')
  14. process.exit(1)
  15. }
  16. let projNames = givenProjName === 'all' ?
  17. globby.sync('*', { cwd: examplesDir, onlyDirectories: true }) :
  18. [ givenProjName ]
  19. for (let projName of projNames) {
  20. let projDir = path.join(examplesDir, projName)
  21. console.log('')
  22. console.log('PROJECT:', projName)
  23. console.log(projDir)
  24. switch(projName) {
  25. /*
  26. each of these projects need to be built with old-fashioned npm-install in their individual directories.
  27. to exclude them from yarn workspaces and cache their directories in CI, keep these files in sync:
  28. - package.json
  29. - .travis.yml
  30. */
  31. case 'next': // somehow incompatible with babel-plugin-transform-require-ignore. REVISIT
  32. case 'next-scheduler': // same
  33. case 'nuxt': // nuxt cli tool uses webpack 4
  34. case 'vue-typescript': // vue cli tool uses webpack 4
  35. case 'vue-vuex': // vue cli tool uses webpack 4
  36. case 'parcel': // doesn't support pnp yet. parcel 2 WILL
  37. console.log('Using NPM simulation')
  38. console.log()
  39. exec.sync(
  40. [ 'yarn', 'run', 'example:npm', projName, runCmd ],
  41. { cwd: rootDir, exitOnError: true, live: true }
  42. )
  43. break
  44. case 'angular':
  45. console.log('Using PnP simulation')
  46. console.log()
  47. exec.sync(
  48. [ 'yarn', 'run', 'example:pnp', projName, runCmd ],
  49. { cwd: rootDir, exitOnError: true, live: true }
  50. )
  51. break
  52. default:
  53. console.log('Normal Yarn execution')
  54. console.log()
  55. exec.sync(
  56. [ 'yarn', 'run', runCmd ],
  57. { cwd: projDir, exitOnError: true, live: true }
  58. )
  59. break
  60. }
  61. console.log('')
  62. }