-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·76 lines (73 loc) · 2.88 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var path = require('path');
var fs = require('fs');
var createCombo = require('./lib/createCombo');
var replaceTpl = require('./lib/tpl');
var analyzeComp = require('./lib/analyzeComp');
var createFrameworkConfig = function(ret, conf, settings, opt) {
var map = {};
map.deps = {};
var cacheDeps = {};
var filePath;
//引入组件js时把样式加入依赖表
fis.util.map(ret.src, function(subpath, file) {
if (file.requires && file.requires.length) {
map.deps[file.id] = map.deps[file.id] || [];
map.deps[file.id] = map.deps[file.id].concat(file.requires);
file.requires.forEach(function(req) {
filePath = req.split(path.sep);
if (filePath[0] == 'components') {
var comp = analyzeComp(filePath[1]);
var jsPath = comp.getJSPATH();
var cssPath = comp.getCSSPATH();
var jsId = comp.getJSID();
var cssId = comp.getCSSID();
if (fs.existsSync(cssPath)) {
if (fs.existsSync(jsPath)) {
map.deps[jsId] = map.deps[jsId] || [];
map.deps[jsId].push(cssId);
}
}
}
})
}
});
//再次遍历文件,找到isViews标记的文件
fis.util.map(ret.src, function(subpath, file) {
//有isViews标记,并且html类文件,才需要做替换
if (file.isViews && file.isHtmlLike) {
var content = file.getContent();
//替换tpl
replaceTpl(content, file);
//获取依赖组件
var compArrs = fis.config.get(file.filename + '.compDeps') || [];
//组件css和js加入依赖表
compArrs.forEach(function(compName) {
var comp = analyzeComp(compName);
var jsId = comp.getJSID();
var cssId = comp.getCSSID();
var jsPath = comp.getJSPATH();
var cssPath = comp.getCSSPATH();
var entryId = 'js/' + file.filename + '.js';
map.deps[entryId] = map.deps[entryId] || [];
if (fs.existsSync(jsPath)) {
add(map.deps[entryId], jsId);
}
if (fs.existsSync(cssPath)) {
add(map.deps[entryId], cssId);
}
})
//创建combo连接,替换钩子
createCombo(ret, file.id, map.deps, settings);
}
});
function add(arrs, newItem) {
var isExist = false;
arrs.forEach(function(i) {
if (arrs[i] === newItem) {
isExist = true;
}
});
!isExist && arrs.push(newItem);
};
};
module.exports = createFrameworkConfig;