-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeepRepo.js
46 lines (41 loc) · 1.37 KB
/
DeepRepo.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
var path = require('path'),
DeepRepo = exports.DeepRepo = (function() {
var PROTOTYPE = function(globalpath, pattern) {
function objectfromPath(repopath) {
var dir = repopath.replace(globalpath + '/', '');
var name = pattern.exec(dir)[1];
return {
location: repopath,
dir: dir,
name: name,
id: name.replace(/\//g, '+'),
archive: name.replace(/\//g, '-')
};
}
function objectfromID(id) {
var name = id.replace(/\+/g, '/');
var dir = name + '.git';
return {
location: path.join(globalpath, dir),
dir: dir,
name: name,
id: id,
archive: name.replace(/\//g, '-')
};
}
this.object = function(pathOrID) {
if (pathOrID.indexOf(globalpath) > -1) {
return objectfromPath(pathOrID);
}
return objectfromID(pathOrID);
}
}
//
return {
'create': function(globalpath, pattern) {
return new PROTOTYPE(globalpath, pattern);
}
}
}
)();
module.exports = DeepRepo;