example-lint.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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] || 'all'
  7. const projNames =
  8. givenProjName === 'all'
  9. ? globby.sync('*', { cwd: examplesDir, onlyDirectories: true })
  10. : [givenProjName]
  11. projNames.forEach((projName) => {
  12. const projDir = path.join(examplesDir, projName)
  13. console.log()
  14. console.info('PROJECT:', projName)
  15. console.log(projDir)
  16. const { success } = exec.sync(['yarn', 'run', 'lint'], {
  17. cwd: projDir,
  18. exitOnError: false,
  19. live: true,
  20. })
  21. if (!success) {
  22. console.log('Could not execute lint script, attempting generic linting')
  23. // Prettier is currently not part of any workspace, I will defer on adding it as a dependency
  24. // exec.sync(["yarn", "run", "prettier", "--write", "./src"], {
  25. // cwd: projDir,
  26. // exitOnError: false,
  27. // live: true,
  28. // });
  29. exec.sync(
  30. 'yarn exec eslint src/ --fix-dry-run --config ../.eslintrc.json --ext .tsx,.ts,.jsx,.js',
  31. {
  32. cwd: projDir,
  33. exitOnError: false,
  34. live: true,
  35. }
  36. )
  37. }
  38. console.log()
  39. })