UNPKG

fd-gulp-jsconcat

Version:

concat js files according to those rules listed on this page(http://wd.alibaba-inc.com/doc/page/work/cbu-regulations/merge)

51 lines (50 loc) 1.84 kB
var constants = require('./constants'); var path = require('path'); module.exports = { /** * 获取匹配到的js文件的本地文件名 * @param {[type]} srcDir 源文件夹目录名 * @param {[type]} matchedFile 通过JS_IMPORT_RE匹配到的内容 * @param {[type]} file 当前正在处理的merge文件的Transform对象 * @param {[type]} domain 指定的url域名 * @param {[type]} localCommonDir 指定fdevlib/sys公共资源的目录 * @return {[type]} 本地文件全名 */ getFileName: function(srcDir, matchedFile, file, domain, localCommonDir) { var tmpFile = matchedFile, tmpList, idx; if ((idx = tmpFile.indexOf('?')) !== -1) { tmpFile = tmpFile.substring(0, idx); } if ((idx = tmpFile.indexOf(domain)) !== -1) { tmpFile = tmpFile.substring(idx + domain.length); // app应用以"app"打头 if (tmpFile.indexOf('app') === 0) { // 获取当前文件相对于分支根目录的路径 tmpFile = tmpFile.substring(tmpFile.indexOf('/', tmpFile.indexOf('/') + 1) + 1); tmpFile = path.join(srcDir, tmpFile); } // fdevlib/sys以"fdevlib"/"sys"打头 else if (localCommonDir && tmpFile.search(/(fdevlib|sys)/) === 0) { tmpFile = path.join(localCommonDir, tmpFile); } } else { tmpFile = path.join(path.dirname(file.path), tmpFile); } return tmpFile.replace(/\\/g, '/'); }, /** * 获取domain值,用在解析merge文件中import的url * @param {[type]} opt [description] * @return {[type]} [description] */ getDomain: function(opt) { var domain = 'http://style.c.aliimg.com/'; if (opt.domain) { domain = opt.domain; } if (domain[domain.length - 1] !== '/') { domain += '/'; } return domain; } }