forked from aui/font-spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (35 loc) · 1.1 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
'use strict';
var spider = require('./spider');
var compressor = require('./compressor');
var Adapter = require('./adapter');
/**
* 分析并压缩字体
* @param {Array<String>} 网页路径列表
* @param {Adapter} 选项
* @param {Function} 回调函数
* @return {Promise} 如果没有 `callback` 参数则返回 `Promise` 对象
*/
function runner(htmlFiles, options, callback) {
options = new Adapter(options);
var webFonts = spider(htmlFiles, options).then(function(webFonts) {
return compressor(webFonts, options);
});
if (typeof callback === 'function') {
webFonts.then(function(webFonts) {
process.nextTick(function() {
callback(null, webFonts);
});
return webFonts;
}).catch(function(errors) {
process.nextTick(function() {
callback(errors);
});
return Promise.reject(errors);
});
} else {
return webFonts;
}
}
runner.spider = spider;
runner.compressor = compressor;
module.exports = runner;