Represents a duo-serve instance

@constructor
@param {String} root  The project root
358577
function Server(root) {
  if (!(this instanceof Server)) return new Server(root);

  this.settings = defaults({}, Server.defaults);
  if (root) this.root(root);
  this.plugins = [];
  this.entries = {};

  var auth = netrc('api.github.com');
  if ('GH_TOKEN' in process.env) this.token(process.env.GH_TOKEN);
  else if (auth.password) this.token(auth.password);
}
179061
function HttpServer(options) {
  options = options || {};

  if (options.root) {
    this.root = options.root;
  }
  else {
    try {
      fs.lstatSync('./public');
      this.root = './public';
    }
    catch (err) {
      this.root = './';
    }
  }

  this.headers = options.headers || {};

  this.cache = options.cache === undefined ? 3600 : options.cache; // in seconds.
  this.showDir = options.showDir !== 'false';
  this.autoIndex = options.autoIndex !== 'false';
  this.gzip = options.gzip === true;
  this.contentType = options.contentType || 'application/octet-stream';

  if (options.ext) {
    this.ext = options.ext === true
      ? 'html'
      : options.ext;
  }

  var before = options.before ? options.before.slice() : [];

  before.push(function (req, res) {
    if (options.logFn) {
      options.logFn(req, res);
    }

    res.emit('next');
  });

  if (options.cors) {
    this.headers['Access-Control-Allow-Origin'] = '*';
    this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
    if (options.corsHeaders) {
      options.corsHeaders.split(/\s*,\s*/)
          .forEach(function (h) { this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
    }
    before.push(corser.create(options.corsHeaders ? {
      requestHeaders: this.headers['Access-Control-Allow-Headers'].split(/\s*,\s*/)
    } : null));
  }

  if (options.robots) {
    before.push(function (req, res) {
      if (req.url === '/robots.txt') {
        res.setHeader('Content-Type', 'text/plain');
        var robots = options.robots === true
          ? 'User-agent: *\nDisallow: /'
          : options.robots.replace(/\\n/, '\n');

        return res.end(robots);
      }

      res.emit('next');
    });
  }

  before.push(ecstatic({
    root: this.root,
    cache: this.cache,
    showDir: this.showDir,
    autoIndex: this.autoIndex,
    defaultExt: this.ext,
    gzip: this.gzip,
    contentType: this.contentType,
//    handleError: typeof options.proxy !== 'string'
    handleError: (!options.fallback || typeof options.proxy === 'string')
  }));

  if (typeof options.proxy === 'string') {
    var proxy = httpProxy.createProxyServer({});
    before.push(function (req, res) {
      proxy.web(req, res, {
        target: options.proxy,
        changeOrigin: true
      });
    });
  }

  if (options.fallback) {
    before.push(function (req, res) {
      if (res.statusCode === 404) {
        res.redirect(options.fallback.address, 301);
      }
    });
  }

  var serverOptions = {
    before: before,
    headers: this.headers,
    onError: function (err, req, res) {
      if (options.logFn) {
        options.logFn(req, res, err);
      }

      res.end();
    }
  };

  if (options.https) {
    serverOptions.https = options.https;
  }

  this.server = union.createServer(serverOptions);
}
599891
function (ref, rootEl) {
  var routes = ref.routes;
  var debug = ref.debug;

  // load the routes
  if (routes) { store.loadRoutes(routes); }

  // enable console tools when debug enabled.
  if (debug === true) {
    window.router = store;
    subscribe(function (state, action) { return console.log("action", action); });
  }

  return connect(Container);
}
901619
function tree(root) {
	var structure = {};

	var _files = fs.readdirSync(root);
	for(var i=0; i<_files.length; i++) {
		if ((_files[i] !== '.') && (_files[i] !== '..')) {
			var stats = fs.statSync(root + '/' + _files[i]);
			if (stats.isDirectory()) {
				structure[_files[i]] = tree(root + '/' + _files[i]);
			} else if (stats.isFile() && xIsJsFile.test(_files[i])) {
				try {
					structure[_files[i]] = require(root + '/' + _files[i]);
				} catch(err) {
					console.log('Could not load task in: ' + _files[i]);
					console.error(err);
				}
			}
		}
	}

	return structure;
}
1334273
function Server(options) {
  var that = this;
  that.options = options || {};
  that.stack = [];
  bind.call(that);
}
1025363
function load(root, path, callback, errback) {
		resolve(root, path, function (realPath, contents) {
			process(realPath, contents, callback, errback);
		}, errback);
	}
549997
function(ns, root){
    if (!ns) {
      return null;
    }
    var nsParts = ns.split(".");
    root = root || this;
    for (var i = 0, len = nsParts.length; i < len; i++) {
      if (typeof root[nsParts[i]] === "undefined") {
        root[nsParts[i]] = {};
      }
      root = root[nsParts[i]];
    }
    return root;
  }
1361943
function(node, root) {
    var pn = node.parentNode;
    while (pn) {
      if (pn == root) {
        break;
      }
      pn = pn.parentNode;
    }
    return !!pn;
  }
274638
@Override
    public Collection<AgentProjectInfo> collectDependencies(String rootDirectory) {
        Collection<DependencyInfo> dependencies = new ArrayList<>();
        try {
            CommandLineProcess npmLsJson = new CommandLineProcess(rootDirectory, getLsCommandParamsJson());
            npmLsJson.setTimeoutReadLineSeconds(this.npmTimeoutDependenciesCollector);
            List<String> linesOfNpmLsJson = npmLsJson.executeProcess();
            // flag that indicates if the 'npm ls' command failed
            this.npmLsFailureStatus = npmLsJson.isErrorInProcess() && !this.ignoreNpmLsErrors;
            StringBuilder json = new StringBuilder();
            for (String line : linesOfNpmLsJson) {
                json.append(line);
            }
            if (json != null && json.length() > 0 && (!npmLsJson.isErrorInProcess() || this.ignoreNpmLsErrors)) {
                logger.debug("'npm ls' output is not empty");
                if(npmLsJson.isErrorInProcess() && this.ignoreNpmLsErrors) {
                    logger.info("Ignore errors of 'npm ls'");
                }
                getDependencies(new JSONObject(json.toString()), rootDirectory, dependencies);
            }
        } catch (IOException e) {
            this.npmLsFailureStatus = true;
            logger.warn("Error getting dependencies after running 'npm ls --json' on {}, error : {}", rootDirectory, e.getMessage());
            logger.debug("Error: {}", e.getStackTrace());
        }

        if (dependencies.isEmpty()) {
            if (!showNpmLsError && this.npmLsFailureStatus) {
                logger.warn("Failed to getting dependencies after running '{}', run {} on {} folder", getLsCommandParams(), getInstallParams(), rootDirectory);
                showNpmLsError = true;
            }
        }
        return getSingleProjectList(dependencies);
    }
942052
function findRoot(root) {
  var pkg;
  root = root.split(path.sep);
  while(!pkg && root.length > 1) {
    var cur = root.join(path.sep);
    if(fs.existsSync(path.join(cur, "package.json"))) {
      return cur;
    }
    root.pop();
  }
}
1289691
function RouterState(root, snapshot) {
        _super.call(this, root);
        this.snapshot = snapshot;
        setRouterStateSnapshot(this, root);
    }
126665
function createBuilder(name,ftask,builderFunc, tasks, parentBuilderInstance) {
        // create root block
        var builderInstance = {};
        builderInstance.name=name;
        builderInstance.ftask = ftask;
        builderInstance.childs = [];
        builderInstance.parent = parentBuilderInstance; // it can be null

        var rootTask={
            name: "rootTask",
            def: function () { return {}; },
            exec: function (scope, next) {
                if (scope.$$input==null){
                    next({});
                }
                else
                {
                    next(scope.$$input);
                }
            }
        };
        builderInstance.root = createBlock(builderInstance,tasks,null, rootTask,null);

        // we can support for child builder ( fork and join support)
        builderInstance.newInstance = function (name,builderFunc) {
            var newInstance = createBuilder(name,ftask,builderFunc, tasks, builderInstance);
            builderInstance.childs.push(newInstance);
            return newInstance;
        }
        
        
        // after end we let use to build the tasks schema
        if (builderFunc!=null){
            builderFunc(builderInstance.root);
        }
        builderInstance.runner=createRunner(builderInstance);
        
        return builderInstance;
    }
304579
function createApp(root, options) {
  root = root || '';
  options = _.defaults(options || {}, {
    views: path.join(root, 'views', path.sep),
    public: path.join(root, 'public'),
    configdir: root,
    configOverrides: {},
    cacheviews: false,
  });
  var app = express();
  app.rootDir = root;
  if (!__theApp) {
    __theApp = app;
  }
  //options.appmethods overrides appmethods
  var methods = _.defaults(options.appmethods || {}, appmethods);
  //the express application object's prototype chain is funky so manually mix-in
  //our application methods
  Object.keys(methods).forEach( function(name) {
    app[name] = methods[name];
  });

  app.log = log; //use simple logger before log configuration

  app._beforeStart = app._setupBeforeStartListeners();
  app.addBeforeStartListener(app._connectToDb.bind(app));
  app._beforeStop = app._setupBeforeStopListeners();
  app.addBeforeStopListener(app._disconnectFromDb.bind(app));

  app.loadConfig = getConfigLoader(options);
  app.userModel = options.userModel;
  var config = app.loadConfig('app');
  app.config = config;
  if (config.settings) {
    Object.keys(config.settings).forEach( function(name) {
      app.set(name, config.settings[name]);
    });
  }
  app.initializeLogging();

  app.email = require('./email')(app);
  require('./passport')(passport, app); // pass passport for configuration
  app.passport = passport;

  app.setupViews(options);

  ///////////////install initial middleware///////////////
  app.useGracefulExiting();

  // adds req.id and req.log
  app.use(log.useReqLog(config.requests && config.requests.hideInternals));

  // configure request logging
  app.configRequestLogging();

  app.use(bodyParser.urlencoded());
  app.use(bodyParser.json());

  app._configureSession();

  app.use(passport.initialize());
  app.use(passport.session()); // persistent login sessions

  app.use(flash()); // use connect-flash for flash messages stored in session

  //now that passport is initialized expose the user to views
  app.use(function(req, res, next) {
    if (req.isAuthenticated && req.isAuthenticated())
      res.locals.user = req.user;
    if (req.session.impersonated)
      res.locals.impersonated = true;
    res.locals.query = req.query;
    //automatically expose flash messages to views, do with
    //a function instead of variable because we only want to consume the
    //flash message if the view requests it.
    res.locals.popAlertMessages = _.partial(utils.popAlertMessages, req.flash.bind(req));
    return next();
  });

  // development only
  if ('development' == app.get('env')) {
    // add development vars to res.locals (enables debug_footer)
    app.use(function debugFooterHandler(req, res, next) {
      res.locals.debug = {
        req: req
      };
      next();
    });
  }
  ////////end initial middleware (see start() for more) //////////

  app.setupPrivateMode();
  app.saveCurrentNamedRoute();
  app.setupAccessControlPolicy();
  app.createDefaultAdmin();

  app.set('dburl', config.dburl);
  if (options.public)
    app.set('publicpath', options.public);

  if (process.env.PORT || config.port)
    app.set('port', process.env.PORT || config.port);

  //set up the base app's named routes
  app.updateNamedRoutes(routes(app, passport));
  if (options.routes)
    app.updateNamedRoutes(options.routes);

  return app;
}
1336020
function (root) {
      if (root.refresh) {
        root.refresh()
        return
      }
      for (var i = 0; i < root.children.length; i++) {
        refreshTree(root.children[i])
      }
    }
602639
function (rootComp, reactContext) {
      var ctx = this;

      var effectiveReactContext = reactContext || {};
      effectiveReactContext.morearty = ctx;

      return React.createClass({
        displayName: 'Bootstrap',

        childContextTypes: {
          morearty: React.PropTypes.instanceOf(Context).isRequired
        },

        getChildContext: function () {
          return effectiveReactContext;
        },

        componentWillMount: function () {
          ctx.init(this);
        },

        render: function () {
          var effectiveProps = Util.assign({}, {binding: ctx.getBinding()}, this.props);

          return React.createFactory(rootComp)(effectiveProps);
        }
      });
    }
960848
function (version, args, pipe) {
        let spawnOpts = { cwd: ForestInternal.elmRoot(version) };
        let buffers = [];
        return new Promise((resolve, reject) => {
            let child = child_process_1.spawn('npm', args, spawnOpts);
            if (pipe) {
                child.stdout.pipe(process.stdout);
                child.stderr.pipe(process.stderr);
                process.stdin.pipe(child.stdin);
                process.stdin.resume();
            }
            child.stdout.on('data', (data) => {
                buffers.push(data);
            });
            child.on('close', (code) => {
                if (pipe) {
                    process.stdin.pause();
                    process.stdin.unpipe();
                }
                if (code === 0) {
                    let str = Buffer.concat(buffers).toString('utf-8');
                    return resolve(str);
                }
                // Use reject instead of throw here because we are in a callback
                reject(new ForestError(Errors.NpmCommandFailed, `npm command failed with exit code ${code}`, code));
            });
        }).catch((err) => {
            if (err instanceof ForestError) {
                throw err;
            }
            else {
                throw new ForestError(Errors.NpmRunFailed, err);
            }
        });
    }
600244
function Delegate(root) {

  /**
   * Maintain a map of listener
   * lists, keyed by event name.
   *
   * @type Object
   */
  this.listenerMap = [{}, {}];
  if (root) {
    this.root(root);
  }

  /** @type function() */
  this.handle = Delegate.prototype.handle.bind(this);
}