watch.ts 1.1 KB

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