watch.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* eslint-env node */
  2. /* eslint import/no-unresolved:0, no-console:0 */
  3. import {spawn} from 'node:child_process';
  4. import {join} from 'node:path';
  5. import {stderr, stdout} from 'node:process';
  6. import sane from 'sane';
  7. const watcherPy = sane(join(__dirname, '../src/sentry'));
  8. const watcherJson = sane(join(__dirname, '../api-docs'));
  9. const watchers = [watcherPy, watcherJson];
  10. let isCurrentlyRunning = false;
  11. const makeApiDocsCommand = function () {
  12. if (isCurrentlyRunning) {
  13. console.log('already rebuilding docs');
  14. return;
  15. }
  16. console.log('rebuilding OpenAPI schema...');
  17. isCurrentlyRunning = true;
  18. const buildCommand = spawn('make', ['-C', '../', 'build-api-docs']);
  19. buildCommand.stdout.on('data', function (data) {
  20. stdout.write(data.toString());
  21. });
  22. buildCommand.stderr.on('data', function (data) {
  23. stderr.write('stderr: ' + data.toString());
  24. });
  25. buildCommand.on('exit', function () {
  26. isCurrentlyRunning = false;
  27. });
  28. };
  29. for (const w of watchers) {
  30. w.on('change', makeApiDocsCommand);
  31. w.on('add', makeApiDocsCommand);
  32. w.on('delete', makeApiDocsCommand);
  33. }
  34. console.log('rebuilding OpenAPI schema on changes');