TrackChangesApp.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  6. * DS102: Remove unnecessary code created because of implicit returns
  7. * DS103: Rewrite code to no longer use __guard__
  8. * DS205: Consider reworking code to avoid use of IIFEs
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const app = require('../../../../app')
  13. const { waitForDb } = require('../../../../app/js/mongodb')
  14. const logger = require('@overleaf/logger')
  15. const Settings = require('@overleaf/settings')
  16. module.exports = {
  17. running: false,
  18. initing: false,
  19. callbacks: [],
  20. ensureRunning(callback) {
  21. if (callback == null) {
  22. callback = function () {}
  23. }
  24. if (this.running) {
  25. return callback()
  26. } else if (this.initing) {
  27. return this.callbacks.push(callback)
  28. }
  29. this.initing = true
  30. this.callbacks.push(callback)
  31. waitForDb().then(() => {
  32. return app.listen(
  33. __guard__(
  34. Settings.internal != null
  35. ? Settings.internal.trackchanges
  36. : undefined,
  37. x => x.port
  38. ),
  39. 'localhost',
  40. error => {
  41. if (error != null) {
  42. throw error
  43. }
  44. this.running = true
  45. logger.info('track changes running in dev mode')
  46. return (() => {
  47. const result = []
  48. for (callback of Array.from(this.callbacks)) {
  49. result.push(callback())
  50. }
  51. return result
  52. })()
  53. }
  54. )
  55. })
  56. },
  57. }
  58. function __guard__(value, transform) {
  59. return typeof value !== 'undefined' && value !== null
  60. ? transform(value)
  61. : undefined
  62. }