1 | var unyield = require('unyield')
|
2 | var thunkify = require('thunkify')
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var safe = function (fn) {
|
10 | return unyield(function * () {
|
11 | try {
|
12 | var result = yield fn.apply(this, arguments)
|
13 | return result
|
14 | } catch (e) {
|
15 | return
|
16 | }
|
17 | })
|
18 | }
|
19 |
|
20 | var stat = safe(thunkify(require('fs').stat))
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | exports.diffHashes = function (old, neww) {
|
41 | var updated = []
|
42 |
|
43 | Object.keys(neww).forEach(function (key) {
|
44 | if (!old[key] || old[key] !== neww[key]) {
|
45 | updated.push(key)
|
46 | }
|
47 | old[key] = neww[key]
|
48 | })
|
49 |
|
50 | return updated
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | exports.filterFiles = unyield(function * (cwd, paths) {
|
59 | var stats = yield paths.map(function (path) {
|
60 | return stat(require('path').join(cwd, path))
|
61 | })
|
62 |
|
63 | var result = paths.filter(function (path, idx) {
|
64 | if (stats[idx] && stats[idx].isFile()) return true
|
65 | })
|
66 |
|
67 | return result
|
68 | })
|
69 |
|
70 | var ASSET_EXPR = /\.(css|js|html|jpe?g|png|gif|woff2?|otf|svg)$/
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | exports.isAsset = function (filename) {
|
78 | return ASSET_EXPR.test(filename)
|
79 | }
|