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M,EAAQ,UAC9B,CACH,EACA,OAAO,QAAU","file":"/npm/sailfish@0.0.19/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/sailfish@0.0.19/index.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\n   domain = require('domain'),\n   express,\n   nodePath = require('path'),\n   fs = require('fs'),\n   extend = require(\"node.extend\"),\n   requirejs = require('requirejs'),\n   lessCompiler = require(\"./lib/lessCompiler\"),\n   render = require(\"./lib/render\"),\n   Router = require(\"./lib/router\");\n\n/**\n * @param {Object} cfg - config\n * @constructor\n */\nvar Sailfish = function(cfg){\n   var self = this;\n\n   this.render = null;\n   this.componentRelativePath = undefined;\n   this.libRelativePath = undefined;\n   this.requirejsCfg = undefined;\n   this.requirejs = undefined;\n   this.sfReady = false;\n   this.app = express();\n\n   this.config = this._validateConfigSync(cfg);\n\n   this._run();\n\n   if (!self.config['debug']){\n      //prepare css if current running mode is production\n      lessCompiler(self.config[\"components\"], function(err){\n         if (!err){\n            self.sfReady = true;\n         }\n         else{\n            throw err;\n         }\n      });\n   }\n   else {\n      this.sfReady = true;\n   }\n};\n\n/**\n * validate and resolve paths in configuration\n * @param {Object} config - application cfg\n * @private\n */\nSailfish.prototype._validateConfigSync = function(config){\n   var optionsToValidate = {\n      'components' : './components'\n   };\n\n   /**\n    * validate and resolve required param\n    * @param {String} param - required param\n    */\n   function validateAndResolvePath(param){\n      //resolve path, use param from config or default value\n      config[param] = nodePath.resolve(config[\"rootPath\"], config[param] || optionsToValidate[param]);\n\n      //check resolved path on disk\n      if(!fs.existsSync(config[param])){\n         throw new Error(param + \" : '\" + config[param] + \"' not found\");\n      }\n   }\n\n   config = config || {};\n\n   config['rootPath'] = config['rootPath'] || process.cwd();\n\n   if (fs.existsSync(config[\"rootPath\"])){\n      //if exist - continue validation\n      for (var param in optionsToValidate){\n         if (optionsToValidate.hasOwnProperty(param)){\n            validateAndResolvePath(param)\n         }\n      }\n   }\n   else{\n      throw new Error(\"rootPath : '\" + config[\"rootPath\"] + \"' not found\");\n   }\n\n   return config;\n};\n\n/**\n * prepare environment and start express\n * @private\n */\nSailfish.prototype._run = function(){\n   var self = this;\n\n   //path for frontend resources\n   this.config[\"sf_client\"] = nodePath.join(__dirname, \"sf_client\");\n   //path for js/css packages\n   this.config[\"sf_build\"]  = nodePath.join(__dirname, \"sf_build\");\n\n   this.componentRelativePath = nodePath.relative(self.config[\"rootPath\"], self.config[\"components\"]) + \"/\";\n   this.libRelativePath = nodePath.relative(self.config[\"rootPath\"], self.config[\"sf_client\"]) + \"/lib/\";\n\n   if(!fs.existsSync(this.config[\"sf_build\"])){\n      fs.mkdirSync(this.config[\"sf_build\"]);\n   }\n\n   this.requirejsCfg = this._prepareRequireJsCfg();\n   this.requirejs = this._prepareRequirejsCtx();\n\n   this.render = new render(this.config, this.requirejs);\n\n   //prepare domain\n   this.app.use(function(req, res, next){\n      if (self.sfReady){\n         next();\n      }\n      else{\n         res.send(503);\n      }\n   });\n\n   //less middleware\n   this.app.use('/components', require('less-middleware')(this.config[\"components\"]));\n\n   //serve dir with build results\n   if (!this.config[\"debug\"]) {\n      this.app.use('/sf_build', express.static(this.config[\"sf_build\"]));\n   }\n\n   //static files\n   this.app.use('/components', express.static(this.config[\"components\"]));\n   this.app.use('/sf_client',  express.static(this.config[\"sf_client\"]));\n\n   //render engine\n   this.app.use(function(req, res, next){\n      function sendAnswer(err, html){\n         if (err){\n            res.send(500, err);\n         }\n         else{\n            res.send(html);\n         }\n      }\n\n      res.render = function(view, options){\n         self.render.render.apply(self.render, [view, options, sendAnswer]);\n      };\n\n      next();\n   });\n};\n\n/**\n * Prepare main.js for server-side and client-side\n * @private\n */\nSailfish.prototype._prepareRequireJsCfg = function(){\n   var\n      systemCfg = require(\"./lib/requirejs.json\"),\n      clientCfg = this.config[\"requirejs\"] || {},\n      path = this.config[\"sf_client\"],\n      clientsPaths = Object.keys(clientCfg[\"paths\"] || {}),\n      result = {};\n\n   extend(true, result, systemCfg, clientCfg);\n\n   //save config for client\n   fs.writeFileSync(nodePath.join(path, \"main.js\"), \"requirejs.config(\"+ JSON.stringify(result, null, 3) +\");\");\n\n   //this paths will be faked for working requirejs on server\n   result[\"fakePaths\"] = clientsPaths;\n\n   //prepare config for working on nodejs\n   for (var i in result[\"paths\"]){\n      if (result[\"paths\"].hasOwnProperty(i)){\n         if (clientsPaths.indexOf(i) > -1){\n            if (!/^(\\/\\/)|(http)/.test(result[\"paths\"][i])){\n               result[\"paths\"][i] = nodePath.resolve(this.config[\"rootPath\"], result[\"paths\"][i]);\n            }\n         }\n         else{\n            result[\"paths\"][i] = nodePath.relative(this.config[\"rootPath\"], nodePath.join(__dirname, result[\"paths\"][i]));\n         }\n      }\n   }\n\n   result.baseUrl = this.config[\"rootPath\"];\n   result.componentRelativePath = this.componentRelativePath;\n   result.libRelativePath = this.libRelativePath;\n\n   //save config for server\n   fs.writeFileSync(nodePath.join(path, \"main-server.js\"), \"requirejs.config(\"+ JSON.stringify(result, null, 3) +\");\");\n\n   return result;\n};\n\n/**\n * retrurns local requirejs\n * @returns {*}\n * @private\n */\nSailfish.prototype._prepareRequirejsCtx = function(){\n   var req = requirejs.config(this.requirejsCfg);\n\n   this.requirejsCfg[\"fakePaths\"].forEach(function(toFake){\n      requirejs.define.apply(req, [toFake, function(){}]);\n   });\n\n   return req;\n};\n\n/**\n * Returns expressjs app\n * @returns {*}\n */\nSailfish.prototype.getApp = function(){\n   return this.app;\n};\n\nvar moduleExports = function(expressjs, cfg){\n   express = expressjs;\n   var sf = new Sailfish(cfg);\n   (function(){return this || (0,eval)('this')})().sfApp = sf;\n   return sf.getApp();\n};\n\nmoduleExports.Sailfish = Sailfish;\nmoduleExports.Component = require(\"./lib/Component.js\");\nmoduleExports.doT = require('./sf_client/ext/dot/doT.js');\nmoduleExports.baseRouting = function(controllersPath){\n   var\n      router,\n      regExp = /\\/(?:([^\\/]*)\\/?)?(?:([^\\/]*)\\/?)?(.*)?/;\n\n   //resolve path\n   controllersPath = nodePath.resolve(process.cwd(), controllersPath || './controllers');\n\n   //check resolved path on disk\n   if(!fs.existsSync(controllersPath)){\n      throw new Error(\"baseRouting : '\" + controllersPath + \"' not found\");\n   }\n\n   router = new Router(controllersPath);\n\n   return function(req, res, next){\n      req.params = [];\n      var a = regExp.exec(req.originalUrl) || [];\n      for (var i = 1, l = a.length; i < l; i++){\n         a[i] && req.params.push(a[i]);\n      }\n      router.route.apply(router, arguments);\n   }\n};\nmodule.exports = moduleExports;\n"]}