watch.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:0, import/no-unresolved:0, no-console:0 */
  3. import {spawn} from 'child_process';
  4. import {join} from 'path';
  5. import {stderr, stdout} from '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');