Skip to content

Commit 141fb55

Browse files
committed
feat(pack logger): 添加打包log
1 parent ea22ae6 commit 141fb55

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/commands/pack.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,47 @@ exports.run = (options) => {
1717
lint = options.l || options.lin,
1818
project = new Project(cwd);
1919

20-
2120
project.readConfig({
2221
min: min
2322
}).pack({
2423
lint: lint
2524
}, (err, stats) => {
26-
success('Complete');
25+
if(err){
26+
error(err.red)
27+
}
28+
29+
const statsInfo = stats.toJson({errorDetails: false})
30+
31+
if(statsInfo.errors.length > 0){
32+
statsInfo.errors.map((err) => {
33+
error(err.red)
34+
info()
35+
})
36+
}
37+
38+
// TODO 测试warning情况
39+
if(statsInfo.warnings.length > 0){
40+
statsInfo.warnings.map((warning) => {
41+
warn(err.yellow)
42+
info()
43+
})
44+
}
45+
46+
statsInfo.assets.map((asset) => {
47+
const size = asset.size > 1024
48+
? (asset.size / 1024).toFixed(2) + ' kB'
49+
: asset.size + ' bytes';
50+
51+
// .cache文件不显示
52+
if(!endWith(asset.name, ".cache")){
53+
log('packed asset: '.gray + asset.name + ' - ' + size )
54+
}
55+
})
56+
57+
success('complete in ' + statsInfo.time + 'ms\n')
58+
59+
function endWith(string, suffix) {
60+
return string.indexOf(suffix, string.length - suffix.length) !== -1;
61+
}
2762
});
2863
};

0 commit comments

Comments
 (0)