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,YAAY,sBACzB,UAAU,OAAO,MAAM,iCACvB,UAAU,OAAO,MAAM,oBAEvB,QAAQ,KAAK,EAAM,EAAI,GAG3B,EAEA,OAAQ,OACR,GAAI,KACJ,OAAQ,QAAQ,YAChB,cAAe,QAAQ,YACvB,YAAa,QAAQ,kBACrB,WAAY,QAAQ,iBACpB,cAAe,QAAQ,aACvB,mBAAoB,QAAQ,kBAC5B,cAAe,QAAQ,UACvB,QAAS,QAAQ,cAGnB,OAAO,QAAU","file":"/npm/cozy-light@0.4.9/lib/cozy-light.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/cozy-light@0.4.9/lib/cozy-light.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var pathExtra = require('path-extra');\nvar Pouchdb = require('pouchdb');\n\nvar logger = require('./helpers/logger');\n\n\nvar platformStatus = 'stopped';\n\nvar cozyLight = {\n\n  setStarted: function () {\n    platformStatus = 'started';\n  },\n\n  setStopped: function () {\n    platformStatus = 'stopped';\n  },\n\n  getStatus: function () {\n    return platformStatus;\n  },\n\n  init: function (program) {\n    if (program === undefined || program === null) { program = {}; }\n    this.program = program;\n    var defaultHome = pathExtra.join(pathExtra.homedir(), '.cozy-light');\n    var home = program.home || defaultHome;\n    var port = program.port || \"19104\";\n\n    cozyLight.logger.debug('Initializing Cozy Light...');\n    cozyLight.npmHelpers.initialWd = process.cwd();\n    cozyLight.configHelpers.init(home, port);\n    process.chdir(cozyLight.configHelpers.getHomePath());\n\n    cozyLight.logger.debug('Home is ' + cozyLight.configHelpers.getHomePath());\n    cozyLight.db = new Pouchdb('cozy');\n    cozyLight.pluginHelpers.loadAll(program);\n\n    // Reload apps when file configuration is modified\n    cozyLight.configHelpers.watcher.on(cozyLight.onConfigChanged);\n  },\n\n  onConfigChanged: function () {\n    cozyLight.logger.info('Configuration changed...');\n\n    if (cozyLight.getStatus() === 'started') {\n      cozyLight.logger.info('Cozy Light is restarting...');\n\n      process.nextTick(cozyLight.actions.restart);\n    }\n  },\n\n  /**\n   * Manage properly exit of the process when SIGINT signal is triggered.\n   * It asks to every plugin to end properly.\n   */\n  stop: function (callback) {\n    cozyLight.actions.stop(function endProcess (err) {\n      if (err) {\n        cozyLight.logger.error('Cozy Light was not properly terminated.');\n      } else {\n        cozyLight.logger.debug('Cozy Light was properly terminated.');\n      }\n\n      var doneCallback = function(){\n        if (cozyLight.configHelpers.watcher)\n          cozyLight.configHelpers.watcher.release();\n        cozyLight.nodeHelpers.invoke(callback);\n      };\n\n      if (cozyLight.db) {\n        try {\n          /*eslint-disable */\n          if(!cozyLight.db._closed) {\n            /*eslint-enable */\n            return cozyLight.db.close(doneCallback);\n          }\n        } catch (err) {\n          cozyLight.logger.error(err);\n        }\n      }\n      return cozyLight.nodeHelpers.invoke(doneCallback);\n    });\n  },\n\n  /**\n   * Manage properly exit of the process when SIGINT signal is triggered.\n   * It asks to every plugin to end properly.\n   */\n  exit: function (err) {\n    if (!cozyLight.nodeHelpers.hasFreedResources()) {\n      cozyLight.logger.debug('Has remaining open handles...');\n      cozyLight.logger.debug('Killing process.');\n      /*eslint-disable */\n      process.exit(err ? 1 : 0);\n      /*eslint-enable */\n    }\n  },\n\n  logger: logger,\n  db: null,\n  routes: require('./routes'),\n  configHelpers: require('./config'),\n  nodeHelpers: require('./helpers/node'),\n  npmHelpers: require('./helpers/npm'),\n  pluginHelpers: require('./plugins'),\n  applicationHelpers: require('./applications'),\n  mainAppHelper: require('./main'),\n  actions: require('./actions')\n};\n\nmodule.exports = cozyLight;\n"]}