example-lint.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. ///////////////////////////////////////////////////////
  8. // Project Settings
  9. const specialMatchers = {
  10. next: 'pages/',
  11. 'next-scheduler': 'pages/',
  12. nuxt: 'pages/ ',
  13. }
  14. ///////////////////////////////////////////////////////
  15. const hasLinting = (projDir) => {
  16. const packageJSON = require(`${projDir}/package.json`)
  17. return packageJSON.scripts && packageJSON.scripts.lint
  18. }
  19. const projNames =
  20. givenProjName && givenProjName !== 'all'
  21. ? [givenProjName]
  22. : globby.sync('*', { cwd: examplesDir, onlyDirectories: true })
  23. projNames.forEach((projName) => {
  24. const projDir = path.join(examplesDir, projName)
  25. console.log()
  26. console.info('PROJECT:', projName)
  27. console.log(projDir)
  28. if (hasLinting(projDir)) {
  29. exec.sync(['yarn', 'run', 'lint'], {
  30. cwd: projDir,
  31. exitOnError: false,
  32. live: true,
  33. })
  34. } else {
  35. const pattern = specialMatchers[projName] || 'src/'
  36. // Prettier is currently not part of any workspace, I will defer on adding it as a dependency
  37. // exec.sync(["yarn", "exec", "prettier", "--write", "./src"], {
  38. // cwd: projDir,
  39. // exitOnError: false,
  40. // live: true,
  41. // });
  42. exec.sync(
  43. `yarn exec eslint ${pattern} --fix-dry-run --config ../.eslintrc.json --ext .tsx,.ts,.jsx,.js`,
  44. {
  45. cwd: projDir,
  46. exitOnError: false,
  47. live: true,
  48. }
  49. )
  50. }
  51. console.log()
  52. })