text: 'use strict';
  
  var callable          = require('es5-ext/object/valid-callable')
    , noop              = require('es5-ext/function/noop')
    , resolve           = require('path').resolve
    , i18n              = require('i18n2')
    , mano              = require('../')
    , tryRequire        = require('../lib/utils/try-require').bind(require)
    , genClientModels   = require('./generate-all-client-models')
    , resolveEnv        = require('./resolve-env')
    , runAppsSetup      = require('./run-apps-setup')
    , genClientPrograms = require('./generate-client-programs')
    , genClientCss      = require('./generate-client-css')
    , genClientIndexes  = require('./generate-client-indexes')
    , loadSchema        = require('./load-schema')
    , genI18n           = require('./i18n-scan')
  
    , now = Date.now;
  
  module.exports = function (path/*, name, log*/) {
  	var time, name = arguments[1], log = arguments[2]
  	  , env = resolveEnv(path), root;
  
  	if (log == null) log = noop;
  	else callable(log);
  
  	log("Generate client-side models...");
  	time = now();
  	return genClientModels(path, name).aside(function () {
  		log(" generated in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  	})(env).aside(function (env) { root = env.root; })(function (env) {
  
  		mano.i18n = i18n(((env.i18n !== undefined) && !env.i18n) ? {}
  			: tryRequire(resolve(root, 'i18n')));
  		mano.env = env;
  
  		log("Load schemas...");
  		time = now();
  		return loadSchema(path, name).aside(function () {
  			log(" loaded in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  		});
  	})(function () {
  
  		log("Run custom setup scripts...");
  		time = now();
  		return runAppsSetup(path, name).aside(function () {
  			log(" done in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  		});
  	})(function () {
  
  		log("Generate client-side html indexes...");
  		time = now();
  		return genClientIndexes(path, name).aside(function () {
  			log(" generated in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  		});
  	})(function () {
  
  		log("Generate i18n data...");
  		time = now();
  		return genI18n(path,
  			{ i18nScannerExtraPackages: mano.i18nScannerExtraPackages }).aside(function () {
  			log(" generated in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  		});
  	})(function () {
  		return env(function (env) {
  			if (env.dev) return;
  			log("Generate client-side programs...");
  			time = now();
  			return genClientPrograms(path, name).aside(function () {
  				log(" generated in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  			})(function () {
  				log("Generate client-side css...");
  				time = now();
  				return genClientCss(path, name).aside(function () {
  					log(" generated in " + ((now() - time) / 1000).toFixed(2) + "s\n");
  				});
  			});
  		});
  	});
  };
  