TrackChangesApp.js 1.9 KB

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