-
Notifications
You must be signed in to change notification settings - Fork 99
/
config.js
118 lines (99 loc) · 3.38 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* @license Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/volojs/volo for details
*/
/*jslint node: true */
/*global console */
'use strict';
var fs = require('fs'),
path = require('path'),
lang = require('./lang'),
file = require('./file'),
homeDir = require('./homeDir'),
overrideConfigUrl = path.join(homeDir, '.voloconfig'),
localConfigUrl = path.join(homeDir, '.voloconfiglocal'),
version = '0.3.8',
data, overrideConfig, localConfig, contents;
// The defaults to use.
data = lang.delegate({
"volo": {
version: version
},
"npmRegistry": "https://registry.npmjs.org/",
"github": {
"userAgent": "volo/" + version,
"scheme": "https",
"host": "github.com",
"apiHost": "api.github.com",
"searchHost": "api.github.com",
"rawUrlPattern": "https://raw.githubusercontent.com/{owner}/{repo}/{version}/{file}",
"searchPath": "/search/repositories?q={query}&language=JavaScript",
"typeOverrides": {
"dojo/dijit": "directory"
},
"auth": {
"domain": "https://api.github.com",
"authPath": "/authorizations",
"scopes": ["repo"],
"note": "Allow volo to interact with your repos.",
"note_url": "https://github.com/volojs/volo"
}
},
"command": {
"add": {
"discard": [
".gitignore",
"test",
"tests",
"doc",
"docs",
"example",
"examples",
"demo",
"demos"
]
}
}
});
//Allow a local config at homeDir + '.config.js'
if (file.exists(overrideConfigUrl)) {
contents = (fs.readFileSync(overrideConfigUrl, 'utf8') || '').trim();
if (contents) {
overrideConfig = JSON.parse(contents);
lang.mixin(data, overrideConfig, true);
}
}
module.exports = {
get: function () {
return data;
},
//Simple local config. No fancy JSON object merging just plain mixing
//of top level properties.
getLocal: function () {
var contents;
if (!localConfig) {
if (file.exists(localConfigUrl)) {
contents = (fs.readFileSync(localConfigUrl, 'utf8') || '').trim();
if (contents) {
localConfig = JSON.parse(contents);
}
}
if (!localConfig) {
localConfig = {};
}
}
return localConfig;
},
saveLocal: function () {
//Make sure the directory exists
try {
file.mkdirs(path.dirname(localConfigUrl));
fs.writeFileSync(localConfigUrl, JSON.stringify(localConfig, null, ' '));
} catch (e) {
console.error('Cannot save local config, continuing without saving.');
return '';
}
return localConfigUrl;
}
};