1 |
|
2 | (function() {
|
3 | var findConfig, fs, loadConfig, loadOldConfig, path, _config, _root;
|
4 |
|
5 | path = require('path');
|
6 |
|
7 | fs = require('fs');
|
8 |
|
9 | try {
|
10 | require('coffee-script/register');
|
11 | } catch (_error) {}
|
12 |
|
13 | _config = void 0;
|
14 |
|
15 | _root = void 0;
|
16 |
|
17 | loadOldConfig = function(root) {
|
18 | var config, p;
|
19 | p = path.join(root, '.lake');
|
20 | if (fs.existsSync(p)) {
|
21 | config = require(path.join(p, 'config'));
|
22 | }
|
23 | if (config.config.lakeOutput == null) {
|
24 | config.config.lakeOutput = path.join(p, 'build');
|
25 | }
|
26 | return config;
|
27 | };
|
28 |
|
29 | loadConfig = function(root) {
|
30 | var c, configurator, e, p;
|
31 | p = path.join(root, 'lake.config');
|
32 | try {
|
33 | configurator = require(p);
|
34 | } catch (_error) {
|
35 | e = _error;
|
36 | }
|
37 | if (!(configurator instanceof Function)) {
|
38 | return configurator;
|
39 | }
|
40 | c = {
|
41 | config: {
|
42 | lakePath: root,
|
43 | lakeOutput: path.join(root, 'build', 'lake')
|
44 | }
|
45 | };
|
46 | configurator(c);
|
47 | return c;
|
48 | };
|
49 |
|
50 | findConfig = function() {
|
51 | var currPath, root;
|
52 | currPath = process.cwd().split(path.sep);
|
53 | while (currPath.length) {
|
54 | root = "/" + (path.join.apply(path, currPath));
|
55 | _config = loadConfig(root);
|
56 | if (_config == null) {
|
57 | _config = loadOldConfig(root);
|
58 | }
|
59 | if (_config) {
|
60 | _root = root;
|
61 | return true;
|
62 | }
|
63 | currPath.pop();
|
64 | }
|
65 | return false;
|
66 | };
|
67 |
|
68 | module.exports = {
|
69 | projectRoot: function() {
|
70 | if (!((_root != null) || findConfig())) {
|
71 | return void 0;
|
72 | }
|
73 | return _root;
|
74 | },
|
75 | config: function() {
|
76 | if (!((_config != null) || findConfig())) {
|
77 | return void 0;
|
78 | }
|
79 | return _config;
|
80 | }
|
81 | };
|
82 |
|
83 | }).call(this);
|