-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
102 lines (75 loc) · 2.74 KB
/
index.js
File metadata and controls
102 lines (75 loc) · 2.74 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var Cache = require('./lib/cache.js');
var alp = require('alpaca-sm');
module.exports = function(ret, conf, settings, opt) {
var alpConf = {},
cache = new Cache(!!opt.optimize),
allFiles = {};
settings['isOptimizer'] = !!opt.optimize;
alpConf = fis.util.merge(alpConf, settings);
alpConf.root = fis.project.getProjectPath();
alpConf.fileBasedRoot = true;
alpConf.readable = {
css: false,
cssInHTML: false
};
alp.config.merge(alpConf);
fis.util.map(ret.src, function (id, file) {
var _cache;
if (!file.isHtmlLike && !file.isCssLike && !file.isJsLike) {
return;
}
id = id.replace(/^[\/]*/, '');
allFiles[id] = {
file: file,
rawContent: file.getContent()
};
_cache = cache.read(id);
//解决文件内容依赖其它文件的情况比如使用了inline方式
if (file.cache && !fis.util.isEmpty(file.cache.deps) && !fis.util.isEmpty(_cache) && fis.util.md5(file.getContent()) != _cache.md5) {
_cache = {};
}
if (!fis.util.isEmpty(_cache)) {
file.rawContent = file.getContent();
file.setContent(_cache._content);
!file.isHtmlLike && ret.map.res[id] && (ret.map.res[id].adeps = _cache.aRequires);
} else {
alp.processor({
src: file.realpath,
contentProcessor: function (file) {
var retObj;
retObj = ret.src['/' + file.subpath];
if (retObj) {
return retObj.rawContent || retObj.getContent();
} else {
return file.getContent();
}
}
});
file.setContent(alp.storage[id].getContent());
}
});
writeCache(alp.storage);
cache.flush();
function writeCache(storage) {
for (var k in storage) {
cache.write(k, storage[k], function (k, cfile) {
var file,
aFile,
deps = [];
deps = cfile.aRequires;
aFile = allFiles[k];
file = aFile.file;
for (var i = 0, len = deps.length, _dep; i < len; i++) {
_dep = deps[i];
file.cache.addDeps(_dep);
}
deps.length && file.cache.save(aFile.rawContent, {
requires: file.requires,
extras: file.extras
});
});
ret.ids[k] && ret.ids[k].setContent(storage[k].getContent());
ret.map.res[k] && (ret.map.res[k].adeps = storage[k].aRequires);
}
}
};