forked from OmniSharp/generator-aspnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.js
73 lines (59 loc) · 1.82 KB
/
configuration.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
var findup = require('findup-sync');
var path = require('path');
var abstractionsStr = '.Abstractions';
function getBaseNamespace(fs) {
'use strict';
var projectJsonPath = module.exports.getProjectJsonPath();
if (!projectJsonPath) {
return 'MyNamespace';
}
var projectJson = require(projectJsonPath);
if (projectJson && projectJson.tooling && projectJson.tooling.defaultNamespace) {
return projectJson.tooling.defaultNamespace;
}
var projectPath = path.resolve(path.dirname(projectJsonPath));
var namespace = path.basename(projectPath);
// If it ends in .Abstractions, we want the common namespace by default.
if (namespace.indexOf(abstractionsStr) === namespace.length - abstractionsStr.length) {
namespace = namespace.substr(0, namespace.length - abstractionsStr.length);
}
return namespace;
}
module.exports = {
// Get the namespace relative to the cwd
getNamespace: function(fs) {
'use strict';
var baseNamespace = getBaseNamespace(fs);
var cwd = process.cwd();
var baseDirectory = path.resolve(path.dirname(this.getProjectJsonPath()));
var relativePath = path.relative(baseDirectory, cwd);
if (relativePath) {
return [baseNamespace].concat(relativePath.split(path.sep)).join('.');
}
return baseNamespace;
},
getProjectJsonPath: function() {
'use strict';
return findup('project.json');
},
getProjectJson: function(fs) {
'use strict';
var path = module.exports.getProjectJsonPath();
if (!path) {
return {};
}
return fs.readJSON(path, {});
},
getGlobalJsonPath: function() {
'use strict';
return findup('global.json');
},
getGlobalJson: function(fs) {
'use strict';
var path = module.exports.getGlobalJsonPath(path);
if (!path) {
return {};
}
return fs.readJSON(path, {});
},
};