1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var fs = require('fs');
|
11 | var path = require('path');
|
12 | var Paths = function (root, callback) {
|
13 | this.paths = {};
|
14 | var self = this;
|
15 | var expected = ['controllers', 'views', 'models', 'helpers', 'config', 'assets'];
|
16 | function check(dir, cb) {
|
17 | if (typeof dir !== 'string') {
|
18 | cb();
|
19 | return;
|
20 | }
|
21 |
|
22 | var target = path.join(root, dir);
|
23 | fs.stat(target, function (err, stat) {
|
24 | if (err) {
|
25 | cb(err);
|
26 | return;
|
27 | }
|
28 | else {
|
29 | self.paths[dir] = target;
|
30 | var next = expected.shift();
|
31 | check(next, cb);
|
32 | }
|
33 | });
|
34 | }
|
35 |
|
36 | check(expected.shift(), callback);
|
37 | };
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | Paths.prototype.get = function (name) {
|
49 | return this.paths[name] || false;
|
50 | };
|
51 |
|
52 | module.exports = Paths;
|
53 |
|