|
| 1 | +'use strict'; |
1 | 2 |
|
2 | | -var spawn = require('child_process').spawn |
3 | | - , path = require('path') |
4 | | - , fs = require('fs-extra') |
| 3 | +var path = require('path'); |
| 4 | +var fs = require('fs-extra'); |
5 | 5 |
|
6 | | -module.exports = cachier |
7 | | - |
8 | | -function safespawn() { |
9 | | - var c = spawn.apply(null, arguments) |
10 | | - c.on('error', function (err) { |
11 | | - // suppress node errors |
12 | | - }) |
13 | | - return c |
14 | | -} |
| 6 | +module.exports = cachier; |
15 | 7 |
|
16 | 8 | function cachier(base) { |
17 | 9 | function child(sub) { |
18 | | - return cachier(path.join(base, sub)) |
| 10 | + return cachier(path.join(base, sub)); |
19 | 11 | } |
| 12 | + |
20 | 13 | child.get = function (key, dest, done) { |
21 | 14 | if (arguments.length === 2) { |
22 | | - done = dest |
23 | | - dest = key |
24 | | - key = '' |
| 15 | + done = dest; |
| 16 | + dest = key; |
| 17 | + key = ''; |
25 | 18 | } |
26 | | - copy(path.join(base, key), dest, done) |
27 | | - } |
| 19 | + |
| 20 | + copy(path.join(base, key), dest, done); |
| 21 | + }; |
| 22 | + |
28 | 23 | child.update = function (key, dest, done) { |
29 | 24 | if (arguments.length === 2) { |
30 | | - done = dest |
31 | | - dest = key |
32 | | - key = '' |
| 25 | + done = dest; |
| 26 | + dest = key; |
| 27 | + key = ''; |
33 | 28 | } |
34 | | - copy(dest, path.join(base, key), done) |
| 29 | + |
| 30 | + copy(dest, path.join(base, key), done); |
35 | 31 | } |
36 | | - child.base = base |
37 | | - return child |
| 32 | + |
| 33 | + child.base = base; |
| 34 | + |
| 35 | + return child; |
38 | 36 | } |
39 | 37 |
|
40 | 38 | function copy(from, to, done) { |
41 | 39 | fs.exists(from, function (exists) { |
42 | | - if (!exists) return done(new Error('Source does not exist: ' + from)) |
| 40 | + if (!exists) { |
| 41 | + return done(new Error('Source does not exist: ' + from)); |
| 42 | + } |
| 43 | + |
43 | 44 | fs.remove(to, function () { |
44 | 45 | fs.mkdirp(path.dirname(to), function () { |
45 | 46 | fs.copy(from, to, function (err) { |
46 | | - return done(err && new Error('Failed to retrieve cached code: ' + err)) |
47 | | - }) |
48 | | - }) |
49 | | - }) |
50 | | - }) |
| 47 | + return done(err && new Error('Failed to retrieve cached code: ' + err)); |
| 48 | + }); |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
51 | 52 | } |
52 | | - |
0 commit comments