TrackChangesApp.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. require('logger-sharelatex')
  17. const logger = require('logger-sharelatex')
  18. const Settings = require('settings-sharelatex')
  19. module.exports = {
  20. running: false,
  21. initing: false,
  22. callbacks: [],
  23. ensureRunning(callback) {
  24. if (callback == null) {
  25. callback = function (error) {}
  26. }
  27. if (this.running) {
  28. return callback()
  29. } else if (this.initing) {
  30. return this.callbacks.push(callback)
  31. } else {
  32. this.initing = true
  33. this.callbacks.push(callback)
  34. return app.listen(
  35. __guard__(
  36. Settings.internal != null
  37. ? Settings.internal.trackchanges
  38. : undefined,
  39. (x) => x.port
  40. ),
  41. 'localhost',
  42. (error) => {
  43. if (error != null) {
  44. throw error
  45. }
  46. this.running = true
  47. logger.log('track changes running in dev mode')
  48. return (() => {
  49. const result = []
  50. for (callback of Array.from(this.callbacks)) {
  51. result.push(callback())
  52. }
  53. return result
  54. })()
  55. }
  56. )
  57. }
  58. }
  59. }
  60. function __guard__(value, transform) {
  61. return typeof value !== 'undefined' && value !== null
  62. ? transform(value)
  63. : undefined
  64. }