watch.ts 1.1 KB

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