text: // Generated by CoffeeScript 1.9.3
  var JsInit, Utils, _, amdclean, color, fs, gutil, path, pkg,
    bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  
  fs = require('fs');
  
  path = require('path');
  
  _ = require('lodash');
  
  amdclean = require('amdclean');
  
  gutil = require('gulp-util');
  
  color = gutil.colors;
  
  Utils = require('../utils');
  
  pkg = require('../../package.json');
  
  
  /**
   * @fileOverview js构建基础类库
   */
  
  JsInit = (function() {
    function JsInit(opts) {
      this.opts = opts;
      this.getOneJsDep = bind(this.getOneJsDep, this);
      this.amdReg = /;?\s*define\s*\(([^(]*),?\s*?function\s*\([^\)]*\)/;
      this.expStr = /define\s*\(([^(]*),?\s*?function/;
      this.depArrReg = /^[^\[]*(\[[^\]\[]*\]).*$/;
      this.jsImgReg = /STATIC_PATH\s*\+\s*(('|")\/img\/.*?\.(jpg|png|gif)('|"))/g;
      this.staticUriReg = /(getStaticUri\.(img|css|js)\(??.*\.(jpg|png|gif|css|js)('|")\))|(STATIC_PATH\s*\+\s*(('|")\/img\/.*?\.(jpg|png|gif)('|")))/g;
      this.info = "/**\n *Uglify by " + pkg.name + "@v" + pkg.version + "\n *@description:" + pkg.description + "\n *@author:Pang.J.G\n *@homepage:" + pkg.homepage + "\n */\n";
      this.root = this.opts.root;
      this.env = this.opts.env;
      this.isDebug = this.opts.isDebug;
      this.srcPath = this.opts.srcPath + 'js/';
      this.debugPath = this.opts.debugPath + 'js/';
      this.distPath = this.opts.distPath + 'js/';
      this.mapPath = this.opts.mapPath;
      this.prefix = this.opts.prefix;
      this.hashLen = this.opts.hashLen;
      this.coreMods = this.opts.coreJs.mods;
      this.coreModsName = this.opts.coreJs.name;
      this.vendorPath = this.debugPath + 'vendor';
      this.jsMap = this.mapPath + 'jsmap.json';
      this.jsLibs = this.mapPath + 'jslibs.json';
    }
  
    JsInit.prototype.tryEval = function(str) {
      var err, json;
      try {
        return json = eval('(' + str + ')');
      } catch (_error) {
        err = _error;
      }
    };
  
    JsInit.prototype.filterDepMap = function(depMap) {
      var _depMap;
      _depMap = depMap.filter(function(dep) {
        return ["require", "exports", "module", ""].indexOf(dep) === -1;
      });
      _depMap.map(function(dep) {
        return dep.replace(/\.js$/, '');
      });
      return _depMap;
    };
  
    JsInit.prototype.madeModId = function(filepath) {
      return filepath.replace(/\\/g, '/').split('/js/')[1].replace(/.js$/, '');
    };
  
    JsInit.prototype.madeModList = function(depArr, curPath) {
      var _arr, _this;
      _this = this;
      _arr = [];
      if (depArr.length > 0) {
        _.forEach(depArr, function(val) {
          var _filePath, _val;
          _val = val;
          if (_val.indexOf('../') === 0 || _val.indexOf('./') === 0) {
            _filePath = path.join(curPath, _val);
            _val = _this.madeModId(_filePath);
          }
          return _arr.push(_val);
        });
      }
      return _arr;
    };
  
    JsInit.prototype.arrToString = function(arr) {
      var _str;
      _str = "";
      if (arr.length > 0) {
        _.forEach(arr, function(val, n) {
          return _str += (n > 0 ? "," : "") + ("'" + val + "'");
        });
      }
      return "[" + _str + "]";
    };
  
    JsInit.prototype.getRegKey = function(str, type) {
      return str.replace("getStaticUri." + type + "(", "").replace(')', '').replace(/(^\'|\")|(\'|\"$)/g, '');
    };
  
    JsInit.prototype.getDistName = function(key, map) {
      if (_.has(map, key)) {
        return map[key].distname;
      } else {
        return key;
      }
    };
  
    JsInit.prototype.replaceStaticResName = function(res) {
      var _getStr, _res, _this;
      _this = this;
      _getStr = function(strs, type) {
        var key, map, val;
        map = Utils.getMap(type);
        key = _this.getRegKey(strs, type);
        val = _this.getDistName(key, map);
        return strs.replace(key, val);
      };
      _res = res.replace(_this.staticUriReg, function(str) {
        var _map, key, val;
        if (str.indexOf('/img/') > -1) {
          _map = Utils.getMap('img');
          key = str.match(/\/img\/.*\.(png|jpg|gif)/)[0].replace('/img/', '');
          val = _this.getDistName(key, _map);
          return str.replace(key, val);
        } else if (str.indexOf('getStaticUri.img(') === 0) {
          return _getStr(str, 'img');
        } else if (str.indexOf('getStaticUri.css(') === 0) {
          return _getStr(str, 'css');
        } else if (str.indexOf('getStaticUri.js(') === 0) {
          return _getStr(str, 'js');
        } else {
          return str;
        }
      });
      return _res;
    };
  
  
    /**
     * 获取具名AMD模块的依赖表
     * @param  {String} file_path [AMD模块文件的路径]
     * @return {Array}  [模块的依赖数组]
     */
  
    JsInit.prototype.getOneJsDep = function(source) {
      var _list, _this;
      _this = this;
      _list = [];
      source.replace(_this.amdReg, function(str, map) {
        var _arr, depStr, err;
        depStr = map.replace(_this.depArrReg, "$1");
        if (/^\[/.test(depStr)) {
          _arr = _this.tryEval(depStr);
          try {
            return _list = _this.filterDepMap(_arr);
          } catch (_error) {
            err = _error;
            return console.log(err);
          }
        }
      });
      return _list;
    };
  
    JsInit.prototype.coreModsFilter = function(arr) {
      var _temp, f, i, len;
      _temp = [];
      for (i = 0, len = arr.length; i < len; i++) {
        f = arr[i];
        if (indexOf.call(this.coreMods, f) < 0) {
          _temp.push(f);
        }
      }
      return _temp;
    };
  
    JsInit.prototype.amdClean = function(source) {
      var s;
      s = amdclean.clean({
        code: source,
        wrap: {
          start: '',
          end: ''
        }
      });
      return s;
    };
  
    return JsInit;
  
  })();
  
  module.exports = JsInit;
  