| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | const _ = require('lodash')const EventEmitter = require('events')/* global WIKI */module.exports = {  async init() {    WIKI.logger.info('=======================================')    WIKI.logger.info(`= Wiki.js ${_.padEnd(WIKI.version + ' ', 29, '=')}`)    WIKI.logger.info('=======================================')    WIKI.logger.info('Initializing...')    WIKI.models = require('./db').init()    try {      await WIKI.models.onReady      await WIKI.configSvc.loadFromDb()      await WIKI.configSvc.applyFlags()    } catch (err) {      WIKI.logger.error('Database Initialization Error: ' + err.message)      if (WIKI.IS_DEBUG) {        console.error(err)      }      process.exit(1)    }    this.bootMaster()  },  /**   * Pre-Master Boot Sequence   */  async preBootMaster() {    try {      await this.initTelemetry()      WIKI.cache = require('./cache').init()      WIKI.scheduler = require('./scheduler').init()      WIKI.sideloader = require('./sideloader').init()      WIKI.events = new EventEmitter()    } catch (err) {      WIKI.logger.error(err)      process.exit(1)    }  },  /**   * Boot Master Process   */  async bootMaster() {    try {      if (WIKI.config.setup) {        WIKI.logger.info('Starting setup wizard...')        require('../setup')()      } else {        await this.preBootMaster()        await require('../master')()        this.postBootMaster()      }    } catch (err) {      WIKI.logger.error(err)      process.exit(1)    }  },  /**   * Post-Master Boot Sequence   */  async postBootMaster() {    await WIKI.models.analytics.refreshProvidersFromDisk()    await WIKI.models.authentication.refreshStrategiesFromDisk()    await WIKI.models.editors.refreshEditorsFromDisk()    await WIKI.models.loggers.refreshLoggersFromDisk()    await WIKI.models.renderers.refreshRenderersFromDisk()    await WIKI.models.searchEngines.refreshSearchEnginesFromDisk()    await WIKI.models.storage.refreshTargetsFromDisk()    await WIKI.auth.activateStrategies()    await WIKI.models.searchEngines.initEngine()    await WIKI.models.storage.initTargets()    WIKI.scheduler.start()  },  /**   * Init Telemetry   */  async initTelemetry() {    require('./telemetry').init()    process.on('unhandledRejection', (err) => {      WIKI.logger.warn(err)      WIKI.telemetry.sendError(err)    })    process.on('uncaughtException', (err) => {      WIKI.logger.warn(err)      WIKI.telemetry.sendError(err)    })  }}
 |