ClsiApp.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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').logger.level('info')
  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 ? Settings.internal.clsi : undefined,
  37. (x) => x.port
  38. ),
  39. 'localhost',
  40. (error) => {
  41. if (error != null) {
  42. throw error
  43. }
  44. this.running = true
  45. logger.log('clsi 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. }